Use more constants.
This commit is contained in:
parent
940913cf89
commit
7e650bf980
2 changed files with 37 additions and 18 deletions
|
|
@ -78,17 +78,33 @@ public class Constants {
|
||||||
/** The Constant COND_RUNNING. */
|
/** The Constant COND_RUNNING. */
|
||||||
public static final String COND_RUNNING = "Running";
|
public static final String COND_RUNNING = "Running";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conditions used in Status.
|
||||||
|
*/
|
||||||
|
public static class Condition {
|
||||||
/** The Constant COND_BOOTED. */
|
/** The Constant COND_BOOTED. */
|
||||||
public static final String COND_BOOTED = "Booted";
|
public static final String BOOTED = "Booted";
|
||||||
|
|
||||||
/** The Constant COND_VMOP_AGENT. */
|
/** The Constant COND_VMOP_AGENT. */
|
||||||
public static final String COND_VMOP_AGENT = "VmopAgentConnected";
|
public static final String VMOP_AGENT = "VmopAgentConnected";
|
||||||
|
|
||||||
/** The Constant COND_USER_LOGGED_IN. */
|
/** The Constant COND_USER_LOGGED_IN. */
|
||||||
public static final String COND_USER_LOGGED_IN = "UserLoggedIn";
|
public static final String USER_LOGGED_IN = "UserLoggedIn";
|
||||||
|
|
||||||
/** The Constant COND_CONSOLE. */
|
/** The Constant COND_CONSOLE. */
|
||||||
public static final String COND_CONSOLE = "ConsoleConnected";
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ import java.util.logging.Level;
|
||||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||||
import org.jdrupes.vmoperator.common.Constants.Crd;
|
import org.jdrupes.vmoperator.common.Constants.Crd;
|
||||||
import org.jdrupes.vmoperator.common.Constants.Status;
|
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.K8s;
|
||||||
import org.jdrupes.vmoperator.common.VmDefinition;
|
import org.jdrupes.vmoperator.common.VmDefinition;
|
||||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||||
|
|
@ -200,7 +202,7 @@ public class StatusUpdater extends VmDefUpdater {
|
||||||
boolean running = event.runState().vmRunning();
|
boolean running = event.runState().vmRunning();
|
||||||
updateCondition(vmDef, Status.COND_RUNNING, running, event.reason(),
|
updateCondition(vmDef, Status.COND_RUNNING, running, event.reason(),
|
||||||
event.message());
|
event.message());
|
||||||
JsonObject status = updateCondition(vmDef, Status.COND_BOOTED,
|
JsonObject status = updateCondition(vmDef, Condition.BOOTED,
|
||||||
event.runState() == RunState.BOOTED, event.reason(),
|
event.runState() == RunState.BOOTED, event.reason(),
|
||||||
event.message());
|
event.message());
|
||||||
if (event.runState() == RunState.STARTING) {
|
if (event.runState() == RunState.STARTING) {
|
||||||
|
|
@ -216,11 +218,12 @@ public class StatusUpdater extends VmDefUpdater {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
// In case console connection was still present
|
// In case console connection was still present
|
||||||
status.addProperty(Status.CONSOLE_CLIENT, "");
|
status.addProperty(Status.CONSOLE_CLIENT, "");
|
||||||
updateCondition(from, Status.COND_CONSOLE, false, "VmStopped",
|
updateCondition(from, Condition.CONSOLE_CONNECTED, false,
|
||||||
|
"VmStopped",
|
||||||
"The VM is not running");
|
"The VM is not running");
|
||||||
|
|
||||||
// In case we had an irregular shutdown
|
// 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");
|
"VmStopped", "The VM is not running");
|
||||||
status.remove(Status.OSINFO);
|
status.remove(Status.OSINFO);
|
||||||
updateCondition(vmDef, "VmopAgentConnected", false, "VmStopped",
|
updateCondition(vmDef, "VmopAgentConnected", false, "VmStopped",
|
||||||
|
|
@ -253,22 +256,22 @@ public class StatusUpdater extends VmDefUpdater {
|
||||||
|
|
||||||
private void updateUserLoggedIn(VmDefinition from) {
|
private void updateUserLoggedIn(VmDefinition from) {
|
||||||
if (loggedInUser == null) {
|
if (loggedInUser == null) {
|
||||||
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
|
updateCondition(from, Condition.USER_LOGGED_IN, false,
|
||||||
"NotRequested", "No user to be logged in");
|
Reason.NOT_REQUESTED, "No user to be logged in");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!from.conditionStatus(Status.COND_VMOP_AGENT).orElse(false)) {
|
if (!from.conditionStatus(Condition.VMOP_AGENT).orElse(false)) {
|
||||||
updateCondition(from, Status.COND_USER_LOGGED_IN, false,
|
updateCondition(from, Condition.USER_LOGGED_IN, false,
|
||||||
"VmopAgentDisconnected", "Waiting for VMOP agent to connect");
|
"VmopAgentDisconnected", "Waiting for VMOP agent to connect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!from.fromStatus(Status.LOGGED_IN_USER).map(loggedInUser::equals)
|
if (!from.fromStatus(Status.LOGGED_IN_USER).map(loggedInUser::equals)
|
||||||
.orElse(false)) {
|
.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");
|
"Processing", "Waiting for user to be logged in");
|
||||||
}
|
}
|
||||||
updateCondition(from, Status.COND_USER_LOGGED_IN, true,
|
updateCondition(from, Condition.USER_LOGGED_IN, true,
|
||||||
"UserLoggedIn", "User is logged in");
|
Reason.LOGGED_IN, "User is logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue