Merge branch 'prep/v4.0.0'

This commit is contained in:
Michael Lipp 2025-01-31 15:58:56 +01:00
commit b78b33a6f1
17 changed files with 130 additions and 112 deletions

View file

@ -9,6 +9,7 @@ rules:
- vmoperator.jdrupes.org - vmoperator.jdrupes.org
resources: resources:
- vms - vms
- vmpools
verbs: verbs:
- '*' - '*'
- apiGroups: - apiGroups:

View file

@ -9,6 +9,8 @@ spec:
- user: admin - user: admin
may: may:
- accessConsole - accessConsole
- start
- role: user - role: user
may: may:
- accessConsole - accessConsole
- start

View file

@ -140,7 +140,8 @@ public class VmPool {
* @return the string * @return the string
*/ */
@Override @Override
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition") @SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
"PMD.AvoidSynchronizedStatement" })
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(50); StringBuilder builder = new StringBuilder(50);
builder.append("VmPool [name=").append(name).append(", permissions=") builder.append("VmPool [name=").append(name).append(", permissions=")
@ -148,8 +149,11 @@ public class VmPool {
if (vms.size() <= 3) { if (vms.size() <= 3) {
builder.append(vms); builder.append(vms);
} else { } else {
builder.append('[').append(vms.stream().limit(3).map(s -> s + ",") synchronized (vms) {
.collect(Collectors.joining())).append("...]"); builder.append('[').append(vms.stream().limit(3)
.map(s -> s + ",").collect(Collectors.joining()))
.append("...]");
}
} }
builder.append(']'); builder.append(']');
return builder.toString(); return builder.toString();

View file

@ -64,7 +64,6 @@ public class PoolMonitor extends
* Instantiates a new VM pool manager. * Instantiates a new VM pool manager.
* *
* @param componentChannel the component channel * @param componentChannel the component channel
* @param channelManager the channel manager
*/ */
public PoolMonitor(Channel componentChannel) { public PoolMonitor(Channel componentChannel) {
super(componentChannel, K8sDynamicModel.class, super(componentChannel, K8sDynamicModel.class,

View file

@ -293,8 +293,9 @@ public class VmMonitor extends
var pool = vmPool; var pool = vmPool;
assignedVm = channelManager.channels().stream() assignedVm = channelManager.channels().stream()
.filter(c -> isAssignable(pool, c.vmDefinition())) .filter(c -> isAssignable(pool, c.vmDefinition()))
.sorted(Comparator.comparing(c -> c.vmDefinition() .sorted(Comparator.comparing((VmChannel c) -> c.vmDefinition()
.assignmentLastUsed().orElse(Instant.ofEpochSecond(0)))) .assignmentLastUsed().orElse(Instant.ofEpochSecond(0)))
.thenComparing(preferRunning))
.findFirst(); .findFirst();
// None found // None found
@ -322,6 +323,19 @@ public class VmMonitor extends
} }
} }
private static Comparator<VmChannel> preferRunning
= new Comparator<>() {
@Override
public int compare(VmChannel ch1, VmChannel ch2) {
if (ch1.vmDefinition().conditionStatus("Running").orElse(false)
&& !ch2.vmDefinition().conditionStatus("Running")
.orElse(false)) {
return -1;
}
return 0;
}
};
@SuppressWarnings("PMD.SimplifyBooleanReturns") @SuppressWarnings("PMD.SimplifyBooleanReturns")
private boolean isAssignable(VmPool pool, VmDefinition vmDef) { private boolean isAssignable(VmPool pool, VmDefinition vmDef) {
// Check if the VM is in the pool // Check if the VM is in the pool

View file

@ -111,12 +111,12 @@ public class VmDefUpdater extends Component {
/** /**
* Update condition. * Update condition.
* *
* @param apiClient the api client * @param from the VM definition
* @param from the vM definition
* @param status the current status * @param status the current status
* @param type the condition type * @param type the condition type
* @param state the new state * @param state the new state
* @param reason the reason for the change * @param reason the reason for the change
* @param message the message
*/ */
protected void updateCondition(VmDefinitionModel from, JsonObject status, protected void updateCondition(VmDefinitionModel from, JsonObject status,
String type, boolean state, String reason, String message) { String type, boolean state, String reason, String message) {

View file

@ -198,9 +198,8 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
// Delete connection file // Delete connection file
deleteConnectionFile deleteConnectionFile
= Optional.ofNullable(c.get("deleteConnectionFile")) = Optional.ofNullable(c.get("deleteConnectionFile"))
.filter(v -> v instanceof String) .map(Object::toString).map(Boolean::parseBoolean)
.map(v -> (String) v) .orElse(true);
.map(Boolean::parseBoolean).orElse(true);
// Users or roles for which previews should be synchronized // Users or roles for which previews should be synchronized
syncUsers = ((List<Map<String, String>>) c.getOrDefault( syncUsers = ((List<Map<String, String>>) c.getOrDefault(
@ -685,8 +684,7 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
* On vm pool changed. * On vm pool changed.
* *
* @param event the event * @param event the event
* @param channel the channel * @throws InterruptedException the interrupted exception
* @throws InterruptedException
*/ */
@Handler(namedChannels = "manager") @Handler(namedChannels = "manager")
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")