private VDS getHost() { VDS host = new VDS(); host.setId(HOST_ID); host.setOpenstackNetworkProviderId(PROVIDER_ID); return host; }
public Response remove() { // First we need to check if the label contains the host: Label label = BackendAffinityLabelHelper.getLabel(this, labelId); if (!label.getHosts().contains(guid)) { throw new WebApplicationException(Response.Status.NOT_FOUND); } // Remove the host from the label: VDS entity = new VDS(); entity.setId(guid); Label updatedLabel = new LabelBuilder(label) .removeEntity(entity) .build(); return performAction(ActionType.UpdateLabel, new LabelActionParameters(updatedLabel)); } }
@Override public Response add(Host model) { validateParameters(model, "id"); Label label = BackendAffinityLabelHelper.getLabel(this, labelId); VDS entity = new VDS(); entity.setId(GuidUtils.asGuid(model.getId())); Label updatedLabel = new LabelBuilder(label) .entity(entity) .build(); // The command used to add the host to the label returns the label, but we need to return the virtual machine, // so we ignore the result and return a link to the added host: LabelActionParameters updateParams = new LabelActionParameters(updatedLabel); try { doAction(ActionType.UpdateLabel, updateParams); } catch (BackendFailureException exception) { handleError(exception, false); } Host result = BackendAffinityLabelHelper.makeHostLink(entity.getId()); return Response.ok(Response.Status.CREATED).entity(result).build(); }
@Test public void testLibvirtVersion() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setLibvirtVersion(new RpmVersion("libvirt-0.9.10-21.el6_3.4", "libvirt-", true)); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host.getLibvirtVersion()); assertEquals(Long.valueOf(0), Long.valueOf(host.getLibvirtVersion().getMajor())); assertEquals(Long.valueOf(9), Long.valueOf(host.getLibvirtVersion().getMinor())); assertEquals(Long.valueOf(0), Long.valueOf(host.getLibvirtVersion().getRevision())); assertEquals(Long.valueOf(10), Long.valueOf(host.getLibvirtVersion().getBuild())); assertEquals("libvirt-0.9.10-21.el6_3.4", host.getLibvirtVersion().getFullVersion()); }
@Test public void testMemoryMapping() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setPhysicalMemMb(4000); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host.getMemory()); assertEquals(Long.valueOf(4194304000L), host.getMemory()); }
@Test public void testVersion() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setVersion(new RpmVersion("vdsm-4.10.0-10.fc17", "vdsm-", true)); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host.getVersion()); assertEquals(Long.valueOf(4), Long.valueOf(host.getVersion().getMajor())); assertEquals(Long.valueOf(10), Long.valueOf(host.getVersion().getMinor())); assertEquals(Long.valueOf(0), Long.valueOf(host.getVersion().getRevision())); assertEquals(Long.valueOf(0), Long.valueOf(host.getVersion().getBuild())); assertEquals("vdsm-4.10.0-10.fc17", host.getVersion().getFullVersion()); }
static VDS setUpEntityExpectations(VDS entity, VdsStatistics statistics, int index) { entity.setId(GUIDS[index]); entity.getStaticData().setName(NAMES[index]); entity.setHostName(ADDRESSES[index]); entity.setStatus(VDS_STATUS[index]); entity.setStoragePoolId(GUIDS[1]); if (statistics != null) { setUpStatisticalEntityExpectations(entity, statistics); } return entity; }
@Test public void vdsIdRefVds() { b.setVdsIdRef(null); final VDS v = new VDS(); v.setId(GUID); b.setVds(v); final Guid g = b.getVdsIdRef(); assertEquals(GUID, g); }
when(model.getIsRunAndPause().getEntity()).thenReturn(true); VDS defaultHost = new VDS(); defaultHost.setId(HOST_ID); when(model.getDefaultHost().getSelectedItem()).thenReturn(defaultHost); when(model.getDefaultHost().getSelectedItems()).thenReturn(Collections.singletonList(defaultHost));
@Test public void testVmSummaryMapping() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setVmCount(2); vds.setVmActive(1); vds.setVmMigrating(1); Host host = HostMapper.map(vds, (Host) null); assertEquals(Integer.valueOf(2), host.getSummary().getTotal()); assertEquals(Integer.valueOf(1), host.getSummary().getActive()); assertEquals(Integer.valueOf(1), host.getSummary().getMigrating()); }
@Test public void testPmProxyPreferences() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setFenceProxySources(Arrays.asList(FenceProxySourceType.CLUSTER, FenceProxySourceType.DC)); Host host = HostMapper.map(vds, (Host) null); assertEquals(2, host.getPowerManagement().getPmProxies().getPmProxies().size()); assertEquals(PmProxyType.CLUSTER, host.getPowerManagement().getPmProxies().getPmProxies().get(0).getType()); assertEquals(PmProxyType.DC, host.getPowerManagement().getPmProxies().getPmProxies().get(1).getType()); }
@Test public void testHostOs() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setHostOs("Fedora - 17 - 1"); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host.getOs()); assertTrue(host.getOs().isSetVersion()); assertEquals("Fedora", host.getOs().getType()); assertEquals("17 - 1", host.getOs().getVersion().getFullVersion()); assertEquals(Long.valueOf(17), Long.valueOf(host.getOs().getVersion().getMajor())); assertEquals(Long.valueOf(1), Long.valueOf(host.getOs().getVersion().getMinor())); }
@Test public void testDevicePassthroughMapping() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setHostDevicePassthroughEnabled(true); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host); assertNotNull(host.getDevicePassthrough()); assertTrue(host.getDevicePassthrough().isEnabled()); } }
@Test public void testMaxSchedulingMemory() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setPhysicalMemMb(4000); vds.setMemCommited(1000); vds.setMaxVdsMemoryOverCommit(150); vds.setReservedMem(65); Host host = HostMapper.map(vds, (Host) null); long vdsValue = (long) vds.getMaxSchedulingMemory(); Long hostValue = host.getMaxSchedulingMemory() / HostMapper.BYTES_IN_MEGABYTE; assertTrue(vdsValue > 0 && hostValue > 0 && vdsValue == hostValue); }
@Test public void testCpuMapping() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setCpuCores(6); vds.setCpuSockets(3); vds.setCpuThreads(12); vds.setCpuModel("some cpu model"); vds.setCpuSpeedMh(5.5); Host host = HostMapper.map(vds, (Host) null); assertNotNull(host.getCpu()); assertEquals(Integer.valueOf(2), host.getCpu().getTopology().getCores()); assertEquals(Integer.valueOf(3), host.getCpu().getTopology().getSockets()); assertEquals(Integer.valueOf(2), host.getCpu().getTopology().getThreads()); assertEquals("some cpu model", host.getCpu().getName()); assertEquals(new BigDecimal(5.5), host.getCpu().getSpeed()); }
@Test public void testHostedEngineMapping() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setHighlyAvailableIsConfigured(true); vds.setHighlyAvailableIsActive(false); vds.setHighlyAvailableScore(123); vds.setHighlyAvailableGlobalMaintenance(true); vds.setHighlyAvailableLocalMaintenance(false); HostedEngine hostedEngine = HostMapper.map(vds, (HostedEngine) null); assertNotNull(hostedEngine); assertEquals(Boolean.TRUE, hostedEngine.isConfigured()); assertEquals(Boolean.FALSE, hostedEngine.isActive()); assertEquals(Integer.valueOf(123), hostedEngine.getScore()); assertEquals(Boolean.TRUE, hostedEngine.isGlobalMaintenance()); assertEquals(Boolean.FALSE, hostedEngine.isLocalMaintenance()); }
@Override protected VDS getInverse(VdsStatic to) { VDS inverse = new VDS(); inverse.setId(to.getId()); inverse.setVdsName(to.getName()); inverse.setHostName(to.getHostName()); inverse.setClusterId(to.getClusterId()); inverse.setPort(to.getPort()); inverse.setSshKeyFingerprint(to.getSshKeyFingerprint()); inverse.setHostProviderId(to.getHostProviderId()); inverse.setSshPort(to.getSshPort()); inverse.setSshUsername(to.getSshUsername()); inverse.setVdsSpmPriority(to.getVdsSpmPriority()); inverse.setConsoleAddress(to.getConsoleAddress()); inverse.setComment(to.getComment()); return inverse; }
private static Object cloneVDS(VDS instance) { VDS obj = new VDS(); obj.setHostName(instance.getHostName()); obj.setSshKeyFingerprint(instance.getSshKeyFingerprint()); obj.setSshPort(instance.getSshPort()); obj.setSshUsername(instance.getSshUsername()); obj.setFenceAgents(cloneAgents(instance.getFenceAgents())); obj.setDisablePowerManagementPolicy(instance.isDisablePowerManagementPolicy()); obj.setPmKdumpDetection(instance.isPmKdumpDetection()); obj.setPort(instance.getPort()); obj.setServerSslEnabled(instance.isServerSslEnabled()); obj.setClusterId(instance.getClusterId()); obj.setId(instance.getId()); obj.setVdsName(instance.getName()); obj.setVdsStrength(instance.getVdsStrength()); obj.setVdsType(instance.getVdsType()); obj.setUniqueId(instance.getUniqueId()); obj.setVdsSpmPriority(instance.getVdsSpmPriority()); obj.setCurrentKernelCmdline(instance.getCurrentKernelCmdline()); obj.setKernelCmdlineParsable(instance.isKernelCmdlineParsable()); obj.setLastStoredKernelCmdline(instance.getLastStoredKernelCmdline()); obj.setKernelCmdlineBlacklistNouveau(instance.isKernelCmdlineBlacklistNouveau()); obj.setKernelCmdlineIommu(instance.isKernelCmdlineIommu()); obj.setKernelCmdlineKvmNested(instance.isKernelCmdlineKvmNested()); obj.setKernelCmdlinePciRealloc(instance.isKernelCmdlinePciRealloc()); obj.setKernelCmdlineFips(instance.isKernelCmdlineFips()); obj.setKernelCmdlineUnsafeInterrupts(instance.isKernelCmdlineUnsafeInterrupts()); return obj; }