Skip to content

Commit

Permalink
Use more constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed Mar 5, 2025
1 parent 940913c commit 7e650bf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,33 @@ public static class Status {
/** The Constant COND_RUNNING. */
public static final String COND_RUNNING = "Running";

/** The Constant COND_BOOTED. */
public static final String COND_BOOTED = "Booted";

/** The Constant COND_VMOP_AGENT. */
public static final String COND_VMOP_AGENT = "VmopAgentConnected";

/** The Constant COND_USER_LOGGED_IN. */
public static final String COND_USER_LOGGED_IN = "UserLoggedIn";

/** The Constant COND_CONSOLE. */
public static final String COND_CONSOLE = "ConsoleConnected";
/**
* Conditions used in Status.
*/
public static class Condition {
/** The Constant COND_BOOTED. */
public static final String BOOTED = "Booted";

/** The Constant COND_VMOP_AGENT. */
public static final String VMOP_AGENT = "VmopAgentConnected";

/** The Constant COND_USER_LOGGED_IN. */
public static final String USER_LOGGED_IN = "UserLoggedIn";

/** The Constant COND_CONSOLE. */
public static final String CONSOLE_CONNECTED = "ConsoleConnected";

/**
* Reasons used in conditions.
*/
public static class Reason {
/** The Constant NOT_REQUESTED. */
public static final String NOT_REQUESTED = "NotRequested";

/** The Constant USER_LOGGED_IN. */
public static final String LOGGED_IN = "LoggedIn";
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd;
import org.jdrupes.vmoperator.common.Constants.Status;
import org.jdrupes.vmoperator.common.Constants.Status.Condition;
import org.jdrupes.vmoperator.common.Constants.Status.Condition.Reason;
import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.VmDefinition;
import org.jdrupes.vmoperator.common.VmDefinitionStub;
Expand Down Expand Up @@ -200,7 +202,7 @@ public void onRunnerStateChanged(RunnerStateChange event)
boolean running = event.runState().vmRunning();
updateCondition(vmDef, Status.COND_RUNNING, running, event.reason(),
event.message());
JsonObject status = updateCondition(vmDef, Status.COND_BOOTED,
JsonObject status = updateCondition(vmDef, Condition.BOOTED,
event.runState() == RunState.BOOTED, event.reason(),
event.message());
if (event.runState() == RunState.STARTING) {
Expand All @@ -216,11 +218,12 @@ public void onRunnerStateChanged(RunnerStateChange event)
if (!running) {
// In case console connection was still present
status.addProperty(Status.CONSOLE_CLIENT, "");
updateCondition(from, Status.COND_CONSOLE, false, "VmStopped",
updateCondition(from, Condition.CONSOLE_CONNECTED, false,
"VmStopped",
"The VM is not running");

// In case we had an irregular shutdown
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
updateCondition(from, Condition.USER_LOGGED_IN, false,
"VmStopped", "The VM is not running");
status.remove(Status.OSINFO);
updateCondition(vmDef, "VmopAgentConnected", false, "VmStopped",
Expand Down Expand Up @@ -253,22 +256,22 @@ public void onRunnerStateChanged(RunnerStateChange event)

private void updateUserLoggedIn(VmDefinition from) {
if (loggedInUser == null) {
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
"NotRequested", "No user to be logged in");
updateCondition(from, Condition.USER_LOGGED_IN, false,
Reason.NOT_REQUESTED, "No user to be logged in");
return;
}
if (!from.conditionStatus(Status.COND_VMOP_AGENT).orElse(false)) {
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
if (!from.conditionStatus(Condition.VMOP_AGENT).orElse(false)) {
updateCondition(from, Condition.USER_LOGGED_IN, false,
"VmopAgentDisconnected", "Waiting for VMOP agent to connect");
return;
}
if (!from.fromStatus(Status.LOGGED_IN_USER).map(loggedInUser::equals)
.orElse(false)) {
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
updateCondition(from, Condition.USER_LOGGED_IN, false,
"Processing", "Waiting for user to be logged in");
}
updateCondition(from, Status.COND_USER_LOGGED_IN, true,
"UserLoggedIn", "User is logged in");
updateCondition(from, Condition.USER_LOGGED_IN, true,
Reason.LOGGED_IN, "User is logged in");
}

/**
Expand Down

0 comments on commit 7e650bf

Please sign in to comment.