Martin Betak has uploaded a new change for review. Change subject: restapi: Expose effective SPICE proxy in VM.display ......................................................................
restapi: Expose effective SPICE proxy in VM.display Change-Id: I0bc84f39c8b6a2da742baae9b0874c2f36c3738d Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1054948 Signed-off-by: Martin Betak <[email protected]> --- M backend/manager/modules/restapi/jaxrs/pom.xml M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendBaseTest.java M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java M backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java 4 files changed, 61 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/50/31350/1 diff --git a/backend/manager/modules/restapi/jaxrs/pom.xml b/backend/manager/modules/restapi/jaxrs/pom.xml index 968515d..3bbba6b 100644 --- a/backend/manager/modules/restapi/jaxrs/pom.xml +++ b/backend/manager/modules/restapi/jaxrs/pom.xml @@ -45,6 +45,14 @@ </dependency> <dependency> + <groupId>${engine.groupId}</groupId> + <artifactId>utils</artifactId> + <version>${engine.version}</version> + <type>test-jar</type> + <scope>provided</scope> + </dependency> + + <dependency> <groupId>org.ovirt.engine.core</groupId> <artifactId>branding</artifactId> <version>${engine.version}</version> diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendBaseTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendBaseTest.java index 3aad305..54e8af0 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendBaseTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendBaseTest.java @@ -26,6 +26,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.ovirt.engine.api.common.invocation.Current; import org.ovirt.engine.api.model.BaseResource; import org.ovirt.engine.api.model.Fault; @@ -54,6 +55,7 @@ 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.utils.MockConfigRule; public abstract class AbstractBackendBaseTest extends Assert { protected static final Guid[] GUIDS = { new Guid("00000000-0000-0000-0000-000000000000"), @@ -122,6 +124,9 @@ protected DbUser currentUser; + @Rule + public final MockConfigRule mcr = new MockConfigRule(); + @Before public void setUp() { control = EasyMock.createNiceControl(); diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java index 144ac45..97d0848 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java @@ -76,6 +76,8 @@ import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.osinfo.OsRepository; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.common.utils.VmDeviceType; @@ -518,6 +520,7 @@ model.getDisplay().setKeyboardLayout(entity.getDefaultVncKeyboardLayout()); model.getDisplay().setFileTransferEnabled(entity.isSpiceFileTransferEnabled()); model.getDisplay().setCopyPasteEnabled(entity.isSpiceCopyPasteEnabled()); + model.getDisplay().setProxy(getEffectiveSpiceProxy(entity)); } model.setType(map(entity.getVmType(), null)); model.setStateless(entity.isStateless()); @@ -584,6 +587,23 @@ return model; } + private static String getEffectiveSpiceProxy(org.ovirt.engine.core.common.businessentities.VM entity) { + if (StringUtils.isNotBlank(entity.getVmPoolSpiceProxy())) { + return entity.getVmPoolSpiceProxy(); + } + + if (StringUtils.isNotBlank(entity.getVdsGroupSpiceProxy())) { + return entity.getVdsGroupSpiceProxy(); + } + + String globalSpiceProxy = Config.getValue(ConfigValues.SpiceProxyDefault); + if (StringUtils.isNotBlank(globalSpiceProxy)) { + return globalSpiceProxy; + } + + return null; + } + @Mapping(from = VM.class, to = RunVmOnceParams.class) public static RunVmOnceParams map(VM vm, RunVmOnceParams template) { RunVmOnceParams params = template != null ? template : new RunVmOnceParams(); diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java index 60805f8..ac35da3 100644 --- a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java @@ -241,6 +241,34 @@ assertNull(model.getDisplay().getSecurePort()); } + private static final String GLOBAL_SPICE_PROXY = "http://host:12345"; + private static final String CLUSTER_SPICE_PROXY = "http://host2:54321"; + private static final String POOL_SPICE_PROXY = "http://host3:9999"; + + @Test + public void testGlobalSpiceProxy() { + org.ovirt.engine.core.common.businessentities.VM entity = new org.ovirt.engine.core.common.businessentities.VM(); + mcr.mockConfigValue(ConfigValues.SpiceProxyDefault, GLOBAL_SPICE_PROXY); + VM model = VmMapper.map(entity, (VM) null); + assertEquals(GLOBAL_SPICE_PROXY, model.getDisplay().getProxy()); + } + + @Test + public void testClusterSpiceProxy() { + org.ovirt.engine.core.common.businessentities.VM entity = new org.ovirt.engine.core.common.businessentities.VM(); + entity.setVdsGroupSpiceProxy(CLUSTER_SPICE_PROXY); + VM model = VmMapper.map(entity, (VM) null); + assertEquals(CLUSTER_SPICE_PROXY, model.getDisplay().getProxy()); + } + + @Test + public void testPoolSpiceProxy() { + org.ovirt.engine.core.common.businessentities.VM entity = new org.ovirt.engine.core.common.businessentities.VM(); + entity.setVmPoolSpiceProxy(POOL_SPICE_PROXY); + VM model = VmMapper.map(entity, (VM) null); + assertEquals(POOL_SPICE_PROXY, model.getDisplay().getProxy()); + } + @Test public void testMapOriginTypeRhev() { String s = VmMapper.map(OriginType.RHEV, null); -- To view, visit http://gerrit.ovirt.org/31350 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0bc84f39c8b6a2da742baae9b0874c2f36c3738d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Betak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
