Prefer running VMs for new assignments.
This commit is contained in:
parent
6a1273e701
commit
23bc41d68d
1 changed files with 16 additions and 2 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue