Don't duplicate pool management.
This commit is contained in:
parent
76be59a5b3
commit
9b47ad3136
3 changed files with 26 additions and 10 deletions
|
|
@ -30,9 +30,21 @@ import org.jgrapes.core.Event;
|
||||||
@SuppressWarnings("PMD.DataClass")
|
@SuppressWarnings("PMD.DataClass")
|
||||||
public class GetPools extends Event<List<VmPool>> {
|
public class GetPools extends Event<List<VmPool>> {
|
||||||
|
|
||||||
|
private String name;
|
||||||
private String user;
|
private String user;
|
||||||
private List<String> roles = Collections.emptyList();
|
private List<String> 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
|
* Return only {@link VmPool}s that are accessible by
|
||||||
* the given user or roles.
|
* the given user or roles.
|
||||||
|
|
@ -47,6 +59,15 @@ public class GetPools extends Event<List<VmPool>> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name filter criterion, if set.
|
||||||
|
*
|
||||||
|
* @return the optional
|
||||||
|
*/
|
||||||
|
public Optional<String> name() {
|
||||||
|
return Optional.ofNullable(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user filter criterion, if set.
|
* Returns the user filter criterion, if set.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,8 @@ public class PoolMonitor extends
|
||||||
@Handler
|
@Handler
|
||||||
public void onGetPools(GetPools event) {
|
public void onGetPools(GetPools event) {
|
||||||
event.setResult(pools.values().stream()
|
event.setResult(pools.values().stream()
|
||||||
|
.filter(p -> event.name().isEmpty()
|
||||||
|
|| p.name().equals(event.name().get()))
|
||||||
.filter(p -> event.forUser().isEmpty() && event.forRoles().isEmpty()
|
.filter(p -> event.forUser().isEmpty() && event.forRoles().isEmpty()
|
||||||
|| !p.permissionsFor(event.forUser().orElse(null),
|
|| !p.permissionsFor(event.forUser().orElse(null),
|
||||||
event.forRoles()).isEmpty())
|
event.forRoles()).isEmpty())
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ import java.time.Duration;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -133,8 +132,6 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
private Set<String> syncUsers = Collections.emptySet();
|
private Set<String> syncUsers = Collections.emptySet();
|
||||||
private Set<String> syncRoles = Collections.emptySet();
|
private Set<String> syncRoles = Collections.emptySet();
|
||||||
private boolean deleteConnectionFile = true;
|
private boolean deleteConnectionFile = true;
|
||||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
|
||||||
private final Map<String, VmPool> vmPools = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The periodically generated update event.
|
* The periodically generated update event.
|
||||||
|
|
@ -452,7 +449,9 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
if (model.mode() == ResourceModel.Mode.POOL && model.name() != null) {
|
if (model.mode() == ResourceModel.Mode.POOL && model.name() != null) {
|
||||||
// Remove conlet if pool definition has been removed
|
// Remove conlet if pool definition has been removed
|
||||||
// or user has not at least one permission
|
// 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
|
if (pool == null
|
||||||
|| poolPermissions(pool, channel.session()).isEmpty()) {
|
|| poolPermissions(pool, channel.session()).isEmpty()) {
|
||||||
channel.respond(
|
channel.respond(
|
||||||
|
|
@ -588,12 +587,6 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||||
public void onVmPoolChanged(VmPoolChanged event) {
|
public void onVmPoolChanged(VmPoolChanged event) {
|
||||||
var poolName = event.vmPool().name();
|
var poolName = event.vmPool().name();
|
||||||
if (event.deleted()) {
|
|
||||||
vmPools.remove(poolName);
|
|
||||||
} else {
|
|
||||||
vmPools.put(poolName, event.vmPool());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update known conlets
|
// Update known conlets
|
||||||
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
||||||
var connection = entry.getKey();
|
var connection = entry.getKey();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue