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
resources:
- vms
- vmpools
verbs:
- '*'
- apiGroups:

View file

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

View file

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

View file

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

View file

@ -293,8 +293,9 @@ public class VmMonitor extends
var pool = vmPool;
assignedVm = channelManager.channels().stream()
.filter(c -> isAssignable(pool, c.vmDefinition()))
.sorted(Comparator.comparing(c -> c.vmDefinition()
.assignmentLastUsed().orElse(Instant.ofEpochSecond(0))))
.sorted(Comparator.comparing((VmChannel c) -> c.vmDefinition()
.assignmentLastUsed().orElse(Instant.ofEpochSecond(0)))
.thenComparing(preferRunning))
.findFirst();
// 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")
private boolean isAssignable(VmPool pool, VmDefinition vmDef) {
// Check if the VM is in the pool

View file

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

View file

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