Fix VM selection.
This commit is contained in:
parent
1dc3c1cc89
commit
4d5b6a58b7
1 changed files with 18 additions and 8 deletions
|
|
@ -20,6 +20,7 @@ package org.jdrupes.vmoperator.vmviewer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
@ -466,11 +467,18 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "PMD.AvoidDecimalLiteralsInBigDecimalConstructor",
|
@SuppressWarnings({ "PMD.AvoidDecimalLiteralsInBigDecimalConstructor",
|
||||||
"PMD.ConfusingArgumentToVarargsMethod", "PMD.NcssCount" })
|
"PMD.ConfusingArgumentToVarargsMethod", "PMD.NcssCount",
|
||||||
|
"PMD.AvoidLiteralsInIfCondition" })
|
||||||
protected void doUpdateConletState(NotifyConletModel event,
|
protected void doUpdateConletState(NotifyConletModel event,
|
||||||
ConsoleConnection channel, ViewerModel model)
|
ConsoleConnection channel, ViewerModel model)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
event.stop();
|
event.stop();
|
||||||
|
if ("selectedVm".equals(event.method())) {
|
||||||
|
selectVm(event, channel, model);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle command for selected VM
|
||||||
var both = Optional.ofNullable(model.vmName())
|
var both = Optional.ofNullable(model.vmName())
|
||||||
.flatMap(vm -> channelManager.both(vm));
|
.flatMap(vm -> channelManager.both(vm));
|
||||||
if (both.isEmpty()) {
|
if (both.isEmpty()) {
|
||||||
|
|
@ -482,13 +490,6 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
||||||
var perms = permissions(vmDef, channel.session());
|
var perms = permissions(vmDef, channel.session());
|
||||||
var resourceBundle = resourceBundle(channel.locale());
|
var resourceBundle = resourceBundle(channel.locale());
|
||||||
switch (event.method()) {
|
switch (event.method()) {
|
||||||
case "selectedVm":
|
|
||||||
model.setVmName(event.params().asString(0));
|
|
||||||
String jsonState = objectMapper.writeValueAsString(model);
|
|
||||||
channel.respond(new KeyValueStoreUpdate().update(storagePath(
|
|
||||||
channel.session(), model.getConletId()), jsonState));
|
|
||||||
updateConfig(channel, model);
|
|
||||||
break;
|
|
||||||
case "start":
|
case "start":
|
||||||
if (perms.contains(Permission.START)) {
|
if (perms.contains(Permission.START)) {
|
||||||
fire(new ModifyVm(vmName, "state", "Running", vmChannel));
|
fire(new ModifyVm(vmName, "state", "Running", vmChannel));
|
||||||
|
|
@ -522,6 +523,15 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void selectVm(NotifyConletModel event, ConsoleConnection channel,
|
||||||
|
ViewerModel model) throws JsonProcessingException {
|
||||||
|
model.setVmName(event.params().asString(0));
|
||||||
|
String jsonState = objectMapper.writeValueAsString(model);
|
||||||
|
channel.respond(new KeyValueStoreUpdate().update(storagePath(
|
||||||
|
channel.session(), model.getConletId()), jsonState));
|
||||||
|
updateConfig(channel, model);
|
||||||
|
}
|
||||||
|
|
||||||
private void openConsole(String vmName, ConsoleConnection connection,
|
private void openConsole(String vmName, ConsoleConnection connection,
|
||||||
ViewerModel model, String password) {
|
ViewerModel model, String password) {
|
||||||
var vmDef = channelManager.associated(vmName).orElse(null);
|
var vmDef = channelManager.associated(vmName).orElse(null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue