parent
9c31f574b8
commit
10182efea1
28 changed files with 114 additions and 998 deletions
|
|
@ -27,7 +27,7 @@ import org.jdrupes.vmoperator.runner.qemu.commands.QmpOpenTray;
|
|||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpRemoveMedium;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.TrayMovedEvent;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
|
|
@ -69,7 +69,7 @@ public class CdMediaController extends Component {
|
|||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
public void onConfigureQemu(ConfigureQemu event) {
|
||||
if (event.state() == State.TERMINATING) {
|
||||
if (event.runState() == RunState.TERMINATING) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ public class CdMediaController extends Component {
|
|||
}
|
||||
var driveId = "cd" + cdCounter++;
|
||||
var newFile = Optional.ofNullable(drives[i].file).orElse("");
|
||||
if (event.state() == State.STARTING) {
|
||||
if (event.runState() == RunState.STARTING) {
|
||||
current.put(driveId, newFile);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -116,8 +116,8 @@ public class CdMediaController extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onTrayMovedEvent(TrayMovedEvent event) {
|
||||
trayState.put(event.driveId(), event.state());
|
||||
if (event.state() == TrayState.OPEN
|
||||
trayState.put(event.driveId(), event.trayState());
|
||||
if (event.trayState() == TrayState.OPEN
|
||||
&& pending.containsKey(event.driveId())) {
|
||||
changeMedium(event.driveId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ FROM docker.io/alpine
|
|||
|
||||
RUN apk update
|
||||
|
||||
RUN apk add qemu-system-x86_64 qemu-modules ovmf swtpm openjdk17 mtools
|
||||
RUN apk add qemu-system-x86_64 qemu-modules ovmf swtpm openjdk21 mtools
|
||||
|
||||
RUN mkdir -p /etc/qemu && echo "allow all" > /etc/qemu/bridge.conf
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ RUN systemd-firstboot
|
|||
RUN pacman-key --init \
|
||||
&& pacman -Sy --noconfirm archlinux-keyring && pacman -Su --noconfirm \
|
||||
&& pacman -S --noconfirm which qemu-full virtiofsd \
|
||||
edk2-ovmf swtpm iproute2 bridge-utils jre17-openjdk-headless \
|
||||
edk2-ovmf swtpm iproute2 bridge-utils jre21-openjdk-headless \
|
||||
mtools \
|
||||
&& pacman -Scc --noconfirm
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import org.jdrupes.vmoperator.runner.qemu.events.CpuAdded;
|
|||
import org.jdrupes.vmoperator.runner.qemu.events.CpuDeleted;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.HotpluggableCpuStatus;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
|
|
@ -64,7 +64,7 @@ public class CpuController extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onConfigureQemu(ConfigureQemu event) {
|
||||
if (event.state() == State.TERMINATING) {
|
||||
if (event.runState() == RunState.TERMINATING) {
|
||||
return;
|
||||
}
|
||||
Optional.ofNullable(event.configuration().vm.currentCpus)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetDisplayPassword;
|
|||
import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetPasswordExpiry;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
|
|
@ -67,7 +67,7 @@ public class DisplayController extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onConfigureQemu(ConfigureQemu event) {
|
||||
if (event.state() == State.TERMINATING) {
|
||||
if (event.runState() == RunState.TERMINATING) {
|
||||
return;
|
||||
}
|
||||
protocol
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ import org.jdrupes.vmoperator.runner.qemu.events.Exit;
|
|||
import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.QmpConfigured;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jdrupes.vmoperator.util.ExtendedObjectWrapper;
|
||||
import org.jdrupes.vmoperator.util.FsdUtils;
|
||||
import org.jgrapes.core.Channel;
|
||||
|
|
@ -217,7 +217,7 @@ public class Runner extends Component {
|
|||
private CommandDefinition qemuDefinition;
|
||||
private final QemuMonitor qemuMonitor;
|
||||
private Integer resetCounter;
|
||||
private State state = State.INITIALIZING;
|
||||
private RunState state = RunState.INITIALIZING;
|
||||
|
||||
/** Preparatory actions for QEMU start */
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
|
|
@ -467,7 +467,7 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onStarted(Started event) {
|
||||
state = State.STARTING;
|
||||
state = RunState.STARTING;
|
||||
rep.fire(new RunnerStateChange(state, "RunnerStarted",
|
||||
"Runner has been started"));
|
||||
// Start first process(es)
|
||||
|
|
@ -618,9 +618,9 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler(priority = -1000)
|
||||
public void onConfigureQemuFinal(ConfigureQemu event) {
|
||||
if (state == State.STARTING) {
|
||||
if (state == RunState.STARTING) {
|
||||
fire(new MonitorCommand(new QmpCont()));
|
||||
state = State.RUNNING;
|
||||
state = RunState.RUNNING;
|
||||
rep.fire(new RunnerStateChange(state, "VmStarted",
|
||||
"Qemu has been configured and is continuing"));
|
||||
}
|
||||
|
|
@ -633,7 +633,7 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler
|
||||
public void onConfigureQemu(ConfigureQemu event) {
|
||||
if (state == State.RUNNING) {
|
||||
if (state == RunState.RUNNING) {
|
||||
if (resetCounter != null
|
||||
&& event.configuration().resetCounter != null
|
||||
&& event.configuration().resetCounter > resetCounter) {
|
||||
|
|
@ -659,14 +659,14 @@ public class Runner extends Component {
|
|||
return;
|
||||
}
|
||||
// No other process(es) may exit during startup
|
||||
if (state == State.STARTING) {
|
||||
if (state == RunState.STARTING) {
|
||||
logger.severe(() -> "Process " + procDef.name
|
||||
+ " has exited with value " + event.exitValue()
|
||||
+ " during startup.");
|
||||
rep.fire(new Stop());
|
||||
return;
|
||||
}
|
||||
if (procDef.equals(qemuDefinition) && state == State.RUNNING) {
|
||||
if (procDef.equals(qemuDefinition) && state == RunState.RUNNING) {
|
||||
rep.fire(new Exit(event.exitValue()));
|
||||
}
|
||||
logger.info(() -> "Process " + procDef.name
|
||||
|
|
@ -693,7 +693,7 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler(priority = 10_000)
|
||||
public void onStopFirst(Stop event) {
|
||||
state = State.TERMINATING;
|
||||
state = RunState.TERMINATING;
|
||||
rep.fire(new RunnerStateChange(state, "VmTerminating",
|
||||
"The VM is being shut down", exitStatus != 0));
|
||||
}
|
||||
|
|
@ -705,14 +705,14 @@ public class Runner extends Component {
|
|||
*/
|
||||
@Handler(priority = -10_000)
|
||||
public void onStopLast(Stop event) {
|
||||
state = State.STOPPED;
|
||||
state = RunState.STOPPED;
|
||||
rep.fire(new RunnerStateChange(state, "VmStopped",
|
||||
"The VM has been shut down"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ConfusingArgumentToVarargsMethod")
|
||||
private void shutdown() {
|
||||
if (!Set.of(State.TERMINATING, State.STOPPED).contains(state)) {
|
||||
if (!Set.of(RunState.TERMINATING, RunState.STOPPED).contains(state)) {
|
||||
fire(new Stop());
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import org.jdrupes.vmoperator.runner.qemu.events.DisplayPasswordChanged;
|
|||
import org.jdrupes.vmoperator.runner.qemu.events.Exit;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.HotpluggableCpuStatus;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ShutdownEvent;
|
||||
import org.jdrupes.vmoperator.util.GsonPtr;
|
||||
import org.jgrapes.core.Channel;
|
||||
|
|
@ -65,8 +65,8 @@ import org.jgrapes.util.events.InitialConfiguration;
|
|||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class StatusUpdater extends Component {
|
||||
|
||||
private static final Set<State> RUNNING_STATES
|
||||
= Set.of(State.RUNNING, State.TERMINATING);
|
||||
private static final Set<RunState> RUNNING_STATES
|
||||
= Set.of(RunState.RUNNING, RunState.TERMINATING);
|
||||
|
||||
private String namespace;
|
||||
private String vmName;
|
||||
|
|
@ -240,11 +240,11 @@ public class StatusUpdater extends Component {
|
|||
updateRunningCondition(event, from, cond);
|
||||
}
|
||||
});
|
||||
if (event.state() == State.STARTING) {
|
||||
if (event.runState() == RunState.STARTING) {
|
||||
status.addProperty("ram", GsonPtr.to(from.data())
|
||||
.getAsString("spec", "vm", "maximumRam").orElse("0"));
|
||||
status.addProperty("cpus", 1);
|
||||
} else if (event.state() == State.STOPPED) {
|
||||
} else if (event.runState() == RunState.STOPPED) {
|
||||
status.addProperty("ram", "0");
|
||||
status.addProperty("cpus", 0);
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ public class StatusUpdater extends Component {
|
|||
});
|
||||
|
||||
// Maybe stop VM
|
||||
if (event.state() == State.TERMINATING && !event.failed()
|
||||
if (event.runState() == RunState.TERMINATING && !event.failed()
|
||||
&& guestShutdownStops && shutdownByGuest) {
|
||||
logger.info(() -> "Stopping VM because of shutdown by guest.");
|
||||
var res = vmStub.patch(V1Patch.PATCH_FORMAT_JSON_PATCH,
|
||||
|
|
@ -277,13 +277,13 @@ public class StatusUpdater extends Component {
|
|||
K8sDynamicModel from, JsonObject cond) {
|
||||
boolean reportedRunning
|
||||
= "True".equals(cond.get("status").getAsString());
|
||||
if (RUNNING_STATES.contains(event.state())
|
||||
if (RUNNING_STATES.contains(event.runState())
|
||||
&& !reportedRunning) {
|
||||
cond.addProperty("status", "True");
|
||||
cond.addProperty("lastTransitionTime",
|
||||
Instant.now().toString());
|
||||
}
|
||||
if (!RUNNING_STATES.contains(event.state())
|
||||
if (!RUNNING_STATES.contains(event.runState())
|
||||
&& reportedRunning) {
|
||||
cond.addProperty("status", "False");
|
||||
cond.addProperty("lastTransitionTime",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
package org.jdrupes.vmoperator.runner.qemu.events;
|
||||
|
||||
import org.jdrupes.vmoperator.runner.qemu.Configuration;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.RunState;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Event;
|
||||
|
||||
|
|
@ -34,14 +34,14 @@ import org.jgrapes.core.Event;
|
|||
public class ConfigureQemu extends Event<Void> {
|
||||
|
||||
private final Configuration configuration;
|
||||
private final State state;
|
||||
private final RunState state;
|
||||
|
||||
/**
|
||||
* Instantiates a new configuration event.
|
||||
*
|
||||
* @param channels the channels
|
||||
*/
|
||||
public ConfigureQemu(Configuration configuration, State state,
|
||||
public ConfigureQemu(Configuration configuration, RunState state,
|
||||
Channel... channels) {
|
||||
super(channels);
|
||||
this.state = state;
|
||||
|
|
@ -62,7 +62,7 @@ public class ConfigureQemu extends Event<Void> {
|
|||
*
|
||||
* @return the state
|
||||
*/
|
||||
public State state() {
|
||||
public RunState runState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ public class RunnerStateChange extends Event<Void> {
|
|||
/**
|
||||
* The state.
|
||||
*/
|
||||
public enum State {
|
||||
public enum RunState {
|
||||
INITIALIZING, STARTING, RUNNING, TERMINATING, STOPPED
|
||||
}
|
||||
|
||||
private final State state;
|
||||
private final RunState state;
|
||||
private final String reason;
|
||||
private final String message;
|
||||
private final boolean failed;
|
||||
|
|
@ -48,7 +48,7 @@ public class RunnerStateChange extends Event<Void> {
|
|||
* @param message the message
|
||||
* @param channels the channels
|
||||
*/
|
||||
public RunnerStateChange(State state, String reason, String message,
|
||||
public RunnerStateChange(RunState state, String reason, String message,
|
||||
Channel... channels) {
|
||||
this(state, reason, message, false, channels);
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ public class RunnerStateChange extends Event<Void> {
|
|||
* @param failed the failed
|
||||
* @param channels the channels
|
||||
*/
|
||||
public RunnerStateChange(State state, String reason, String message,
|
||||
public RunnerStateChange(RunState state, String reason, String message,
|
||||
boolean failed, Channel... channels) {
|
||||
super(channels);
|
||||
this.state = state;
|
||||
|
|
@ -76,7 +76,7 @@ public class RunnerStateChange extends Event<Void> {
|
|||
*
|
||||
* @return the state
|
||||
*/
|
||||
public State state() {
|
||||
public RunState runState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class TrayMovedEvent extends MonitorEvent {
|
|||
*
|
||||
* @return the tray state
|
||||
*/
|
||||
public TrayState state() {
|
||||
public TrayState trayState() {
|
||||
return data().get("tray-open").asBoolean()
|
||||
? TrayState.OPEN
|
||||
: TrayState.CLOSED;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue