use of org.apache.cloudstack.api.response.HostResponse in project cloudstack by apache.
the class ViewResponseHelper method createHostResponse.
public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
Hashtable<Long, HostResponse> vrDataList = new Hashtable<Long, HostResponse>();
// Initialise the vrdatalist with the input data
for (HostJoinVO vr : hosts) {
HostResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this vm
vrData = ApiDBUtils.newHostResponse(vr, details);
} else {
// update tags
vrData = ApiDBUtils.fillHostDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<HostResponse>(vrDataList.values());
}
use of org.apache.cloudstack.api.response.HostResponse in project cloudstack by apache.
the class AddHostCmdTest method testExecuteForResult.
/*
* @Test public void testExecuteForResult() throws Exception {
*
* addHostCmd._resourceService = resourceService;
* addHostCmd._responseGenerator = responseGenerator; MockHost mockInstance
* = new MockHost(); MockHost[] mockArray = new MockHost[]{mockInstance};
* HostResponse responseHost = new HostResponse();
* responseHost.setName("Test");
* Mockito.when(resourceService.discoverHosts(addHostCmd
* )).thenReturn(Arrays.asList(mockArray));
* Mockito.when(responseGenerator.createHostResponse
* (mockInstance)).thenReturn(responseHost); addHostCmd.execute();
* Mockito.verify(responseGenerator).createHostResponse(mockInstance);
* ListResponse<HostResponse> actualResponse =
* ((ListResponse<HostResponse>)addHostCmd.getResponseObject());
* Assert.assertEquals(responseHost, actualResponse.getResponses().get(0));
* Assert.assertEquals("addhostresponse", actualResponse.getResponseName());
* }
*/
@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());
}
use of org.apache.cloudstack.api.response.HostResponse in project cloudstack by apache.
the class PrepareForMaintenanceCmd method execute.
@Override
public void execute() {
Host result = _resourceService.maintain(this);
if (result != null) {
HostResponse response = _responseGenerator.createHostResponse(result);
response.setResponseName("host");
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to prepare host for maintenance");
}
}
use of org.apache.cloudstack.api.response.HostResponse in project cloudstack by apache.
the class CancelMaintenanceCmd method execute.
@Override
public void execute() {
Host result = _resourceService.cancelMaintenance(this);
if (result != null) {
HostResponse response = _responseGenerator.createHostResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to cancel host maintenance");
}
}
use of org.apache.cloudstack.api.response.HostResponse in project cloudstack by apache.
the class UpdateHostCmd method execute.
@Override
public void execute() {
Host result;
try {
result = _resourceService.updateHost(this);
HostResponse hostResponse = _responseGenerator.createHostResponse(result);
hostResponse.setResponseName(getCommandName());
this.setResponseObject(hostResponse);
} catch (Exception e) {
s_logger.debug("Failed to update host:" + getId(), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage());
}
}
Aggregations