diff --git a/org.jdrupes.vmoperator.manager.events/src/org/jdrupes/vmoperator/manager/events/GetPools.java b/org.jdrupes.vmoperator.manager.events/src/org/jdrupes/vmoperator/manager/events/GetPools.java index 12575995e..40fa6ad5c 100644 --- a/org.jdrupes.vmoperator.manager.events/src/org/jdrupes/vmoperator/manager/events/GetPools.java +++ b/org.jdrupes.vmoperator.manager.events/src/org/jdrupes/vmoperator/manager/events/GetPools.java @@ -30,9 +30,21 @@ @SuppressWarnings("PMD.DataClass") public class GetPools extends Event> { + private String name; private String user; private List roles = Collections.emptyList(); + /** + * Return only the pool with the given name. + * + * @param name the name + * @return the returns the vms + */ + public GetPools withName(String name) { + this.name = name; + return this; + } + /** * Return only {@link VmPool}s that are accessible by * the given user or roles. @@ -47,6 +59,15 @@ public GetPools accessibleFor(String user, List roles) { return this; } + /** + * Returns the name filter criterion, if set. + * + * @return the optional + */ + public Optional name() { + return Optional.ofNullable(name); + } + /** * Returns the user filter criterion, if set. * diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java index 1864ea7df..00033ba14 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java @@ -171,6 +171,8 @@ public void onVmDefChanged(VmDefChanged event) { @Handler public void onGetPools(GetPools event) { event.setResult(pools.values().stream() + .filter(p -> event.name().isEmpty() + || p.name().equals(event.name().get())) .filter(p -> event.forUser().isEmpty() && event.forRoles().isEmpty() || !p.permissionsFor(event.forUser().orElse(null), event.forRoles()).isEmpty()) diff --git a/org.jdrupes.vmoperator.vmaccess/src/org/jdrupes/vmoperator/vmaccess/VmAccess.java b/org.jdrupes.vmoperator.vmaccess/src/org/jdrupes/vmoperator/vmaccess/VmAccess.java index 8d1a71adb..c48488af7 100644 --- a/org.jdrupes.vmoperator.vmaccess/src/org/jdrupes/vmoperator/vmaccess/VmAccess.java +++ b/org.jdrupes.vmoperator.vmaccess/src/org/jdrupes/vmoperator/vmaccess/VmAccess.java @@ -38,7 +38,6 @@ import java.util.Base64; import java.util.Collections; import java.util.EnumSet; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -133,8 +132,6 @@ public class VmAccess extends FreeMarkerConlet { private Set syncUsers = Collections.emptySet(); private Set syncRoles = Collections.emptySet(); private boolean deleteConnectionFile = true; - @SuppressWarnings("PMD.UseConcurrentHashMap") - private final Map vmPools = new HashMap<>(); /** * The periodically generated update event. @@ -452,7 +449,9 @@ private Set renderPreview(RenderConletRequestBase event, if (model.mode() == ResourceModel.Mode.POOL && model.name() != null) { // Remove conlet if pool definition has been removed // or user has not at least one permission - VmPool pool = vmPools.get(model.name()); + VmPool pool = appPipeline + .fire(new GetPools().withName(model.name())).get() + .stream().findFirst().orElse(null); if (pool == null || poolPermissions(pool, channel.session()).isEmpty()) { channel.respond( @@ -588,12 +587,6 @@ public void onVmDefChanged(VmDefChanged event, VmChannel channel) @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public void onVmPoolChanged(VmPoolChanged event) { var poolName = event.vmPool().name(); - if (event.deleted()) { - vmPools.remove(poolName); - } else { - vmPools.put(poolName, event.vmPool()); - } - // Update known conlets for (var entry : conletIdsByConsoleConnection().entrySet()) { var connection = entry.getKey();