Frank Kobzik has uploaded a new change for review. Change subject: engine: Phase 3: Configuring ConsoleOptions on backend ......................................................................
engine: Phase 3: Configuring ConsoleOptions on backend Move filling ConsoleOptions from *ConsoleModel(s) to backend. Small cleanups in SpiceConsoleModel spaghetti code (generating menu). todo describe cleanups (configurator, consolemodels etc) Got rid of explicit setting VM ticket. It is done in ConfigureConsoleOptionsQuery instead. Change-Id: Ida16e4de2701d6f6b3f6b3ed52eddca805fa43a7 Signed-off-by: Frantisek Kobzik <fkob...@redhat.com> Bug-Url: https://bugzilla.redhat.com/1128763 --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQuery.java A backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQueryTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/console/ConsoleOptions.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigureConsoleOptionsParams.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConsoleOptionsParams.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/console/ConsoleOptionsTest.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractSpice.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractVnc.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Configurator.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleClient.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java 15 files changed, 488 insertions(+), 384 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/37974/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQuery.java new file mode 100644 index 0000000..158e25c --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQuery.java @@ -0,0 +1,211 @@ +package org.ovirt.engine.core.bll; + +import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.common.action.SetVmTicketParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.GraphicsInfo; +import org.ovirt.engine.core.common.businessentities.GraphicsType; +import org.ovirt.engine.core.common.businessentities.UsbPolicy; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.common.console.ConsoleOptions; +import org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +/** + * Query for filling required backend data to given ConsoleOptions. + * Clients (frontend and restapi) use this query before initiating console session. + * + * @param <P> ConsoleOptions instance filled with 2 required parameters + * - vmId - id of VM for which options are configured + * - graphicsType - protocol for which options are configured + */ +public class ConfigureConsoleOptionsQuery<P extends ConfigureConsoleOptionsParams> extends QueriesCommandBase<P> { + + private VM cachedVm; + private GraphicsType graphicsType; + + public ConfigureConsoleOptionsQuery(P parameters) { + super(parameters); + } + + @Override + protected boolean validateInputs() { + ConsoleOptions options = getParameters().getOptions(); + if (options == null) { + getQueryReturnValue().setExceptionString("Console options can't be null."); + return false; + } + + if (options.getGraphicsType() == null) { + getQueryReturnValue().setExceptionString("Graphics type must be filled in console options."); + return false; + } + + if (options.getVmId() == null) { + getQueryReturnValue().setExceptionString("VM id must be filled in console options."); + return false; + } + + return super.validateInputs(); + } + + @Override + protected void executeQueryCommand() { + boolean success = true; + + ConsoleOptions options = getParameters().getOptions(); + this.graphicsType = options.getGraphicsType(); + this.cachedVm = getCachedVm(); + + fillCommonPart(options); + if (options.getGraphicsType() == GraphicsType.SPICE) { + success = fillSpice(options); + } + + getQueryReturnValue().setSucceeded(success); + if (success) { + setReturnValue(options); + } + } + + private void fillCommonPart(ConsoleOptions options) { + GraphicsInfo graphicsInfo = cachedVm.getGraphicsInfos().get(graphicsType); + + options.setHost(determineHost()); + options.setPort(graphicsInfo.getPort()); + options.setSmartcardEnabled(cachedVm.isSmartcardEnabled()); + if (getParameters().isSetTicket()) { + options.setTicket(generateTicket()); + } + options.setToggleFullscreenHotKey((String) getConfigValue(ConfigValues.ConsoleToggleFullScreenKeys)); + options.setReleaseCursorHotKey((String) getConfigValue(ConfigValues.ConsoleReleaseCursorKeys)); + } + + private boolean fillSpice(ConsoleOptions options) { + boolean success = true; + GraphicsInfo graphicsInfo = cachedVm.getGraphicsInfos().get(graphicsType); + + options.setSmartcardEnabled(cachedVm.isSmartcardEnabled()); + options.setNumberOfMonitors(cachedVm.getNumOfMonitors()); + options.setGuestHostName(cachedVm.getVmHost().split("[ ]", -1)[0]); //$NON-NLS-1$ + if (graphicsInfo.getTlsPort() != null) { + options.setSecurePort(graphicsInfo.getTlsPort()); + } + + if (getConfigValue(ConfigValues.SSLEnabled)) { + String spiceSecureChannels = getConfigValue(ConfigValues.SpiceSecureChannels); + if (!StringUtils.isBlank(spiceSecureChannels)) { + options.setSslChanels(spiceSecureChannels); + } + String cipherSuite = getConfigValue(ConfigValues.CipherSuite); + if (!StringUtils.isBlank(cipherSuite)) { + options.setCipherSuite(cipherSuite); + } + } + + String certificateSubject = ""; + String caCertificate = ""; + + // if SPICE root certificate validation is enabled + // but the root certificate cannot be retrieved -> FAIL + if (getConfigValue(ConfigValues.EnableSpiceRootCertificateValidation)) { + VdcQueryReturnValue certificate = getCACertificate(); + if (!certificate.getSucceeded()) { + getQueryReturnValue().setExceptionString("Spice Root Certificate Validation enforced, but no CA found!"); + return false; + } + certificateSubject = getVdsCertificateSubject(); + caCertificate = certificate.getReturnValue(); + } + options.setHostSubject(certificateSubject); + options.setTrustStore(caCertificate); + + options.setSpiceProxy(determineSpiceProxy()); + + // Update 'UsbListenPort' value + boolean getIsUsbEnabled = getConfigValue(ConfigValues.EnableUSBAsDefault); + options.setUsbListenPort(getIsUsbEnabled && cachedVm.getUsbPolicy() == UsbPolicy.ENABLED_LEGACY + ? ConsoleOptions.SPICE_USB_DEFAULT_PORT + : ConsoleOptions.SET_SPICE_DISABLE_USB_LISTEN_PORT); + + return success; + } + + private String generateTicket() { + SetVmTicketParameters parameters = new SetVmTicketParameters( + getParameters().getOptions().getVmId(), + null, + ConsoleOptions.TICKET_VALIDITY_SECONDS, + getParameters().getOptions().getGraphicsType()); + // we need these two params because SetVmTicket needs to know current user + parameters.setSessionId(getEngineContext().getSessionId()); + parameters.setParametersCurrentUser(getUser()); + + VdcReturnValueBase result = getBackend().runInternalAction(VdcActionType.SetVmTicket, parameters); + + if (result.getSucceeded()) { + return result.getActionReturnValue(); + } + + return null; + } + + private String getVdsCertificateSubject() { + return getBackend().runInternalQuery( + VdcQueryType.GetVdsCertificateSubjectByVmId, + new IdQueryParameters(cachedVm.getId())).getReturnValue(); + + } + + private VdcQueryReturnValue getCACertificate() { + return getBackend().runInternalQuery(VdcQueryType.GetCACertificate, new VdcQueryParametersBase()); + } + + private String determineHost() { + GraphicsInfo graphicsInfo = cachedVm.getGraphicsInfos().get(graphicsType); + String result = graphicsInfo.getIp(); + + // if we don't have display ip, we try management network of host + if (StringUtils.isBlank(result) || "0".equals(result)) { + VdcQueryReturnValue returnValue = getBackend().runInternalQuery( + VdcQueryType.GetManagementInterfaceAddressByVmId, + new IdQueryParameters(cachedVm.getId())); + result = returnValue.getReturnValue(); + } + + return result; + } + + private String determineSpiceProxy() { + if (!StringUtils.isNotBlank(cachedVm.getVmPoolSpiceProxy())) { + return cachedVm.getVmPoolSpiceProxy(); + } + + if (!StringUtils.isNotBlank(cachedVm.getVdsGroupSpiceProxy())) { + return cachedVm.getVdsGroupSpiceProxy(); + } + + String globalSpiceProxy = getConfigValue(ConfigValues.SpiceProxyDefault); + if (StringUtils.isNotBlank(globalSpiceProxy)) { + return globalSpiceProxy; + } + + return null; + } + + VM getCachedVm() { + return getBackend().runInternalQuery( + VdcQueryType.GetVmByVmId, + new IdQueryParameters(getParameters().getOptions().getVmId())).getReturnValue(); + } + + <T> T getConfigValue(ConfigValues value) { + return Config.getValue(value); + } +} diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQueryTest.java new file mode 100644 index 0000000..bb83258 --- /dev/null +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ConfigureConsoleOptionsQueryTest.java @@ -0,0 +1,131 @@ +package org.ovirt.engine.core.bll; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.bll.interfaces.BackendInternal; +import org.ovirt.engine.core.common.action.SetVmTicketParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.GraphicsInfo; +import org.ovirt.engine.core.common.businessentities.GraphicsType; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.common.console.ConsoleOptions; +import org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigureConsoleOptionsQueryTest { + + @Mock + BackendInternal backend; + + @Test + public void shouldFailtWhenNoId() { + ConsoleOptions options = new ConsoleOptions(GraphicsType.SPICE); + ConfigureConsoleOptionsQuery query = + new ConfigureConsoleOptionsQuery(new ConfigureConsoleOptionsParams(options, false)); + assertFalse(query.validateInputs()); + } + + @Test + public void shouldFailtWhenNoGraphicsType() { + ConsoleOptions options = new ConsoleOptions(); + ConfigureConsoleOptionsQuery query = + new ConfigureConsoleOptionsQuery(new ConfigureConsoleOptionsParams(options, false)); + assertFalse(query.validateInputs()); + } + + @Test + public void testInputDataOk() { + ConfigureConsoleOptionsQuery query = + new ConfigureConsoleOptionsQuery(new ConfigureConsoleOptionsParams(getValidOptions(GraphicsType.SPICE), false)); + assertTrue(query.validateInputs()); + } + + private ConsoleOptions getValidOptions(GraphicsType graphicsType) { + ConsoleOptions options = new ConsoleOptions(graphicsType); + options.setVmId(Guid.Empty); + return options; + } + + @Test + public void shouldCallSetTicket() { + ConfigureConsoleOptionsParams params = new ConfigureConsoleOptionsParams(getValidOptions(GraphicsType.VNC), true); + ConfigureConsoleOptionsQuery query = spy(new ConfigureConsoleOptionsQuery(params)); + doReturn(mockVm(GraphicsType.VNC)).when(query).getCachedVm(); + doReturn(null).when(query).getConfigValue(any(ConfigValues.class)); + + VdcReturnValueBase result = new VdcReturnValueBase(); + result.setSucceeded(true); + result.setActionReturnValue("nbusr123"); + doReturn(result).when(backend).runInternalAction(eq(VdcActionType.SetVmTicket), any(SetVmTicketParameters.class)); + doReturn(backend).when(query).getBackend(); + + query.executeQueryCommand(); + verify(backend, times(1)).runInternalAction(eq(VdcActionType.SetVmTicket), any(SetVmTicketParameters.class)); + } + + @Test + public void failWhenCertEnforcedAndCANotFound() { + ConfigureConsoleOptionsParams params = new ConfigureConsoleOptionsParams(getValidOptions(GraphicsType.SPICE), false); + ConfigureConsoleOptionsQuery query = spy(new ConfigureConsoleOptionsQuery(params)); + doReturn(mockVm(GraphicsType.SPICE)).when(query).getCachedVm(); + + mockSpiceRelatedConfig(query); + doReturn(true).when(query).getConfigValue(ConfigValues.EnableSpiceRootCertificateValidation); + + VdcQueryReturnValue caResult = new VdcQueryReturnValue(); + caResult.setSucceeded(false); + doReturn(caResult).when(backend).runInternalQuery(eq(VdcQueryType.GetCACertificate), any(VdcQueryParametersBase.class)); + doReturn(backend).when(query).getBackend(); + + query.executeQueryCommand(); + assertFalse(query.getQueryReturnValue().getSucceeded()); + } + + @Test + public void passWhenCertNotEnforcedAndCANotFound() { + ConfigureConsoleOptionsParams params = new ConfigureConsoleOptionsParams(getValidOptions(GraphicsType.SPICE), false); + ConfigureConsoleOptionsQuery query = spy(new ConfigureConsoleOptionsQuery(params)); + doReturn(mockVm(GraphicsType.SPICE)).when(query).getCachedVm(); + + mockSpiceRelatedConfig(query); + doReturn(false).when(query).getConfigValue(ConfigValues.EnableSpiceRootCertificateValidation); + + doReturn(null).when(backend).runInternalQuery(eq(VdcQueryType.GetCACertificate), any(VdcQueryParametersBase.class)); + doReturn(backend).when(query).getBackend(); + + query.executeQueryCommand(); + assertTrue(query.getQueryReturnValue().getSucceeded()); + } + + private void mockSpiceRelatedConfig(ConfigureConsoleOptionsQuery query) { + doReturn(null).when(query).getConfigValue(any(ConfigValues.class)); + doReturn(false).when(query).getConfigValue(ConfigValues.SSLEnabled); + doReturn(false).when(query).getConfigValue(ConfigValues.EnableUSBAsDefault); + } + + private VM mockVm(GraphicsType graphicsType) { + VM vm = new VM(); + vm.setId(Guid.Empty); + vm.getGraphicsInfos().put(graphicsType, new GraphicsInfo().setIp("host").setPort(5901)); + return vm; + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/console/ConsoleOptions.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/console/ConsoleOptions.java index 1654411..dab1f04 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/console/ConsoleOptions.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/console/ConsoleOptions.java @@ -49,6 +49,8 @@ private List<WanDisableEffects> wanDisableEffects; public static final int TICKET_VALIDITY_SECONDS = 120; + public static final int SPICE_USB_DEFAULT_PORT = 32023; + public static final int SET_SPICE_DISABLE_USB_LISTEN_PORT = 0; public static final String SECURE_ATTENTION_MAPPING = "ctrl+alt+end";// $NON-NLS-1$ public ConsoleOptions() { // enforced by GWT @@ -318,7 +320,6 @@ public void setWanDisableEffects(List<WanDisableEffects> wanDisableEffects) { this.wanDisableEffects = wanDisableEffects; } - public enum WanColorDepth { depth16(16), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigureConsoleOptionsParams.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigureConsoleOptionsParams.java new file mode 100644 index 0000000..0fb5971 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigureConsoleOptionsParams.java @@ -0,0 +1,20 @@ +package org.ovirt.engine.core.common.queries; + + +import org.ovirt.engine.core.common.console.ConsoleOptions; + +public class ConfigureConsoleOptionsParams extends ConsoleOptionsParams { + + boolean setTicket = false; + + public ConfigureConsoleOptionsParams() { } + + public ConfigureConsoleOptionsParams(ConsoleOptions options, boolean setTicket) { + super(options); + this.setTicket = setTicket; + } + + public boolean isSetTicket() { + return setTicket; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConsoleOptionsParams.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConsoleOptionsParams.java new file mode 100644 index 0000000..f56ad33 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConsoleOptionsParams.java @@ -0,0 +1,18 @@ +package org.ovirt.engine.core.common.queries; + +import org.ovirt.engine.core.common.console.ConsoleOptions; + +public class ConsoleOptionsParams extends VdcQueryParametersBase { + + ConsoleOptions options; + + public ConsoleOptionsParams() { } + + public ConsoleOptionsParams(ConsoleOptions options) { + this.options = options; + } + + public ConsoleOptions getOptions() { + return options; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 65b8891..d4534a0 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -373,6 +373,8 @@ GetRngDevice(VdcQueryAuthType.User), GetGraphicsDevices(VdcQueryAuthType.User), + ConfigureConsoleOptions(VdcQueryAuthType.User), + GetDeviceCustomProperties(VdcQueryAuthType.User), // Scheduling diff --git a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/console/ConsoleOptionsTest.java b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/console/ConsoleOptionsTest.java index 9101e0e..1cba6ba 100644 --- a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/console/ConsoleOptionsTest.java +++ b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/console/ConsoleOptionsTest.java @@ -29,4 +29,4 @@ assertEquals(correctChannels, ConsoleOptions.adjustLegacySecureChannels(legacyChannels)); } -} \ No newline at end of file +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractSpice.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractSpice.java index d21c5e6..db84361 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractSpice.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractSpice.java @@ -8,7 +8,7 @@ public abstract class AbstractSpice { - protected final ConsoleOptions consoleOptions = new ConsoleOptions(GraphicsType.SPICE); + protected ConsoleOptions consoleOptions = new ConsoleOptions(GraphicsType.SPICE); // long term todo - move these events to plugin impl protected Event<EventArgs> disconnectedEvent = new Event<>(SpiceConsoleModel.spiceDisconnectedEventDefinition); @@ -23,6 +23,10 @@ return consoleOptions; } + public void setOptions(ConsoleOptions consoleOptions) { + this.consoleOptions = consoleOptions; + } + public Event<EventArgs> getDisconnectedEvent() { return disconnectedEvent; } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractVnc.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractVnc.java index 8608210..7e3812f 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractVnc.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/AbstractVnc.java @@ -5,12 +5,16 @@ public class AbstractVnc { - private final ConsoleOptions consoleOptions = new ConsoleOptions(GraphicsType.VNC); + private ConsoleOptions consoleOptions = new ConsoleOptions(GraphicsType.VNC); public ConsoleOptions getOptions() { return consoleOptions; } + public void setOptions(ConsoleOptions consoleOptions) { + this.consoleOptions = consoleOptions; + } + public AbstractVnc() { consoleOptions.setRemapCtrlAltDelete(true); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Configurator.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Configurator.java index 8dd2ee7..d0fc370 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Configurator.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Configurator.java @@ -45,8 +45,6 @@ documentationLangPath = currentLocale.replaceAll("_", "-") + "/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setSpiceVersion(new Version(4, 4)); - setSpiceDefaultUsbPort(32023); - setSpiceDisableUsbListenPort(0); setBackendPort("8700"); //$NON-NLS-1$ setLogLevel("INFO"); //$NON-NLS-1$ setPollingTimerInterval(5000); @@ -54,8 +52,6 @@ protected static final String DEFAULT_USB_FILTER = "-1,-1,-1,-1,0"; //$NON-NLS-1$ protected String usbFilter = DEFAULT_USB_FILTER; - - private boolean isInitialized; /** * Gets or sets the value specifying what is the desired Spice version. @@ -78,36 +74,6 @@ protected void setIsAdmin(boolean value) { privateIsAdmin = value; - } - - private int privateSpiceDefaultUsbPort; - - public int getSpiceDefaultUsbPort() { - return privateSpiceDefaultUsbPort; - } - - protected void setSpiceDefaultUsbPort(int value) { - privateSpiceDefaultUsbPort = value; - } - - private int privateSpiceDisableUsbListenPort; - - public int getSpiceDisableUsbListenPort() { - return privateSpiceDisableUsbListenPort; - } - - protected void setSpiceDisableUsbListenPort(int value) { - privateSpiceDisableUsbListenPort = value; - } - - private boolean privateIsUsbEnabled; - - public boolean getIsUsbEnabled() { - return privateIsUsbEnabled; - } - - protected void setIsUsbEnabled(boolean value) { - privateIsUsbEnabled = value; } private boolean privateSpiceAdminConsole; @@ -273,22 +239,6 @@ spice.getOptions().setFullScreen(getSpiceFullScreen()); spice.getOptions().setUsbFilter(getUsbFilter()); updateSpiceUsbAutoShare(spice); - - if (!isInitialized) { - updateIsUsbEnabled(); - isInitialized = true; - } - } - - private void updateIsUsbEnabled() { - // Get 'EnableUSBAsDefault' value from database - AsyncDataProvider.getInstance().isUSBEnabledByDefault(new AsyncQuery(this, new INewAsyncCallback() { - @Override - public void onSuccess(Object target, Object returnValue) { - // Update IsUsbEnabled value - setIsUsbEnabled((Boolean) returnValue); - } - })); } private void updateSpiceUsbAutoShare(final ISpice spice) { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java index 9d99a48..3d79bc3 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java @@ -1871,20 +1871,6 @@ Frontend.getInstance().runQuery(VdcQueryType.GetAllVmTemplates, params, aQuery); } - public void isUSBEnabledByDefault(AsyncQuery aQuery) { - aQuery.converterCallback = new IAsyncConverter() { - @Override - public Object Convert(Object source, AsyncQuery _asyncQuery) - { - return source != null ? ((Boolean) source).booleanValue() : false; - } - }; - getConfigFromCache( - new GetConfigurationValueParameters(ConfigurationValues.EnableUSBAsDefault, - getDefaultConfigurationVersion()), - aQuery); - } - public void getStorageConnectionById(AsyncQuery aQuery, String id, boolean isRefresh) { aQuery.converterCallback = new IAsyncConverter() { @Override diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleClient.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleClient.java index 8e1fe40..95e3f24 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleClient.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleClient.java @@ -4,5 +4,6 @@ public interface ConsoleClient { ConsoleOptions getOptions(); + void setOptions(ConsoleOptions options); void invokeClient(); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java index 24a6c0b..f7bb5a1 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java @@ -291,19 +291,12 @@ return textArea; } - protected String getToggleFullScreenKeys() { - return (String) AsyncDataProvider.getInstance().getConfigValuePreConverted(ConfigurationValues.ConsoleToggleFullScreenKeys); - } - - protected String getReleaseCursorKeys() { - return (String) AsyncDataProvider.getInstance().getConfigValuePreConverted(ConfigurationValues.ConsoleReleaseCursorKeys); - } - protected String getClientTitle() { - String releaseCursorKeys = getReleaseCursorKeys(); - String releaseCursorKeysTranslated = - AsyncDataProvider.getInstance().getComplexValueFromSpiceRedKeysResource((releaseCursorKeys != null) ? releaseCursorKeys - : "shift+f12"); //$NON-NLS-1$ + AsyncDataProvider asyncDataProvider = AsyncDataProvider.getInstance(); + String releaseCursorKeys = (String) asyncDataProvider + .getConfigValuePreConverted(ConfigurationValues.ConsoleReleaseCursorKeys); + String releaseCursorKeysTranslated = asyncDataProvider + .getComplexValueFromSpiceRedKeysResource((releaseCursorKeys != null) ? releaseCursorKeys : "shift+f12"); //$NON-NLS-1$ String releaseCursorMsg = ""; //$NON-NLS-1$ diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java index 547bf40..4ed5e4a 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java @@ -7,7 +7,6 @@ import org.ovirt.engine.core.common.action.ChangeDiskCommandParameters; import org.ovirt.engine.core.common.action.RunVmParams; -import org.ovirt.engine.core.common.action.SetVmTicketParameters; import org.ovirt.engine.core.common.action.ShutdownVmParameters; import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; @@ -19,20 +18,15 @@ import org.ovirt.engine.core.common.businessentities.RepoImage; import org.ovirt.engine.core.common.businessentities.SsoMethod; import org.ovirt.engine.core.common.businessentities.StorageDomain; -import org.ovirt.engine.core.common.businessentities.UsbPolicy; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; import org.ovirt.engine.core.common.console.ConsoleOptions; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.queries.ConfigurationValues; -import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; +import org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams; import org.ovirt.engine.core.common.queries.GetImagesListByStoragePoolIdParameters; -import org.ovirt.engine.core.common.queries.IdQueryParameters; -import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; -import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.compat.StringHelper; import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.frontend.INewAsyncCallback; @@ -49,11 +43,9 @@ import org.ovirt.engine.ui.uicompat.EventArgs; import org.ovirt.engine.ui.uicompat.EventDefinition; import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; -import org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult; import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback; -import org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback; -public class SpiceConsoleModel extends ConsoleModel implements IFrontendMultipleQueryAsyncCallback { +public class SpiceConsoleModel extends ConsoleModel { public enum ClientConsoleMode { Native, Plugin, Auto, Html5 } @@ -171,13 +163,13 @@ getspice().getOptions().setWanOptionsEnabled(false); } - UICommand setVmTicketCommand = new UICommand("setVmCommand", new BaseCommandTarget() { //$NON-NLS-1$ + UICommand invokeConsoleCommand = new UICommand("invokeConsoleCommand", new BaseCommandTarget() { //$NON-NLS-1$ @Override public void executeCommand(UICommand uiCommand) { - setVmTicket(); + invokeConsole(); } }); - executeCommandWithConsoleSafenessWarning(setVmTicketCommand); + executeCommandWithConsoleSafenessWarning(invokeConsoleCommand); } } @@ -266,141 +258,79 @@ } private void executeQuery(final VM vm) { - AsyncQuery _asyncQuery0 = new AsyncQuery(); - _asyncQuery0.setModel(this); - - _asyncQuery0.asyncCallback = new INewAsyncCallback() { + final AsyncQuery imagesListQuery = new AsyncQuery(); + imagesListQuery.setModel(this); + imagesListQuery.asyncCallback = new INewAsyncCallback() { @Override - public void onSuccess(Object model0, Object result0) { - SpiceConsoleModel thisSpiceConsoleModel = (SpiceConsoleModel) model0; - VM thisVm = thisSpiceConsoleModel.getEntity(); - - StorageDomain isoDomain = null; - if (result0 != null) { - isoDomain = (StorageDomain) result0; - } - - ArrayList<VdcQueryType> queryTypeList = new ArrayList<VdcQueryType>(); - queryTypeList.add(VdcQueryType.GetConfigurationValue); - queryTypeList.add(VdcQueryType.GetConfigurationValue); - queryTypeList.add(VdcQueryType.GetConfigurationValue); - queryTypeList.add(VdcQueryType.GetConfigurationValue); - queryTypeList.add(VdcQueryType.GetVdsCertificateSubjectByVmId); - queryTypeList.add(VdcQueryType.GetCACertificate); - - ArrayList<VdcQueryParametersBase> parametersList = - new ArrayList<VdcQueryParametersBase>(); - parametersList.add(new GetConfigurationValueParameters(ConfigurationValues.SSLEnabled, AsyncDataProvider.getInstance().getDefaultConfigurationVersion())); - parametersList.add(new GetConfigurationValueParameters(ConfigurationValues.CipherSuite, AsyncDataProvider.getInstance().getDefaultConfigurationVersion())); - parametersList.add(new GetConfigurationValueParameters(ConfigurationValues.SpiceSecureChannels, - thisVm.getVdsGroupCompatibilityVersion().toString())); - parametersList.add(new GetConfigurationValueParameters(ConfigurationValues.EnableSpiceRootCertificateValidation, AsyncDataProvider.getInstance().getDefaultConfigurationVersion())); - parametersList.add(new IdQueryParameters(thisVm.getId())); - parametersList.add(new VdcQueryParametersBase()); - - if (isoDomain != null) { - queryTypeList.add(VdcQueryType.GetImagesListByStoragePoolId); - - GetImagesListByStoragePoolIdParameters getIsoParams = - new GetImagesListByStoragePoolIdParameters(vm.getStoragePoolId(), ImageFileType.ISO); - parametersList.add(getIsoParams); - } - - Frontend.getInstance().runMultipleQueries(queryTypeList, parametersList, thisSpiceConsoleModel); + public void onSuccess(Object model, Object returnValue) { + List<RepoImage> repoImages = ((VdcQueryReturnValue) returnValue).getReturnValue(); + ((SpiceConsoleModel) model).invokeClient(repoImages); } }; - AsyncDataProvider.getInstance().getIsoDomainByDataCenterId(_asyncQuery0, vm.getStoragePoolId()); - } + AsyncQuery isoDomainQuery = new AsyncQuery(); + isoDomainQuery.setModel(this); + isoDomainQuery.asyncCallback = new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object result) { + StorageDomain isoDomain = (StorageDomain) result; + if (isoDomain != null) { + GetImagesListByStoragePoolIdParameters getIsoParams = + new GetImagesListByStoragePoolIdParameters(vm.getStoragePoolId(), ImageFileType.ISO); - private String ticket; - - @Override - public void executed(FrontendMultipleQueryAsyncResult result) { - List<VdcQueryReturnValue> returnValues = result.getReturnValues(); - - boolean success = true; - for (VdcQueryReturnValue returnValue : returnValues) { - if (!returnValue.getSucceeded()) { - success = false; - break; - } - } - - if (!success) { - boolean enableSpiceRootCertificateValidation = (Boolean) result.getReturnValues().get(3).getReturnValue(); - VdcQueryReturnValue caCertificateReturnValue = result.getReturnValues().get(5); - - // If only the caCertificate query failed - ignore failure (goto onSuccess) - if (!caCertificateReturnValue.getSucceeded() && !enableSpiceRootCertificateValidation) { - // Verify that all queries (except caCertificate) succeeded - // If succeeded goto 'onSuccess'; Otherwise, 'onFailure'. - for (VdcQueryReturnValue returnValue : returnValues) { - if (!returnValue.getSucceeded() && returnValue != caCertificateReturnValue) { - return; - } + Frontend.getInstance().runQuery( + VdcQueryType.GetImagesListByStoragePoolId, + getIsoParams, + imagesListQuery); + } else { + ((SpiceConsoleModel) model).invokeClient(null); } } - } + }; - String cipherSuite = null; - String spiceSecureChannels = null; + AsyncDataProvider.getInstance().getIsoDomainByDataCenterId(isoDomainQuery, vm.getStoragePoolId()); + } - boolean isSSLEnabled = (Boolean) returnValues.get(0).getReturnValue(); - if (isSSLEnabled) { - cipherSuite = (String) returnValues.get(1).getReturnValue(); - spiceSecureChannels = (String) returnValues.get(2).getReturnValue(); - } - - String certificateSubject = ""; //$NON-NLS-1$ - String caCertificate = ""; //$NON-NLS-1$ - - if ((Boolean) returnValues.get(3).getReturnValue()) { - certificateSubject = (String) returnValues.get(4).getReturnValue(); - caCertificate = (String) returnValues.get(5).getReturnValue(); - } - - GraphicsInfo spiceInfo = getEntity().getGraphicsInfos().get(GraphicsType.SPICE); + public void invokeClient(final List<RepoImage> repoImages) { + final GraphicsInfo spiceInfo = getEntity().getGraphicsInfos().get(GraphicsType.SPICE); if (spiceInfo == null) { throw new IllegalStateException("Trying to invoke SPICE console but VM GraphicsInfo is null.");//$NON-NLS-1$ } - ConsoleOptions options = getspice().getOptions(); - options.setSmartcardEnabled(getEntity().isSmartcardEnabled()); - Integer port = spiceInfo.getPort(); - options.setPort(port == null ? 0 : port); - options.setTicket(ticket); - options.setNumberOfMonitors(getEntity().getNumOfMonitors()); - options.setGuestHostName(getEntity().getVmHost().split("[ ]", -1)[0]); //$NON-NLS-1$ - if (spiceInfo.getTlsPort() != null) { - options.setSecurePort(spiceInfo.getTlsPort()); - } - if (!StringHelper.isNullOrEmpty(spiceSecureChannels)) { - options.setSslChanels(spiceSecureChannels); - } - if (!StringHelper.isNullOrEmpty(cipherSuite)) { - options.setCipherSuite(cipherSuite); - } - options.setHostSubject(certificateSubject); - options.setTrustStore(caCertificate); + final ConsoleOptions options = getspice().getOptions(); + options.setVmId(getEntity().getId()); + // configure options + Frontend.getInstance().runQuery( + VdcQueryType.ConfigureConsoleOptions, + new ConfigureConsoleOptionsParams(options, true), + new AsyncQuery(new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object returnValue) { + final ConsoleOptions options = ((VdcQueryReturnValue) returnValue).getReturnValue(); - options.setTitle(getClientTitle()); + options.setTitle(getClientTitle()); + options.setAdminConsole(getConfigurator().getSpiceAdminConsole() ? true : !getEntity().getHasSpiceDriver()); + if (!options.isSpiceProxyEnabled()) { + options.setSpiceProxy(null); // override spice proxy from backend + } + createAndSetMenu(options, repoImages); - options.setSpiceProxy(determineSpiceProxy()); + // Subscribe to events. + getspice().getDisconnectedEvent().addListener(SpiceConsoleModel.this); + getspice().getMenuItemSelectedEvent().addListener(SpiceConsoleModel.this); - // If 'AdminConsole' is true, send true; otherwise, false should be sent only for VMs with SPICE driver - // installed. - options.setAdminConsole(getConfigurator().getSpiceAdminConsole() ? true : !getEntity().getHasSpiceDriver()); + try { + getspice().setOptions(options); + getspice().invokeClient(); + } catch (RuntimeException ex) { + getLogger().error("Exception on Spice connect", ex); //$NON-NLS-1$ + } + } + })); + } - // Update 'UsbListenPort' value - options.setUsbListenPort(getConfigurator().getIsUsbEnabled() - && getEntity().getUsbPolicy() == UsbPolicy.ENABLED_LEGACY ? getConfigurator().getSpiceDefaultUsbPort() - : getConfigurator().getSpiceDisableUsbListenPort()); - - options.setToggleFullscreenHotKey(getToggleFullScreenKeys()); - options.setReleaseCursorHotKey(getReleaseCursorKeys()); - - // Create menu. + // todo move to spicepluginimpl + private void createAndSetMenu(ConsoleOptions options, List<RepoImage> repoImages) { int id = 1; menu = new SpiceMenu(); @@ -408,30 +338,24 @@ new SpiceMenuContainerItem(id, ConstantsManager.getInstance().getConstants().changeCd()); id++; - ArrayList<String> isos = new ArrayList<String>(); + ArrayList<String> isos = new ArrayList<>(); - if (returnValues.size() > 6) { - ArrayList<RepoImage> repoList = returnValues.get(6).getReturnValue(); - for (RepoImage repoImage : repoList) { + if (repoImages != null) { + for (RepoImage repoImage : repoImages) { isos.add(repoImage.getRepoImageId()); } } - isos = - isos.size() > 0 ? isos - : new ArrayList<String>(Arrays.asList(new String[] { ConstantsManager.getInstance() - .getConstants() - .noCds() })); - + isos = isos.size() > 0 + ? isos + : new ArrayList<>(Arrays.asList(new String[]{ConstantsManager.getInstance().getConstants().noCds()})); Collections.sort(isos); - for (String fileName : isos) { changeCDItem.getItems().add(new SpiceMenuCommandItem(id, fileName, CommandChangeCD)); id++; } changeCDItem.getItems().add(new SpiceMenuCommandItem(id, getEjectLabel(), CommandChangeCD)); id++; - menu.getItems().add(changeCDItem); menu.getItems().add(new SpiceMenuSeparatorItem(id)); id++; @@ -448,87 +372,9 @@ .stopSpiceConsole(), CommandStop)); options.setMenu(menu.toString()); - - // Subscribe to events. - getspice().getDisconnectedEvent().addListener(this); - getspice().getMenuItemSelectedEvent().addListener(this); - - String displayIp = spiceInfo.getIp(); - if (StringHelper.isNullOrEmpty(displayIp) || "0".equals(displayIp)) { //$NON-NLS-1$ - determineIpAndConnect(getEntity().getId()); - } - else { - // Try to connect. - options.setHost(displayIp); - spiceConnect(); - } } - private String determineSpiceProxy() { - if (!getspice().getOptions().isSpiceProxyEnabled()) { - return null; - } - - if (!StringHelper.isNullOrEmpty(getEntity().getVmPoolSpiceProxy())) { - return getEntity().getVmPoolSpiceProxy(); - } - - if (!StringHelper.isNullOrEmpty(getEntity().getVdsGroupSpiceProxy())) { - return getEntity().getVdsGroupSpiceProxy(); - } - - String globalSpiceProxy = (String) AsyncDataProvider.getInstance().getConfigValuePreConverted(ConfigurationValues.SpiceProxyDefault); - if (!StringHelper.isNullOrEmpty(globalSpiceProxy)) { - return globalSpiceProxy; - } - - return null; - } - - private void determineIpAndConnect(Guid vmId) { - if (vmId == null) { - return; - } - - AsyncQuery _asyncQuery = new AsyncQuery(); - _asyncQuery.setModel(this); - _asyncQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void onSuccess(Object model, Object ReturnValue) { - SpiceConsoleModel spiceConsoleModel = (SpiceConsoleModel) model; - String address = - (String) ((VdcQueryReturnValue) ReturnValue).getReturnValue(); - spiceConsoleModel.getspice().getOptions().setHost(address); - spiceConsoleModel.spiceConnect(); - } - }; - - Frontend.getInstance().runQuery(VdcQueryType.GetManagementInterfaceAddressByVmId, - new IdQueryParameters(vmId), - _asyncQuery); - } - - private void setVmTicket() { - // Create ticket for single sign on. - Frontend.getInstance().runAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), null, ConsoleOptions.TICKET_VALIDITY_SECONDS, GraphicsType.SPICE), - new IFrontendActionAsyncCallback() { - @Override - public void executed(FrontendActionAsyncResult result) { - - SpiceConsoleModel spiceConsoleModel = (SpiceConsoleModel) result.getState(); - spiceConsoleModel.postSendVmTicket(result.getReturnValue()); - - } - }, this); - } - - public void postSendVmTicket(VdcReturnValueBase returnValue) { - if (returnValue == null || !returnValue.getSucceeded()) { - return; - } - - ticket = (String) returnValue.getActionReturnValue(); - + public void invokeConsole() { // todo refactor this later // Only if the VM has agent and we connect through user-portal // we attempt to perform SSO (otherwise an error will be thrown) if (!getConfigurator().getIsAdmin() && getEntity().getStatus() == VMStatus.Up @@ -616,15 +462,6 @@ private void logSsoOnDesktopFailed(ILogger logger, String vmName) { logger.info("SpiceConsoleManager::Connect: Failed to perform SSO on Destkop " //$NON-NLS-1$ + vmName + ", cancel open spice console request."); //$NON-NLS-1$ - } - - public void spiceConnect() - { - try { - getspice().invokeClient(); - } catch (RuntimeException ex) { - getLogger().error("Exception on Spice connect", ex); //$NON-NLS-1$ - } } private static final String CommandStop = "Stop"; //$NON-NLS-1$ diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java index 0707ed5..8c5e1f7 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java @@ -1,17 +1,13 @@ package org.ovirt.engine.ui.uicommonweb.models.vms; -import org.ovirt.engine.core.common.action.SetVmTicketParameters; -import org.ovirt.engine.core.common.action.VdcActionType; -import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.businessentities.GraphicsInfo; import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.console.ConsoleOptions; import org.ovirt.engine.core.common.queries.ConfigurationValues; -import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; -import org.ovirt.engine.core.compat.StringHelper; import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.frontend.INewAsyncCallback; @@ -22,28 +18,13 @@ import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider; import org.ovirt.engine.ui.uicommonweb.models.Model; import org.ovirt.engine.ui.uicompat.ConstantsManager; -import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; -import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback; public class VncConsoleModel extends ConsoleModel { - private ClientConsoleMode consoleMode; - public enum ClientConsoleMode { Native, NoVnc } - private String host; - - private String otp64 = null; - + private ClientConsoleMode consoleMode; private IVnc vncImpl; - - private String getHost() { - return host; - } - - private String getOtp64() { - return otp64; - } public VncConsoleModel(VM myVm, Model parentModel) { super(myVm, parentModel); @@ -92,14 +73,14 @@ } getLogger().debug("VNC console info..."); //$NON-NLS-1$ - UICommand setVmTicketCommand = new UICommand("setVmCommand", new BaseCommandTarget() { //$NON-NLS-1$ + UICommand invokeConsoleCommand = new UICommand("invokeConsoleCommand", new BaseCommandTarget() { //$NON-NLS-1$ @Override public void executeCommand(UICommand uiCommand) { - setVmTicket(); + invokeConsole(); } }); - executeCommandWithConsoleSafenessWarning(setVmTicketCommand); + executeCommandWithConsoleSafenessWarning(invokeConsoleCommand); } @Override @@ -107,61 +88,26 @@ return getEntity().getGraphicsInfos().containsKey(GraphicsType.VNC); } - private void setVmTicket() { + private void invokeConsole() { final GraphicsInfo vncInfo = getEntity().getGraphicsInfos().get(GraphicsType.VNC); if (vncInfo == null) { throw new IllegalStateException("Trying to invoke VNC console but VM GraphicsInfo is null."); //$NON-NLS-1$ } - Frontend.getInstance().runAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), - null, - ConsoleOptions.TICKET_VALIDITY_SECONDS, GraphicsType.VNC), new IFrontendActionAsyncCallback() { + final AsyncQuery configureCallback = new AsyncQuery(new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object returnValue) { + vncImpl.setOptions((ConsoleOptions) ((VdcQueryReturnValue) returnValue).getReturnValue()); + vncImpl.getOptions().setTitle(getClientTitle()); + vncImpl.invokeClient(); + } + }); - @Override - public void executed(FrontendActionAsyncResult result) { - - VdcReturnValueBase ticketReturnValue = result.getReturnValue(); - if (ticketReturnValue != null && ticketReturnValue.getActionReturnValue() != null) - { - otp64 = (String) ticketReturnValue.getActionReturnValue(); - // Determine the display IP. - String displayIp = vncInfo.getIp(); - if (StringHelper.isNullOrEmpty(displayIp) - || "0".equals(displayIp)) //$NON-NLS-1$ - { - AsyncQuery _asyncQuery = new AsyncQuery(); - _asyncQuery.setModel(this); - _asyncQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void onSuccess(Object model, Object ReturnValue) - { - VncConsoleModel.this.host = ((VdcQueryReturnValue) ReturnValue).getReturnValue(); - VncConsoleModel.this.setAndInvokeClient(); - } - }; - - Frontend.getInstance().runQuery(VdcQueryType.GetManagementInterfaceAddressByVmId, - new IdQueryParameters(getEntity().getId()), _asyncQuery); - } - else { - VncConsoleModel.this.host = displayIp; - setAndInvokeClient(); - } - } - } - }); - } - - private void setAndInvokeClient() { - vncImpl.getOptions().setHost(getHost()); - GraphicsInfo vncInfo = getEntity().getGraphicsInfos().get(GraphicsType.VNC); - vncImpl.getOptions().setPort(vncInfo.getPort()); - vncImpl.getOptions().setTicket(getOtp64()); - vncImpl.getOptions().setTitle(getClientTitle()); - vncImpl.getOptions().setToggleFullscreenHotKey(getToggleFullScreenKeys()); - vncImpl.getOptions().setReleaseCursorHotKey(getReleaseCursorKeys()); - - vncImpl.invokeClient(); + vncImpl.getOptions().setVmId(getEntity().getId()); + Frontend.getInstance().runQuery( + VdcQueryType.ConfigureConsoleOptions, + new ConfigureConsoleOptionsParams(vncImpl.getOptions(), true), + configureCallback); } } -- To view, visit http://gerrit.ovirt.org/37974 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ida16e4de2701d6f6b3f6b3ed52eddca805fa43a7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Frank Kobzik <fkob...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches