Don't duplicate VM management.
This commit is contained in:
parent
5bd6700541
commit
76be59a5b3
5 changed files with 315 additions and 85 deletions
|
|
@ -35,6 +35,7 @@ import org.jdrupes.vmoperator.common.K8sDynamicStub;
|
|||
import org.jdrupes.vmoperator.common.K8sObserver.ResponseType;
|
||||
import org.jdrupes.vmoperator.common.VmPool;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_KIND_VM_POOL;
|
||||
import org.jdrupes.vmoperator.manager.events.GetPools;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jdrupes.vmoperator.manager.events.VmPoolChanged;
|
||||
import org.jdrupes.vmoperator.util.GsonPtr;
|
||||
|
|
@ -161,4 +162,18 @@ public class PoolMonitor extends
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the requested pools.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
public void onGetPools(GetPools event) {
|
||||
event.setResult(pools.values().stream()
|
||||
.filter(p -> event.forUser().isEmpty() && event.forRoles().isEmpty()
|
||||
|| !p.permissionsFor(event.forUser().orElse(null),
|
||||
event.forRoles()).isEmpty())
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,13 @@ import static org.jdrupes.vmoperator.manager.Constants.APP_NAME;
|
|||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_KIND_VM;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
|
||||
import org.jdrupes.vmoperator.manager.events.ChannelManager;
|
||||
import org.jdrupes.vmoperator.manager.events.GetVms;
|
||||
import org.jdrupes.vmoperator.manager.events.GetVms.VmData;
|
||||
import org.jdrupes.vmoperator.manager.events.VmChannel;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Event;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
|
||||
/**
|
||||
* Watches for changes of VM definitions.
|
||||
|
|
@ -208,4 +211,21 @@ public class VmMonitor extends
|
|||
() -> "Cannot access node information: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the VM data.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
public void onGetVms(GetVms event) {
|
||||
event.setResult(channelManager.channels().stream()
|
||||
.filter(c -> event.name().isEmpty()
|
||||
|| c.vmDefinition().name().equals(event.name().get()))
|
||||
.filter(c -> event.user().isEmpty() && event.roles().isEmpty()
|
||||
|| !c.vmDefinition().permissionsFor(event.user().orElse(null),
|
||||
event.roles()).isEmpty())
|
||||
.map(c -> new VmData(c.vmDefinition(), c))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue