Set loggedInUser via Reconciler.

This commit is contained in:
Michael Lipp 2025-03-04 13:33:54 +01:00
parent 28b1903acc
commit bfe4c2bb32
10 changed files with 111 additions and 74 deletions

View file

@ -141,6 +141,16 @@ public class VmDefinition extends K8sDynamicModel {
}
}
/**
* The assignment information.
*
* @param pool the pool
* @param user the user
* @param lastUsed the last used
*/
public record Assignment(String pool, String user, Instant lastUsed) {
}
/**
* Instantiates a new vm definition.
*
@ -215,31 +225,15 @@ public class VmDefinition extends K8sDynamicModel {
}
/**
* The pool that the VM was taken from.
* The assignment information.
*
* @return the optional
*/
public Optional<String> assignedFrom() {
return fromStatus(Status.ASSIGNMENT, "pool");
}
/**
* The user that the VM was assigned to.
*
* @return the optional
*/
public Optional<String> assignedTo() {
return fromStatus(Status.ASSIGNMENT, "user");
}
/**
* Last usage of assigned VM.
*
* @return the optional
*/
public Optional<Instant> assignmentLastUsed() {
return this.<String> fromStatus(Status.ASSIGNMENT, "lastUsed")
.map(Instant::parse);
public Optional<Assignment> assignment() {
return this.<Map<String, Object>> fromStatus(Status.ASSIGNMENT)
.filter(m -> !m.isEmpty()).map(a -> new Assignment(
a.get("pool").toString(), a.get("user").toString(),
Instant.parse(a.get("lastUsed").toString())));
}
/**

View file

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.jdrupes.vmoperator.common.VmDefinition.Assignment;
import org.jdrupes.vmoperator.common.VmDefinition.Grant;
import org.jdrupes.vmoperator.common.VmDefinition.Permission;
import org.jdrupes.vmoperator.util.DataPath;
@ -165,13 +166,12 @@ public class VmPool {
}
// If not assigned, it's usable
if (vmDef.assignedTo().isEmpty()) {
if (vmDef.assignment().isEmpty()) {
return true;
}
// Check if it is to be retained
if (vmDef.assignmentLastUsed()
.map(this::retainUntil)
if (vmDef.assignment().map(Assignment::lastUsed).map(this::retainUntil)
.map(ru -> Instant.now().isBefore(ru)).orElse(false)) {
return false;
}