Update GUI on pool permission changes.
This commit is contained in:
parent
6d5ba8829c
commit
1cb90b0c94
2 changed files with 31 additions and 15 deletions
|
|
@ -559,6 +559,11 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
result.addAll(pool.permissionsFor(user, roles));
|
result.addAll(pool.permissionsFor(user, roles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (vmDef == null) {
|
||||||
|
vmDef = appPipeline.fire(new GetVms().assignedFrom(model.name())
|
||||||
|
.assignedTo(user)).get().stream().map(VmData::definition)
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
if (vmDef != null) {
|
if (vmDef != null) {
|
||||||
result.addAll(vmDef.permissionsFor(user, roles));
|
result.addAll(vmDef.permissionsFor(user, roles));
|
||||||
}
|
}
|
||||||
|
|
@ -567,32 +572,36 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
|
|
||||||
private void updatePreview(ConsoleConnection channel, ResourceModel model,
|
private void updatePreview(ConsoleConnection channel, ResourceModel model,
|
||||||
VmDefinition vmDef) throws InterruptedException {
|
VmDefinition vmDef) throws InterruptedException {
|
||||||
channel.respond(new NotifyConletView(type(),
|
updateConfig(channel, model, vmDef);
|
||||||
model.getConletId(), "updateConfig", model.mode(), model.name()));
|
|
||||||
updateVmDef(channel, model, vmDef);
|
updateVmDef(channel, model, vmDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateConfig(ConsoleConnection channel, ResourceModel model,
|
||||||
|
VmDefinition vmDef) throws InterruptedException {
|
||||||
|
channel.respond(new NotifyConletView(type(),
|
||||||
|
model.getConletId(), "updateConfig", model.mode(), model.name(),
|
||||||
|
permissions(model, channel.session(), null, vmDef).stream()
|
||||||
|
.map(VmDefinition.Permission::toString).toList()));
|
||||||
|
}
|
||||||
|
|
||||||
private void updateVmDef(ConsoleConnection channel, ResourceModel model,
|
private void updateVmDef(ConsoleConnection channel, ResourceModel model,
|
||||||
VmDefinition vmDef) throws InterruptedException {
|
VmDefinition vmDef) throws InterruptedException {
|
||||||
Map<String, Object> data = null;
|
Map<String, Object> data = null;
|
||||||
if (vmDef != null) {
|
if (vmDef == null) {
|
||||||
|
model.setAssignedVm(null);
|
||||||
|
} else {
|
||||||
model.setAssignedVm(vmDef.name());
|
model.setAssignedVm(vmDef.name());
|
||||||
try {
|
try {
|
||||||
data = Map.of("metadata",
|
data = Map.of("metadata",
|
||||||
Map.of("namespace", vmDef.namespace(),
|
Map.of("namespace", vmDef.namespace(),
|
||||||
"name", vmDef.name()),
|
"name", vmDef.name()),
|
||||||
"spec", vmDef.spec(),
|
"spec", vmDef.spec(),
|
||||||
"status", vmDef.getStatus(),
|
"status", vmDef.getStatus());
|
||||||
"userPermissions",
|
|
||||||
permissions(model, channel.session(), null, vmDef).stream()
|
|
||||||
.map(VmDefinition.Permission::toString).toList());
|
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
logger.log(Level.SEVERE, e,
|
logger.log(Level.SEVERE, e,
|
||||||
() -> "Failed to serialize VM definition");
|
() -> "Failed to serialize VM definition");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
model.setAssignedVm(null);
|
|
||||||
}
|
}
|
||||||
channel.respond(new NotifyConletView(type(),
|
channel.respond(new NotifyConletView(type(),
|
||||||
model.getConletId(), "updateVmDefinition", data));
|
model.getConletId(), "updateVmDefinition", data));
|
||||||
|
|
@ -677,10 +686,12 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
*
|
*
|
||||||
* @param event the event
|
* @param event the event
|
||||||
* @param channel the channel
|
* @param channel the channel
|
||||||
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
@Handler(namedChannels = "manager")
|
@Handler(namedChannels = "manager")
|
||||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||||
public void onVmPoolChanged(VmPoolChanged event) {
|
public void onVmPoolChanged(VmPoolChanged event)
|
||||||
|
throws InterruptedException {
|
||||||
var poolName = event.vmPool().name();
|
var poolName = event.vmPool().name();
|
||||||
// Update known conlets
|
// Update known conlets
|
||||||
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
||||||
|
|
@ -697,7 +708,9 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||||
.isEmpty()) {
|
.isEmpty()) {
|
||||||
connection.respond(
|
connection.respond(
|
||||||
new DeleteConlet(conletId, Collections.emptySet()));
|
new DeleteConlet(conletId, Collections.emptySet()));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
updateConfig(connection, model.get(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ interface Api {
|
||||||
vmName: string;
|
vmName: string;
|
||||||
vmDefinition: any;
|
vmDefinition: any;
|
||||||
poolName: string | null;
|
poolName: string | null;
|
||||||
|
permissions: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const localize = (key: string) => {
|
const localize = (key: string) => {
|
||||||
|
|
@ -64,7 +65,8 @@ window.orgJDrupesVmOperatorVmAccess.initPreview = (previewDom: HTMLElement,
|
||||||
const previewApi: Api = reactive({
|
const previewApi: Api = reactive({
|
||||||
vmName: "",
|
vmName: "",
|
||||||
vmDefinition: {},
|
vmDefinition: {},
|
||||||
poolName: null
|
poolName: null,
|
||||||
|
permissions: []
|
||||||
});
|
});
|
||||||
const poolName = computed(() => previewApi.poolName);
|
const poolName = computed(() => previewApi.poolName);
|
||||||
const vmName = computed(() => previewApi.vmDefinition.name);
|
const vmName = computed(() => previewApi.vmDefinition.name);
|
||||||
|
|
@ -77,15 +79,14 @@ window.orgJDrupesVmOperatorVmAccess.initPreview = (previewDom: HTMLElement,
|
||||||
const startable = computed(() => previewApi.vmDefinition.spec
|
const startable = computed(() => previewApi.vmDefinition.spec
|
||||||
&& previewApi.vmDefinition.spec.vm.state !== 'Running'
|
&& previewApi.vmDefinition.spec.vm.state !== 'Running'
|
||||||
&& !previewApi.vmDefinition.running
|
&& !previewApi.vmDefinition.running
|
||||||
&& previewApi.vmDefinition.userPermissions.includes('start')
|
&& previewApi.permissions.includes('start')
|
||||||
|| previewApi.poolName !== null && !previewApi.vmDefinition.name);
|
|| previewApi.poolName !== null && !previewApi.vmDefinition.name);
|
||||||
const stoppable = computed(() => previewApi.vmDefinition.spec &&
|
const stoppable = computed(() => previewApi.vmDefinition.spec &&
|
||||||
previewApi.vmDefinition.spec.vm.state !== 'Stopped'
|
previewApi.vmDefinition.spec.vm.state !== 'Stopped'
|
||||||
&& previewApi.vmDefinition.running);
|
&& previewApi.vmDefinition.running);
|
||||||
const running = computed(() => previewApi.vmDefinition.running);
|
const running = computed(() => previewApi.vmDefinition.running);
|
||||||
const inUse = computed(() => previewApi.vmDefinition.usedBy != '');
|
const inUse = computed(() => previewApi.vmDefinition.usedBy != '');
|
||||||
const permissions = computed(() => previewApi.vmDefinition.spec
|
const permissions = computed(() => previewApi.permissions);
|
||||||
? previewApi.vmDefinition.userPermissions : []);
|
|
||||||
|
|
||||||
watch(previewApi, (api: Api) => {
|
watch(previewApi, (api: Api) => {
|
||||||
JGConsole.instance.updateConletTitle(conletId,
|
JGConsole.instance.updateConletTitle(conletId,
|
||||||
|
|
@ -150,7 +151,8 @@ window.orgJDrupesVmOperatorVmAccess.initPreview = (previewDom: HTMLElement,
|
||||||
|
|
||||||
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmaccess.VmAccess",
|
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmaccess.VmAccess",
|
||||||
"updateConfig",
|
"updateConfig",
|
||||||
function(conletId: string, type: string, resource: string) {
|
function(conletId: string, type: string, resource: string,
|
||||||
|
permissions: []) {
|
||||||
const conlet = JGConsole.findConletPreview(conletId);
|
const conlet = JGConsole.findConletPreview(conletId);
|
||||||
if (!conlet) {
|
if (!conlet) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -164,6 +166,7 @@ JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmaccess.VmAccess",
|
||||||
api.poolName = resource;
|
api.poolName = resource;
|
||||||
api.vmName = "";
|
api.vmName = "";
|
||||||
}
|
}
|
||||||
|
api.permissions = permissions;
|
||||||
});
|
});
|
||||||
|
|
||||||
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmaccess.VmAccess",
|
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmaccess.VmAccess",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue