@Test public void testSetDetailsNull() { final HostResponse hostResponse = new HostResponse(); hostResponse.setDetails(null); assertEquals(null, hostResponse.getDetails()); }
@Override public String getObjectId() { return this.getId(); }
@Override public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) { HostResponse hostResponse = new HostResponse(); hostResponse.setId(host.getUuid()); hostResponse.setCapabilities(host.getCapabilities()); hostResponse.setClusterId(host.getClusterUuid()); hostResponse.setCpuSockets(host.getCpuSockets()); hostResponse.setCpuNumber(host.getCpus()); hostResponse.setZoneId(host.getZoneUuid()); hostResponse.setDisconnectedOn(host.getDisconnectedOn()); hostResponse.setHypervisor(host.getHypervisorType()); hostResponse.setHostType(host.getType()); hostResponse.setLastPinged(new Date(host.getLastPinged())); hostResponse.setManagementServerId(host.getManagementServerId()); hostResponse.setName(host.getName()); hostResponse.setPodId(host.getPodUuid()); hostResponse.setRemoved(host.getRemoved()); hostResponse.setCpuSpeed(host.getSpeed()); hostResponse.setState(host.getStatus()); hostResponse.setIpAddress(host.getPrivateIpAddress()); hostResponse.setVersion(host.getVersion()); hostResponse.setCreated(host.getCreated()); hostResponse.setGpuGroups(gpus); hostResponse.setOsCategoryId(host.getOsCategoryUuid()); hostResponse.setOsCategoryName(host.getOsCategoryName()); hostResponse.setZoneName(host.getZoneName()); hostResponse.setPodName(host.getPodName()); if (host.getClusterId() > 0) {
final Host host = hostDao.findByUuid(hostResponse.getId()); if (host == null) { continue; metricsResponse.setPowerState(hostResponse.getOutOfBandManagementResponse().getPowerState()); metricsResponse.setInstances(upInstances, totalInstances); metricsResponse.setCpuTotal(hostResponse.getCpuNumber(), hostResponse.getCpuSpeed(), cpuOvercommitRatio); metricsResponse.setCpuUsed(hostResponse.getCpuUsed(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed()); metricsResponse.setCpuAllocated(hostResponse.getCpuAllocated(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed()); metricsResponse.setMemTotal(hostResponse.getMemoryTotal(), memoryOvercommitRatio); metricsResponse.setMemAllocated(hostResponse.getMemoryAllocated()); metricsResponse.setMemUsed(hostResponse.getMemoryUsed()); metricsResponse.setNetworkRead(hostResponse.getNetworkKbsRead()); metricsResponse.setNetworkWrite(hostResponse.getNetworkKbsWrite()); metricsResponse.setCpuUsageThreshold(hostResponse.getCpuUsed(), cpuThreshold); metricsResponse.setCpuUsageDisableThreshold(hostResponse.getCpuUsed(), cpuDisableThreshold); metricsResponse.setCpuAllocatedThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuThreshold); metricsResponse.setCpuAllocatedDisableThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuDisableThreshold); metricsResponse.setMemoryUsageThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryThreshold); metricsResponse.setMemoryUsageDisableThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryDisableThreshold); metricsResponse.setMemoryAllocatedThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryThreshold); metricsResponse.setMemoryAllocatedDisableThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryDisableThreshold); metricsResponses.add(metricsResponse);
@Test public void testExecuteForResult() throws Exception { addHostCmd._resourceService = resourceService; addHostCmd._responseGenerator = responseGenerator; Host host = Mockito.mock(Host.class); Host[] mockArray = new Host[] {host}; HostResponse responseHost = new HostResponse(); responseHost.setName("Test"); Mockito.doReturn(Arrays.asList(mockArray)).when(resourceService).discoverHosts(addHostCmd); Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(responseHost); addHostCmd.execute(); Mockito.verify(responseGenerator).createHostResponse(host); @SuppressWarnings("unchecked") ListResponse<HostResponse> actualResponse = ((ListResponse<HostResponse>)addHostCmd.getResponseObject()); Assert.assertEquals(responseHost, actualResponse.getResponses().get(0)); Assert.assertEquals("addhostresponse", actualResponse.getResponseName()); }
protected ListResponse<HostResponse> getHostResponses() { ListResponse<HostResponse> response = new ListResponse<>(); if (getVirtualMachineId() == null) { response = _queryService.searchForServers(this); } else { Pair<List<? extends Host>, Integer> result; Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal(), null); result = hostsForMigration.first(); List<? extends Host> hostsWithCapacity = hostsForMigration.second(); List<HostResponse> hostResponses = new ArrayList<HostResponse>(); for (Host host : result.first()) { HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails()); Boolean suitableForMigration = false; if (hostsWithCapacity.contains(host)) { suitableForMigration = true; } hostResponse.setSuitableForMigration(suitableForMigration); hostResponse.setObjectName("host"); hostResponses.add(hostResponse); } response.setResponses(hostResponses, result.second()); } return response; }
@Test public void testSetDetailsWithoutRootCredentials() { final HostResponse hostResponse = new HostResponse(); final Map details = new HashMap<>(); details.put(VALID_KEY, VALID_VALUE); final Map expectedDetails = new HashedMap(); expectedDetails.put(VALID_KEY, VALID_VALUE); hostResponse.setDetails(details); final Map actualDetails = hostResponse.getDetails(); assertTrue(details != actualDetails); assertEquals(expectedDetails, actualDetails); } }
@Test public void testSetDetailsWithRootCredentials() { final HostResponse hostResponse = new HostResponse(); final Map details = new HashMap<>(); details.put(VALID_KEY, VALID_VALUE); details.put("username", "test"); details.put("password", "password"); final Map expectedDetails = new HashedMap(); expectedDetails.put(VALID_KEY, VALID_VALUE); hostResponse.setDetails(details); final Map actualDetails = hostResponse.getDetails(); assertTrue(details != actualDetails); assertEquals(expectedDetails, actualDetails); }