Search in sources :

Example 6 with HostResponse

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());
}
Also used : Hashtable(java.util.Hashtable) HostResponse(org.apache.cloudstack.api.response.HostResponse) ArrayList(java.util.ArrayList) HostJoinVO(com.cloud.api.query.vo.HostJoinVO)

Example 7 with HostResponse

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());
}
Also used : HostResponse(org.apache.cloudstack.api.response.HostResponse) Host(com.cloud.host.Host) Test(org.junit.Test)

Example 8 with HostResponse

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");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) HostResponse(org.apache.cloudstack.api.response.HostResponse) Host(com.cloud.host.Host)

Example 9 with HostResponse

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");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) HostResponse(org.apache.cloudstack.api.response.HostResponse) Host(com.cloud.host.Host)

Example 10 with HostResponse

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());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) HostResponse(org.apache.cloudstack.api.response.HostResponse) Host(com.cloud.host.Host) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

HostResponse (org.apache.cloudstack.api.response.HostResponse)10 Host (com.cloud.host.Host)8 ServerApiException (org.apache.cloudstack.api.ServerApiException)6 ArrayList (java.util.ArrayList)5 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 HostJoinVO (com.cloud.api.query.vo.HostJoinVO)1 DiscoveryException (com.cloud.exception.DiscoveryException)1 HostGpuGroupsVO (com.cloud.gpu.HostGpuGroupsVO)1 VGPUTypesVO (com.cloud.gpu.VGPUTypesVO)1 HostStats (com.cloud.host.HostStats)1 StorageStats (com.cloud.storage.StorageStats)1 Pair (com.cloud.utils.Pair)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1 GpuResponse (org.apache.cloudstack.api.response.GpuResponse)1