Compare commits
10 commits
5bcf0ba051
...
7b8df80828
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b8df80828 | |||
| fccf2a6b65 | |||
| 00e9affee4 | |||
| fa84110e1d | |||
| 76b579c404 | |||
| a5433c869b | |||
| 10f3028f06 | |||
| b7fad4614d | |||
| 7d298ce24b | |||
| 6ef4c2aaa2 |
17 changed files with 157 additions and 89 deletions
|
|
@ -24,7 +24,7 @@ stages:
|
||||||
- "*/build"
|
- "*/build"
|
||||||
before_script:
|
before_script:
|
||||||
- echo -n $CI_REGISTRY_PASSWORD | podman login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
|
- echo -n $CI_REGISTRY_PASSWORD | podman login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
|
||||||
- git switch $(git branch -r --sort="authordate" --contains $CI_COMMIT_SHA | head -1 | sed -e 's#[^/]*/##')
|
- git switch $(git branch -r --sort="authordate" --contains $CI_COMMIT_SHA | head -1 | sed -e 's#.*/##')
|
||||||
- git pull
|
- git pull
|
||||||
- git reset --hard $CI_COMMIT_SHA
|
- git reset --hard $CI_COMMIT_SHA
|
||||||
|
|
||||||
|
|
|
||||||
3
dev-example/vmop-agent/gdm/PostLogin/Default
Executable file
3
dev-example/vmop-agent/gdm/PostLogin/Default
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||||
|
|
@ -72,8 +72,8 @@ doLogin() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if this user is already logged in on tty1
|
# Check if this user is already logged in on tty2
|
||||||
curUser=$(loginctl -j | jq -r '.[] | select(.tty=="tty1") | .user')
|
curUser=$(loginctl -j | jq -r '.[] | select(.tty=="tty2") | .user')
|
||||||
if [ "$curUser" = "$user" ]; then
|
if [ "$curUser" = "$user" ]; then
|
||||||
echo >&${con} "201 User already logged in"
|
echo >&${con} "201 User already logged in"
|
||||||
return
|
return
|
||||||
|
|
@ -96,17 +96,14 @@ doLogin() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the desktop for the user
|
# Configure user as auto login user
|
||||||
systemd-run 2>$temperr \
|
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||||
--unit vmop-user-desktop --uid=$uid --gid=$uid \
|
sed -i '/\[daemon\]/a AutomaticLoginEnable=true\nAutomaticLogin='$user \
|
||||||
--working-directory="/home/$user" -p TTYPath=/dev/tty1 \
|
/etc/gdm/custom.conf
|
||||||
-p PAMName=login -p StandardInput=tty -p StandardOutput=journal \
|
|
||||||
-p Conflicts="gdm.service getty@tty1.service" \
|
# Activate user
|
||||||
-E XDG_RUNTIME_DIR="/run/user/$uid" \
|
systemctl restart gdm
|
||||||
-E XDG_CURRENT_DESKTOP=GNOME \
|
|
||||||
-p ExecStartPre="/usr/bin/chvt 1" \
|
|
||||||
dbus-run-session -- gnome-shell --display-server --wayland
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo >&${con} "201 User logged in successfully"
|
echo >&${con} "201 User logged in successfully"
|
||||||
else
|
else
|
||||||
|
|
@ -117,14 +114,8 @@ doLogin() {
|
||||||
# Attempt to log out a user currently using tty1. This is an intermediate
|
# Attempt to log out a user currently using tty1. This is an intermediate
|
||||||
# operation that can be invoked from other operations
|
# operation that can be invoked from other operations
|
||||||
attemptLogout() {
|
attemptLogout() {
|
||||||
systemctl status vmop-user-desktop > /dev/null 2>&1
|
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||||
if [ $? = 0 ]; then
|
systemctl stop gdm
|
||||||
systemctl stop vmop-user-desktop
|
|
||||||
fi
|
|
||||||
loginctl -j | jq -r '.[] | select(.tty=="tty1") | .session' \
|
|
||||||
| while read sid; do
|
|
||||||
loginctl kill-session $sid
|
|
||||||
done
|
|
||||||
echo >&${con} "102 Desktop stopped"
|
echo >&${con} "102 Desktop stopped"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,15 +124,7 @@ attemptLogout() {
|
||||||
# Also try to restart gdm, if it is not running.
|
# Also try to restart gdm, if it is not running.
|
||||||
doLogout() {
|
doLogout() {
|
||||||
attemptLogout
|
attemptLogout
|
||||||
systemctl status gdm >/dev/null 2>&1
|
systemctl restart gdm
|
||||||
if [ $? != 0 ]; then
|
|
||||||
systemctl restart gdm 2>$temperr
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo >&${con} "102 gdm restarted"
|
|
||||||
else
|
|
||||||
echo >&${con} "102 Restarting gdm failed: $(tr '\n' ' ' <${temperr})"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo >&${con} "202 User logged out"
|
echo >&${con} "202 User logged out"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +136,7 @@ while read line <&${con}; do
|
||||||
done
|
done
|
||||||
|
|
||||||
onExit() {
|
onExit() {
|
||||||
attemptLogout
|
doLogout
|
||||||
if [ -n "$temperr" ]; then
|
if [ -n "$temperr" ]; then
|
||||||
rm -f $temperr
|
rm -f $temperr
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
||||||
* @param <L> the object list type
|
* @param <L> the object list type
|
||||||
* @param <R> the result type
|
* @param <R> the result type
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface GenericSupplier<O extends KubernetesObject,
|
public interface GenericSupplier<O extends KubernetesObject,
|
||||||
L extends KubernetesListObject,
|
L extends KubernetesListObject,
|
||||||
R extends K8sClusterGenericStub<O, L>> {
|
R extends K8sClusterGenericStub<O, L>> {
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
||||||
* @param <L> the object list type
|
* @param <L> the object list type
|
||||||
* @param <R> the result type
|
* @param <R> the result type
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface GenericSupplier<O extends KubernetesObject,
|
public interface GenericSupplier<O extends KubernetesObject,
|
||||||
L extends KubernetesListObject, R extends K8sGenericStub<O, L>> {
|
L extends KubernetesListObject, R extends K8sGenericStub<O, L>> {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,14 +118,14 @@ public class VmExtraData {
|
||||||
if (addr.isEmpty()) {
|
if (addr.isEmpty()) {
|
||||||
logger
|
logger
|
||||||
.severe(() -> "Failed to find display IP for " + vmDef.name());
|
.severe(() -> "Failed to find display IP for " + vmDef.name());
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var port = vmDef.<Number> fromVm("display", "spice", "port")
|
var port = vmDef.<Number> fromVm("display", "spice", "port")
|
||||||
.map(Number::longValue);
|
.map(Number::longValue);
|
||||||
if (port.isEmpty()) {
|
if (port.isEmpty()) {
|
||||||
logger
|
logger
|
||||||
.severe(() -> "No port defined for display of " + vmDef.name());
|
.severe(() -> "No port defined for display of " + vmDef.name());
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
StringBuffer data = new StringBuffer(100)
|
StringBuffer data = new StringBuffer(100)
|
||||||
.append("[virt-viewer]\ntype=spice\nhost=")
|
.append("[virt-viewer]\ntype=spice\nhost=")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ dependencies {
|
||||||
implementation 'org.jgrapes:org.jgrapes.io:[2.12.1,3)'
|
implementation 'org.jgrapes:org.jgrapes.io:[2.12.1,3)'
|
||||||
implementation 'org.jgrapes:org.jgrapes.http:[3.5.0,4)'
|
implementation 'org.jgrapes:org.jgrapes.http:[3.5.0,4)'
|
||||||
|
|
||||||
implementation 'org.jgrapes:org.jgrapes.webconsole.base:[2.2.0,3)'
|
implementation 'org.jgrapes:org.jgrapes.webconsole.base:[2.3.0,3)'
|
||||||
implementation 'org.jgrapes:org.jgrapes.webconsole.vuejs:[1.8.0,2)'
|
implementation 'org.jgrapes:org.jgrapes.webconsole.vuejs:[1.8.0,2)'
|
||||||
implementation 'org.jgrapes:org.jgrapes.webconsole.rbac:[1.4.0,2)'
|
implementation 'org.jgrapes:org.jgrapes.webconsole.rbac:[1.4.0,2)'
|
||||||
implementation 'org.jgrapes:org.jgrapes.webconlet.oidclogin:[1.7.0,2)'
|
implementation 'org.jgrapes:org.jgrapes.webconlet.oidclogin:[1.7.0,2)'
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ data:
|
||||||
# The template to use. Resolved relative to /usr/share/vmrunner/templates.
|
# The template to use. Resolved relative to /usr/share/vmrunner/templates.
|
||||||
# template: "Standard-VM-latest.ftl.yaml"
|
# template: "Standard-VM-latest.ftl.yaml"
|
||||||
<#if spec.runnerTemplate?? && spec.runnerTemplate.source?? >
|
<#if spec.runnerTemplate?? && spec.runnerTemplate.source?? >
|
||||||
template: ${ cm.spec().runnerTemplate.source }
|
template: ${ spec.runnerTemplate.source }
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
# The template is copied to the data diretory when the VM starts for
|
# The template is copied to the data diretory when the VM starts for
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ import org.jdrupes.vmoperator.manager.events.VmPoolChanged;
|
||||||
import org.jdrupes.vmoperator.manager.events.VmResourceChanged;
|
import org.jdrupes.vmoperator.manager.events.VmResourceChanged;
|
||||||
import org.jgrapes.core.Channel;
|
import org.jgrapes.core.Channel;
|
||||||
import org.jgrapes.core.Component;
|
import org.jgrapes.core.Component;
|
||||||
|
import org.jgrapes.core.EventPipeline;
|
||||||
import org.jgrapes.core.annotation.Handler;
|
import org.jgrapes.core.annotation.Handler;
|
||||||
import org.jgrapes.core.events.HandlingError;
|
import org.jgrapes.core.events.HandlingError;
|
||||||
import org.jgrapes.core.events.Start;
|
import org.jgrapes.core.events.Start;
|
||||||
|
|
@ -94,7 +95,7 @@ import org.jgrapes.util.events.ConfigurationUpdate;
|
||||||
public class Controller extends Component {
|
public class Controller extends Component {
|
||||||
|
|
||||||
private String namespace;
|
private String namespace;
|
||||||
private final ChannelManager<String, VmChannel, ?> chanMgr;
|
private final ChannelManager<String, VmChannel, EventPipeline> chanMgr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ import org.jose4j.base64url.Base64;
|
||||||
* * `passwordValidity`: the validity of the random password in seconds.
|
* * `passwordValidity`: the validity of the random password in seconds.
|
||||||
* Used to calculate the password expiry time in the generated secret.
|
* Used to calculate the password expiry time in the generated secret.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyStaticImports" })
|
|
||||||
public class DisplaySecretReconciler extends Component {
|
public class DisplaySecretReconciler extends Component {
|
||||||
|
|
||||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||||
|
|
@ -104,12 +103,15 @@ public class DisplaySecretReconciler extends Component {
|
||||||
return oldConfig;
|
return oldConfig;
|
||||||
}).ifPresent(c -> {
|
}).ifPresent(c -> {
|
||||||
try {
|
try {
|
||||||
if (c.containsKey("passwordValidity")) {
|
Optional.ofNullable(c.get("passwordValidity"))
|
||||||
passwordValidity = Integer
|
.map(p -> p instanceof Integer ? (Integer) p
|
||||||
.parseInt((String) c.get("passwordValidity"));
|
: Integer.valueOf((String) p))
|
||||||
}
|
.ifPresent(p -> {
|
||||||
} catch (ClassCastException e) {
|
passwordValidity = p;
|
||||||
logger.config("Malformed configuration: " + e.getMessage());
|
});
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
logger.warning(
|
||||||
|
() -> "Malformed configuration: " + e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +192,6 @@ public class DisplaySecretReconciler extends Component {
|
||||||
* @throws ApiException the api exception
|
* @throws ApiException the api exception
|
||||||
*/
|
*/
|
||||||
@Handler
|
@Handler
|
||||||
@SuppressWarnings("PMD.StringInstantiation")
|
|
||||||
public void onGetDisplaySecret(GetDisplaySecret event, VmChannel channel)
|
public void onGetDisplaySecret(GetDisplaySecret event, VmChannel channel)
|
||||||
throws ApiException {
|
throws ApiException {
|
||||||
// Get VM definition and check if running
|
// Get VM definition and check if running
|
||||||
|
|
@ -319,7 +320,6 @@ public class DisplaySecretReconciler extends Component {
|
||||||
/**
|
/**
|
||||||
* The Class PendingGet.
|
* The Class PendingGet.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.DataClass")
|
|
||||||
private static class PendingRequest {
|
private static class PendingRequest {
|
||||||
public final GetDisplaySecret event;
|
public final GetDisplaySecret event;
|
||||||
public final long expectedSerial;
|
public final long expectedSerial;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import com.google.gson.JsonObject;
|
||||||
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
||||||
import io.kubernetes.client.custom.V1Patch;
|
import io.kubernetes.client.custom.V1Patch;
|
||||||
import io.kubernetes.client.openapi.ApiException;
|
import io.kubernetes.client.openapi.ApiException;
|
||||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
|
||||||
import io.kubernetes.client.util.Watch;
|
import io.kubernetes.client.util.Watch;
|
||||||
import io.kubernetes.client.util.generic.options.ListOptions;
|
import io.kubernetes.client.util.generic.options.ListOptions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -32,7 +31,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
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;
|
||||||
|
|
@ -57,16 +55,28 @@ import org.jdrupes.vmoperator.manager.events.VmResourceChanged;
|
||||||
import org.jdrupes.vmoperator.util.GsonPtr;
|
import org.jdrupes.vmoperator.util.GsonPtr;
|
||||||
import org.jgrapes.core.Channel;
|
import org.jgrapes.core.Channel;
|
||||||
import org.jgrapes.core.Event;
|
import org.jgrapes.core.Event;
|
||||||
|
import org.jgrapes.core.EventPipeline;
|
||||||
import org.jgrapes.core.annotation.Handler;
|
import org.jgrapes.core.annotation.Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watches for changes of VM definitions.
|
* Watches for changes of VM definitions. When a VM definition (CR)
|
||||||
|
* becomes known, is is registered with a {@link ChannelManager} and thus
|
||||||
|
* gets an associated {@link VmChannel} and an associated
|
||||||
|
* {@link EventPipeline}.
|
||||||
|
*
|
||||||
|
* The {@link EventPipeline} is used for submitting an action that processes
|
||||||
|
* the change data from kubernetes, eventually transforming it to a
|
||||||
|
* {@link VmResourceChanged} event that is handled by another
|
||||||
|
* {@link EventPipeline} associated with the {@link VmChannel}. This
|
||||||
|
* event pipeline should be used for all events related to changes of
|
||||||
|
* a particular VM.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
||||||
public class VmMonitor extends
|
public class VmMonitor extends
|
||||||
AbstractMonitor<VmDefinition, VmDefinitions, VmChannel> {
|
AbstractMonitor<VmDefinition, VmDefinitions, VmChannel> {
|
||||||
|
|
||||||
private final ChannelManager<String, VmChannel, ?> channelManager;
|
private final ChannelManager<String, VmChannel,
|
||||||
|
EventPipeline> channelManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new VM definition watcher.
|
* Instantiates a new VM definition watcher.
|
||||||
|
|
@ -75,7 +85,7 @@ public class VmMonitor extends
|
||||||
* @param channelManager the channel manager
|
* @param channelManager the channel manager
|
||||||
*/
|
*/
|
||||||
public VmMonitor(Channel componentChannel,
|
public VmMonitor(Channel componentChannel,
|
||||||
ChannelManager<String, VmChannel, ?> channelManager) {
|
ChannelManager<String, VmChannel, EventPipeline> channelManager) {
|
||||||
super(componentChannel, VmDefinition.class,
|
super(componentChannel, VmDefinition.class,
|
||||||
VmDefinitions.class);
|
VmDefinitions.class);
|
||||||
this.channelManager = channelManager;
|
this.channelManager = channelManager;
|
||||||
|
|
@ -122,14 +132,18 @@ public class VmMonitor extends
|
||||||
@Override
|
@Override
|
||||||
protected void handleChange(K8sClient client,
|
protected void handleChange(K8sClient client,
|
||||||
Watch.Response<VmDefinition> response) {
|
Watch.Response<VmDefinition> response) {
|
||||||
V1ObjectMeta metadata = response.object.getMetadata();
|
var name = response.object.getMetadata().getName();
|
||||||
AtomicBoolean toBeAdded = new AtomicBoolean(false);
|
|
||||||
VmChannel channel = channelManager.channel(metadata.getName())
|
|
||||||
.orElseGet(() -> {
|
|
||||||
toBeAdded.set(true);
|
|
||||||
return channelManager.createChannel(metadata.getName());
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Process the response data on a VM specific pipeline to
|
||||||
|
// increase concurrency when e.g. starting many VMs.
|
||||||
|
var preparing = channelManager.associated(name)
|
||||||
|
.orElseGet(() -> newEventPipeline());
|
||||||
|
preparing.submit("VmChange[" + name + "]",
|
||||||
|
() -> processChange(client, response, preparing));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processChange(K8sClient client,
|
||||||
|
Watch.Response<VmDefinition> response, EventPipeline preparing) {
|
||||||
// Get full definition and associate with channel as backup
|
// Get full definition and associate with channel as backup
|
||||||
var vmDef = response.object;
|
var vmDef = response.object;
|
||||||
if (vmDef.data() == null) {
|
if (vmDef.data() == null) {
|
||||||
|
|
@ -137,6 +151,9 @@ public class VmMonitor extends
|
||||||
// https://github.com/kubernetes-client/java/issues/3215
|
// https://github.com/kubernetes-client/java/issues/3215
|
||||||
vmDef = getModel(client, vmDef);
|
vmDef = getModel(client, vmDef);
|
||||||
}
|
}
|
||||||
|
var name = response.object.getMetadata().getName();
|
||||||
|
var channel = channelManager.channel(name)
|
||||||
|
.orElseGet(() -> channelManager.createChannel(name));
|
||||||
if (vmDef.data() != null) {
|
if (vmDef.data() != null) {
|
||||||
// New data, augment and save
|
// New data, augment and save
|
||||||
addExtraData(vmDef, channel.vmDefinition());
|
addExtraData(vmDef, channel.vmDefinition());
|
||||||
|
|
@ -150,9 +167,7 @@ public class VmMonitor extends
|
||||||
+ response.object.getMetadata());
|
+ response.object.getMetadata());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (toBeAdded.get()) {
|
channelManager.put(name, channel, preparing);
|
||||||
channelManager.put(vmDef.name(), channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and fire changed event. Remove channel from channel
|
// Create and fire changed event. Remove channel from channel
|
||||||
// manager on completion.
|
// manager on completion.
|
||||||
|
|
@ -199,9 +214,16 @@ public class VmMonitor extends
|
||||||
@Handler
|
@Handler
|
||||||
public void onPodChanged(PodChanged event, VmChannel channel) {
|
public void onPodChanged(PodChanged event, VmChannel channel) {
|
||||||
var vmDef = channel.vmDefinition();
|
var vmDef = channel.vmDefinition();
|
||||||
updateNodeInfo(event, vmDef);
|
|
||||||
channel
|
// Make sure that this is properly sync'd with VM CR changes.
|
||||||
.fire(new VmResourceChanged(ResponseType.MODIFIED, vmDef, false, true));
|
channelManager.associated(vmDef.name())
|
||||||
|
.orElseGet(() -> activeEventPipeline())
|
||||||
|
.submit("NodeInfo[" + vmDef.name() + "]",
|
||||||
|
() -> {
|
||||||
|
updateNodeInfo(event, vmDef);
|
||||||
|
channel.fire(new VmResourceChanged(ResponseType.MODIFIED,
|
||||||
|
vmDef, false, true));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateNodeInfo(PodChanged event, VmDefinition vmDef) {
|
private void updateNodeInfo(PodChanged event, VmDefinition vmDef) {
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,14 @@ public class GuestAgentClient extends AgentConnector {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void agentConnected() {
|
protected void agentConnected() {
|
||||||
logger.fine(() -> "guest agent connected");
|
logger.fine(() -> "Guest agent connected");
|
||||||
connected = true;
|
connected = true;
|
||||||
rep().fire(new GuestAgentCommand(new QmpGuestGetOsinfo()));
|
rep().fire(new GuestAgentCommand(new QmpGuestGetOsinfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void agentDisconnected() {
|
protected void agentDisconnected() {
|
||||||
logger.fine(() -> "guest agent disconnected");
|
logger.fine(() -> "Guest agent disconnected");
|
||||||
connected = false;
|
connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,15 +88,16 @@ public class GuestAgentClient extends AgentConnector {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processInput(String line) throws IOException {
|
protected void processInput(String line) throws IOException {
|
||||||
logger.fine(() -> "guest agent(in): " + line);
|
logger.finer(() -> "guest agent(in): " + line);
|
||||||
try {
|
try {
|
||||||
var response = mapper.readValue(line, ObjectNode.class);
|
var response = mapper.readValue(line, ObjectNode.class);
|
||||||
if (response.has("return") || response.has("error")) {
|
if (response.has("return") || response.has("error")) {
|
||||||
QmpCommand executed = executing.poll();
|
QmpCommand executed = executing.poll();
|
||||||
logger.fine(() -> String.format("(Previous \"guest agent(in)\""
|
logger.finer(() -> String.format("(Previous \"guest agent(in)\""
|
||||||
+ " is result from executing %s)", executed));
|
+ " is result from executing %s)", executed));
|
||||||
if (executed instanceof QmpGuestGetOsinfo) {
|
if (executed instanceof QmpGuestGetOsinfo) {
|
||||||
var osInfo = new OsinfoEvent(response.get("return"));
|
var osInfo = new OsinfoEvent(response.get("return"));
|
||||||
|
logger.fine(() -> "Guest agent triggers: " + osInfo);
|
||||||
rep().fire(osInfo);
|
rep().fire(osInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +121,11 @@ public class GuestAgentClient extends AgentConnector {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var command = event.command();
|
var command = event.command();
|
||||||
logger.fine(() -> "guest agent(out): " + command.toString());
|
logger.fine(() -> "Guest handles: " + event);
|
||||||
String asText;
|
String asText;
|
||||||
try {
|
try {
|
||||||
asText = command.asText();
|
asText = command.asText();
|
||||||
|
logger.finer(() -> "guest agent(out): " + asText);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
logger.log(Level.SEVERE, e,
|
logger.log(Level.SEVERE, e,
|
||||||
() -> "Cannot serialize Json: " + e.getMessage());
|
() -> "Cannot serialize Json: " + e.getMessage());
|
||||||
|
|
@ -163,8 +165,8 @@ public class GuestAgentClient extends AgentConnector {
|
||||||
}
|
}
|
||||||
event.suspendHandling();
|
event.suspendHandling();
|
||||||
suspendedStop = event;
|
suspendedStop = event;
|
||||||
logger.fine(() -> "Sending powerdown command, waiting for"
|
logger.fine(() -> "Attempting shutdown through guest agent,"
|
||||||
+ " termination until " + waitUntil);
|
+ " waiting for termination until " + waitUntil);
|
||||||
powerdownTimer = Components.schedule(t -> {
|
powerdownTimer = Components.schedule(t -> {
|
||||||
logger.fine(() -> "Powerdown timeout reached.");
|
logger.fine(() -> "Powerdown timeout reached.");
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
|
||||||
|
|
@ -108,24 +108,30 @@ public class QemuMonitor extends QemuConnector {
|
||||||
@Override
|
@Override
|
||||||
protected void processInput(String line)
|
protected void processInput(String line)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
logger.fine(() -> "monitor(in): " + line);
|
logger.finer(() -> "monitor(in): " + line);
|
||||||
try {
|
try {
|
||||||
var response = mapper.readValue(line, ObjectNode.class);
|
var response = mapper.readValue(line, ObjectNode.class);
|
||||||
if (response.has("QMP")) {
|
if (response.has("QMP")) {
|
||||||
monitorReady = true;
|
monitorReady = true;
|
||||||
|
logger.fine(() -> "QMP connection ready");
|
||||||
rep().fire(new MonitorReady());
|
rep().fire(new MonitorReady());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (response.has("return") || response.has("error")) {
|
if (response.has("return") || response.has("error")) {
|
||||||
QmpCommand executed = executing.poll();
|
QmpCommand executed = executing.poll();
|
||||||
logger.fine(
|
logger.finer(
|
||||||
() -> String.format("(Previous \"monitor(in)\" is result "
|
() -> String.format("(Previous \"monitor(in)\" is result "
|
||||||
+ "from executing %s)", executed));
|
+ "from executing %s)", executed));
|
||||||
rep().fire(MonitorResult.from(executed, response));
|
var monRes = MonitorResult.from(executed, response);
|
||||||
|
logger.fine(() -> "QMP triggers: " + monRes);
|
||||||
|
rep().fire(monRes);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (response.has("event")) {
|
if (response.has("event")) {
|
||||||
MonitorEvent.from(response).ifPresent(rep()::fire);
|
MonitorEvent.from(response).ifPresent(me -> {
|
||||||
|
logger.fine(() -> "QMP triggers: " + me);
|
||||||
|
rep().fire(me);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
|
|
@ -141,7 +147,7 @@ public class QemuMonitor extends QemuConnector {
|
||||||
public void onClosed(Closed<?> event, SocketIOChannel channel) {
|
public void onClosed(Closed<?> event, SocketIOChannel channel) {
|
||||||
channel.associated(this, getClass()).ifPresent(qm -> {
|
channel.associated(this, getClass()).ifPresent(qm -> {
|
||||||
super.onClosed(event, channel);
|
super.onClosed(event, channel);
|
||||||
logger.finer(() -> "QMP socket closed.");
|
logger.fine(() -> "QMP connection closed.");
|
||||||
monitorReady = false;
|
monitorReady = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +164,7 @@ public class QemuMonitor extends QemuConnector {
|
||||||
public void onMonitorCommand(MonitorCommand event) throws IOException {
|
public void onMonitorCommand(MonitorCommand event) throws IOException {
|
||||||
// Check prerequisites
|
// Check prerequisites
|
||||||
if (!monitorReady && !(event.command() instanceof QmpCapabilities)) {
|
if (!monitorReady && !(event.command() instanceof QmpCapabilities)) {
|
||||||
logger.severe(() -> "Premature monitor command (not ready): "
|
logger.severe(() -> "Premature QMP command (not ready): "
|
||||||
+ event.command());
|
+ event.command());
|
||||||
rep().fire(new Stop());
|
rep().fire(new Stop());
|
||||||
return;
|
return;
|
||||||
|
|
@ -166,10 +172,11 @@ public class QemuMonitor extends QemuConnector {
|
||||||
|
|
||||||
// Send the command
|
// Send the command
|
||||||
var command = event.command();
|
var command = event.command();
|
||||||
logger.fine(() -> "monitor(out): " + command.toString());
|
logger.fine(() -> "QMP handles: " + event.toString());
|
||||||
String asText;
|
String asText;
|
||||||
try {
|
try {
|
||||||
asText = command.asText();
|
asText = command.asText();
|
||||||
|
logger.finer(() -> "monitor(out): " + asText);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
logger.log(Level.SEVERE, e,
|
logger.log(Level.SEVERE, e,
|
||||||
() -> "Cannot serialize Json: " + e.getMessage());
|
() -> "Cannot serialize Json: " + e.getMessage());
|
||||||
|
|
@ -192,8 +199,8 @@ public class QemuMonitor extends QemuConnector {
|
||||||
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
|
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
|
||||||
public void onStop(Stop event) {
|
public void onStop(Stop event) {
|
||||||
if (!monitorReady) {
|
if (!monitorReady) {
|
||||||
logger.fine(() -> "No QMP connection,"
|
logger.fine(() -> "Not sending QMP powerdown command"
|
||||||
+ " cannot send powerdown command");
|
+ " because QMP connection is closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,14 @@ public class VmopAgentClient extends AgentConnector {
|
||||||
*/
|
*/
|
||||||
@Handler
|
@Handler
|
||||||
public void onVmopAgentLogIn(VmopAgentLogIn event) throws IOException {
|
public void onVmopAgentLogIn(VmopAgentLogIn event) throws IOException {
|
||||||
logger.fine(() -> "vmop agent(out): login " + event.user());
|
|
||||||
if (writer().isPresent()) {
|
if (writer().isPresent()) {
|
||||||
|
logger.fine(() -> "Vmop agent handles:" + event);
|
||||||
executing.add(event);
|
executing.add(event);
|
||||||
|
logger.finer(() -> "vmop agent(out): login " + event.user());
|
||||||
sendCommand("login " + event.user());
|
sendCommand("login " + event.user());
|
||||||
|
} else {
|
||||||
|
logger
|
||||||
|
.warning(() -> "No vmop agent connection for sending " + event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,9 +78,10 @@ public class VmopAgentClient extends AgentConnector {
|
||||||
*/
|
*/
|
||||||
@Handler
|
@Handler
|
||||||
public void onVmopAgentLogout(VmopAgentLogOut event) throws IOException {
|
public void onVmopAgentLogout(VmopAgentLogOut event) throws IOException {
|
||||||
logger.fine(() -> "vmop agent(out): logout");
|
|
||||||
if (writer().isPresent()) {
|
if (writer().isPresent()) {
|
||||||
|
logger.fine(() -> "Vmop agent handles:" + event);
|
||||||
executing.add(event);
|
executing.add(event);
|
||||||
|
logger.finer(() -> "vmop agent(out): logout");
|
||||||
sendCommand("logout");
|
sendCommand("logout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,23 +90,27 @@ public class VmopAgentClient extends AgentConnector {
|
||||||
@SuppressWarnings({ "PMD.UnnecessaryReturn",
|
@SuppressWarnings({ "PMD.UnnecessaryReturn",
|
||||||
"PMD.AvoidLiteralsInIfCondition" })
|
"PMD.AvoidLiteralsInIfCondition" })
|
||||||
protected void processInput(String line) throws IOException {
|
protected void processInput(String line) throws IOException {
|
||||||
logger.fine(() -> "vmop agent(in): " + line);
|
logger.finer(() -> "vmop agent(in): " + line);
|
||||||
|
|
||||||
// Check validity
|
// Check validity
|
||||||
if (line.isEmpty() || !Character.isDigit(line.charAt(0))) {
|
if (line.isEmpty() || !Character.isDigit(line.charAt(0))) {
|
||||||
logger.warning(() -> "Illegal response: " + line);
|
logger.warning(() -> "Illegal vmop agent response: " + line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check positive responses
|
// Check positive responses
|
||||||
if (line.startsWith("220 ")) {
|
if (line.startsWith("220 ")) {
|
||||||
rep().fire(new VmopAgentConnected());
|
var evt = new VmopAgentConnected();
|
||||||
|
logger.fine(() -> "Vmop agent triggers " + evt);
|
||||||
|
rep().fire(evt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (line.startsWith("201 ")) {
|
if (line.startsWith("201 ")) {
|
||||||
Event<?> cmd = executing.pop();
|
Event<?> cmd = executing.pop();
|
||||||
if (cmd instanceof VmopAgentLogIn login) {
|
if (cmd instanceof VmopAgentLogIn login) {
|
||||||
rep().fire(new VmopAgentLoggedIn(login));
|
var evt = new VmopAgentLoggedIn(login);
|
||||||
|
logger.fine(() -> "Vmop agent triggers " + evt);
|
||||||
|
rep().fire(evt);
|
||||||
} else {
|
} else {
|
||||||
logger.severe(() -> "Response " + line
|
logger.severe(() -> "Response " + line
|
||||||
+ " does not match executing command " + cmd);
|
+ " does not match executing command " + cmd);
|
||||||
|
|
@ -111,7 +120,9 @@ public class VmopAgentClient extends AgentConnector {
|
||||||
if (line.startsWith("202 ")) {
|
if (line.startsWith("202 ")) {
|
||||||
Event<?> cmd = executing.pop();
|
Event<?> cmd = executing.pop();
|
||||||
if (cmd instanceof VmopAgentLogOut logout) {
|
if (cmd instanceof VmopAgentLogOut logout) {
|
||||||
rep().fire(new VmopAgentLoggedOut(logout));
|
var evt = new VmopAgentLoggedOut(logout);
|
||||||
|
logger.fine(() -> "Vmop agent triggers " + evt);
|
||||||
|
rep().fire(evt);
|
||||||
} else {
|
} else {
|
||||||
logger.severe(() -> "Response " + line
|
logger.severe(() -> "Response " + line
|
||||||
+ "does not match executing command " + cmd);
|
+ "does not match executing command " + cmd);
|
||||||
|
|
@ -125,7 +136,7 @@ public class VmopAgentClient extends AgentConnector {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
logger.warning(() -> "Error response: " + line);
|
logger.warning(() -> "Error response from vmop agent: " + line);
|
||||||
executing.pop();
|
executing.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ package org.jdrupes.vmoperator.runner.qemu.events;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.jgrapes.core.Channel;
|
||||||
|
import org.jgrapes.core.Components;
|
||||||
import org.jgrapes.core.Event;
|
import org.jgrapes.core.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,4 +114,20 @@ public class MonitorEvent extends Event<Void> {
|
||||||
public JsonNode data() {
|
public JsonNode data() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(Components.objectName(this)).append(" [").append(data);
|
||||||
|
if (channels() != null) {
|
||||||
|
builder.append(", channels=").append(Channel.toString(channels()));
|
||||||
|
}
|
||||||
|
builder.append(']');
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
package org.jdrupes.vmoperator.runner.qemu.events;
|
package org.jdrupes.vmoperator.runner.qemu.events;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.jgrapes.core.Channel;
|
||||||
|
import org.jgrapes.core.Components;
|
||||||
import org.jgrapes.core.Event;
|
import org.jgrapes.core.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,4 +42,21 @@ public class OsinfoEvent extends Event<Void> {
|
||||||
public JsonNode osinfo() {
|
public JsonNode osinfo() {
|
||||||
return osinfo;
|
return osinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(Components.objectName(this)).append(" [")
|
||||||
|
.append(osinfo);
|
||||||
|
if (channels() != null) {
|
||||||
|
builder.append(", channels=").append(Channel.toString(channels()));
|
||||||
|
}
|
||||||
|
builder.append(']');
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<template v-for="(entry, rowIndex) in filteredData">
|
<template v-for="(entry, rowIndex) in filteredData" :key="entry.name">
|
||||||
<tr :class="[(rowIndex % 2) ? 'odd' : 'even']"
|
<tr :class="[(rowIndex % 2) ? 'odd' : 'even']"
|
||||||
:aria-expanded="(entry.name in detailsByName) ? 'true' : 'false'">
|
:aria-expanded="(entry.name in detailsByName) ? 'true' : 'false'">
|
||||||
<td v-for="key in controller.keys"
|
<td v-for="key in controller.keys"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue