Search in sources :

Example 66 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ApiDiscoveryTest method verifyListApis.

@Test
public void verifyListApis() throws Exception {
    ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) s_discoveryService.listApis(testUser, null);
    assertNotNull("Responses should not be null", responses);
    if (responses != null) {
        assertTrue("No. of response items > 2", responses.getCount().intValue() == 2);
        for (ApiDiscoveryResponse response : responses.getResponses()) {
            assertFalse("API name is empty", response.getName().isEmpty());
            assertFalse("API description is empty", response.getDescription().isEmpty());
        }
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse) Test(org.junit.Test)

Example 67 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ApiDiscoveryTest method verifyListSingleApi.

@Test
public void verifyListSingleApi() throws Exception {
    ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) s_discoveryService.listApis(testUser, testApiName);
    assertNotNull("Responses should not be null", responses);
    if (responses != null) {
        ApiDiscoveryResponse response = responses.getResponses().get(0);
        assertTrue("No. of response items should be one", responses.getCount() == 1);
        assertEquals("Error in api name", testApiName, response.getName());
        assertEquals("Error in api description", testApiDescription, response.getDescription());
        assertEquals("Error in api since", testApiSince, response.getSince());
        assertEquals("Error in api isAsync", testApiAsync, response.getAsync());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse) Test(org.junit.Test)

Example 68 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ListCiscoAsa1000vResourcesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<CiscoAsa1000vDeviceVO> ciscoAsa1000vDevices = _ciscoAsa1000vService.listCiscoAsa1000vResources(this);
        ListResponse<CiscoAsa1000vResourceResponse> response = new ListResponse<CiscoAsa1000vResourceResponse>();
        List<CiscoAsa1000vResourceResponse> ciscoAsa1000vResourcesResponse = new ArrayList<CiscoAsa1000vResourceResponse>();
        if (ciscoAsa1000vDevices != null && !ciscoAsa1000vDevices.isEmpty()) {
            for (CiscoAsa1000vDevice ciscoAsa1000vDeviceVO : ciscoAsa1000vDevices) {
                CiscoAsa1000vResourceResponse ciscoAsa1000vResourceResponse = _ciscoAsa1000vService.createCiscoAsa1000vResourceResponse(ciscoAsa1000vDeviceVO);
                ciscoAsa1000vResourceResponse.setObjectName("CiscoAsa1000vResource");
                ciscoAsa1000vResourcesResponse.add(ciscoAsa1000vResourceResponse);
            }
        }
        response.setResponses(ciscoAsa1000vResourcesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoAsa1000vResourceResponse(com.cloud.api.response.CiscoAsa1000vResourceResponse) ArrayList(java.util.ArrayList) CiscoAsa1000vDevice(com.cloud.network.cisco.CiscoAsa1000vDevice)

Example 69 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ListCiscoVnmcResourcesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<CiscoVnmcControllerVO> ciscoVnmcResources = _ciscoVnmcElementService.listCiscoVnmcResources(this);
        ListResponse<CiscoVnmcResourceResponse> response = new ListResponse<CiscoVnmcResourceResponse>();
        List<CiscoVnmcResourceResponse> ciscoVnmcResourcesResponse = new ArrayList<CiscoVnmcResourceResponse>();
        if (ciscoVnmcResources != null && !ciscoVnmcResources.isEmpty()) {
            for (CiscoVnmcController ciscoVnmcResourceVO : ciscoVnmcResources) {
                CiscoVnmcResourceResponse ciscoVnmcResourceResponse = _ciscoVnmcElementService.createCiscoVnmcResourceResponse(ciscoVnmcResourceVO);
                ciscoVnmcResourceResponse.setObjectName("CiscoVnmcResource");
                ciscoVnmcResourcesResponse.add(ciscoVnmcResourceResponse);
            }
        }
        response.setResponses(ciscoVnmcResourcesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : CiscoVnmcResourceResponse(com.cloud.api.response.CiscoVnmcResourceResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Example 70 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ApiServer method buildAsyncListResponse.

@SuppressWarnings("unchecked")
private void buildAsyncListResponse(final BaseListCmd command, final Account account) {
    final List<ResponseObject> responses = ((ListResponse) command.getResponseObject()).getResponses();
    if (responses != null && responses.size() > 0) {
        List<? extends AsyncJob> jobs = null;
        // list all jobs for ROOT admin
        if (accountMgr.isRootAdmin(account.getId())) {
            jobs = asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType().toString(), null);
        } else {
            jobs = asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType().toString(), account.getId());
        }
        if (jobs.size() == 0) {
            return;
        }
        final Map<String, AsyncJob> objectJobMap = new HashMap<String, AsyncJob>();
        for (final AsyncJob job : jobs) {
            if (job.getInstanceId() == null) {
                continue;
            }
            final String instanceUuid = ApiDBUtils.findJobInstanceUuid(job);
            objectJobMap.put(instanceUuid, job);
        }
        for (final ResponseObject response : responses) {
            if (response.getObjectId() != null && objectJobMap.containsKey(response.getObjectId())) {
                final AsyncJob job = objectJobMap.get(response.getObjectId());
                response.setJobId(job.getUuid());
                response.setJobStatus(job.getStatus().ordinal());
            }
        }
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) HashMap(java.util.HashMap) ResponseObject(org.apache.cloudstack.api.ResponseObject) AsyncJob(org.apache.cloudstack.framework.jobs.AsyncJob)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)177 ArrayList (java.util.ArrayList)160 List (java.util.List)70 ServerApiException (org.apache.cloudstack.api.ServerApiException)49 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 Account (com.cloud.user.Account)10 Network (com.cloud.network.Network)9 Host (com.cloud.host.Host)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 Test (org.junit.Test)8 DedicatedResources (com.cloud.dc.DedicatedResources)7 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Domain (com.cloud.domain.Domain)6 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 ApiDiscoveryResponse (org.apache.cloudstack.api.response.ApiDiscoveryResponse)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4