Reorganize imports.
This commit is contained in:
parent
e822d472f9
commit
41ae658e0c
16 changed files with 139 additions and 100 deletions
|
|
@ -25,8 +25,8 @@ import io.kubernetes.client.openapi.models.EventsV1Event;
|
|||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
|
||||
import org.jdrupes.vmoperator.common.Constants.Crd;
|
||||
import org.jdrupes.vmoperator.common.Constants.Status;
|
||||
import org.jdrupes.vmoperator.common.K8s;
|
||||
import org.jdrupes.vmoperator.common.K8sClient;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||
|
|
@ -74,7 +74,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
}
|
||||
try {
|
||||
vmStub = VmDefinitionStub.get(apiClient,
|
||||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM),
|
||||
namespace, vmName);
|
||||
} catch (ApiException e) {
|
||||
logger.log(Level.SEVERE, e,
|
||||
|
|
@ -108,13 +108,13 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = updateCondition(from, "ConsoleConnected", true,
|
||||
"Connected", "Connection from " + event.clientHost());
|
||||
status.addProperty("consoleClient", event.clientHost());
|
||||
status.addProperty(Status.CONSOLE_CLIENT, event.clientHost());
|
||||
return status;
|
||||
});
|
||||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.action("ConsoleConnectionUpdate")
|
||||
.reason("Connection from " + event.clientHost());
|
||||
K8s.createEvent(apiClient, vmStub.model().get(), evt);
|
||||
|
|
@ -142,13 +142,13 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = updateCondition(from, "ConsoleConnected", false,
|
||||
"Disconnected", event.clientHost() + " has disconnected");
|
||||
status.addProperty("consoleClient", "");
|
||||
status.addProperty(Status.CONSOLE_CLIENT, "");
|
||||
return status;
|
||||
});
|
||||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.action("ConsoleConnectionUpdate")
|
||||
.reason("Disconnected from " + event.clientHost());
|
||||
K8s.createEvent(apiClient, vmStub.model().get(), evt);
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ import java.nio.file.Path;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import static org.jdrupes.vmoperator.common.Constants.DATA_DISPLAY_PASSWORD;
|
||||
import static org.jdrupes.vmoperator.common.Constants.DATA_PASSWORD_EXPIRY;
|
||||
import org.jdrupes.vmoperator.common.Constants.DisplaySecret;
|
||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetDisplayPassword;
|
||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetPasswordExpiry;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||
|
|
@ -64,7 +63,7 @@ public class DisplayController extends Component {
|
|||
public DisplayController(Channel componentChannel, Path configDir) {
|
||||
super(componentChannel);
|
||||
this.configDir = configDir;
|
||||
fire(new WatchFile(configDir.resolve(DATA_DISPLAY_PASSWORD)));
|
||||
fire(new WatchFile(configDir.resolve(DisplaySecret.PASSWORD)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +114,7 @@ public class DisplayController extends Component {
|
|||
@Handler
|
||||
@SuppressWarnings("PMD.EmptyCatchBlock")
|
||||
public void onFileChanged(FileChanged event) {
|
||||
if (event.path().equals(configDir.resolve(DATA_DISPLAY_PASSWORD))) {
|
||||
if (event.path().equals(configDir.resolve(DisplaySecret.PASSWORD))) {
|
||||
configurePassword();
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +129,7 @@ public class DisplayController extends Component {
|
|||
}
|
||||
|
||||
private boolean setDisplayPassword() {
|
||||
return readFromFile(DATA_DISPLAY_PASSWORD).map(password -> {
|
||||
return readFromFile(DisplaySecret.PASSWORD).map(password -> {
|
||||
if (Objects.equals(this.currentPassword, password)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -143,7 +142,7 @@ public class DisplayController extends Component {
|
|||
}
|
||||
|
||||
private void setPasswordExpiry() {
|
||||
readFromFile(DATA_PASSWORD_EXPIRY).ifPresent(expiry -> {
|
||||
readFromFile(DisplaySecret.EXPIRY).ifPresent(expiry -> {
|
||||
logger.fine(() -> "Updating expiry time to " + expiry);
|
||||
fire(
|
||||
new MonitorCommand(new QmpSetPasswordExpiry(protocol, expiry)));
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import org.apache.commons.cli.DefaultParser;
|
|||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||
import static org.jdrupes.vmoperator.common.Constants.DATA_DISPLAY_PASSWORD;
|
||||
import org.jdrupes.vmoperator.common.Constants.DisplaySecret;
|
||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont;
|
||||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpReset;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||
|
|
@ -312,7 +312,7 @@ public class Runner extends Component {
|
|||
|
||||
// Add some values from other sources to configuration
|
||||
newConf.asOf = Instant.ofEpochSecond(configFile.lastModified());
|
||||
Path dsPath = configDir.resolve(DATA_DISPLAY_PASSWORD);
|
||||
Path dsPath = configDir.resolve(DisplaySecret.PASSWORD);
|
||||
newConf.hasDisplayPassword = dsPath.toFile().canRead();
|
||||
|
||||
// Special actions for initial configuration (startup)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ import java.io.IOException;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.logging.Level;
|
||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
|
||||
import org.jdrupes.vmoperator.common.Constants.Crd;
|
||||
import org.jdrupes.vmoperator.common.Constants.Status;
|
||||
import org.jdrupes.vmoperator.common.K8s;
|
||||
import org.jdrupes.vmoperator.common.VmDefinition;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||
|
|
@ -112,7 +112,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
}
|
||||
try {
|
||||
vmStub = VmDefinitionStub.get(apiClient,
|
||||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM),
|
||||
namespace, vmName);
|
||||
var vmDef = vmStub.model().orElse(null);
|
||||
if (vmDef == null) {
|
||||
|
|
@ -121,7 +121,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
observedGeneration = vmDef.getMetadata().getGeneration();
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.remove("loggedInUser");
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
return status;
|
||||
});
|
||||
} catch (ApiException e) {
|
||||
|
|
@ -206,12 +206,12 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
} else if (event.runState() == RunState.STOPPED) {
|
||||
status.addProperty("ram", "0");
|
||||
status.addProperty("cpus", 0);
|
||||
status.remove("loggedInUser");
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
// In case console connection was still present
|
||||
status.addProperty("consoleClient", "");
|
||||
status.addProperty(Status.CONSOLE_CLIENT, "");
|
||||
updateCondition(from, "ConsoleConnected", false, "VmStopped",
|
||||
"The VM is not running");
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.action("StatusUpdate").reason(event.reason())
|
||||
.note(event.message());
|
||||
K8s.createEvent(apiClient, vmDef, evt);
|
||||
|
|
@ -363,7 +363,8 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.addProperty("loggedInUser", event.triggering().user());
|
||||
status.addProperty(Status.LOGGED_IN_USER,
|
||||
event.triggering().user());
|
||||
return status;
|
||||
});
|
||||
}
|
||||
|
|
@ -378,7 +379,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.remove("loggedInUser");
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
return status;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue