Search in sources :

Example 26 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class ListDedicatedZonesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends DedicatedResourceVO>, Integer> result = _dedicatedservice.listDedicatedZones(this);
    ListResponse<DedicateZoneResponse> response = new ListResponse<DedicateZoneResponse>();
    List<DedicateZoneResponse> Responses = new ArrayList<DedicateZoneResponse>();
    if (result != null) {
        for (DedicatedResources resource : result.first()) {
            DedicateZoneResponse zoneResponse = _dedicatedservice.createDedicateZoneResponse(resource);
            Responses.add(zoneResponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated zones");
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicateZoneResponse(org.apache.cloudstack.api.response.DedicateZoneResponse) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 27 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class QuotaEmailTemplateUpdateCmdTest method testQuotaEmailTemplateUpdateCmd.

@Test
public void testQuotaEmailTemplateUpdateCmd() throws NoSuchFieldException, IllegalAccessException {
    QuotaEmailTemplateUpdateCmd cmd = new QuotaEmailTemplateUpdateCmd();
    Field rbField = QuotaEmailTemplateUpdateCmd.class.getDeclaredField("_quotaResponseBuilder");
    rbField.setAccessible(true);
    rbField.set(cmd, responseBuilder);
    // templatename parameter check
    try {
        cmd.execute();
    } catch (ServerApiException e) {
        assertTrue(e.getErrorCode().equals(ApiErrorCode.PARAM_ERROR));
    }
    // invalid template name test
    cmd.setTemplateName("randomTemplate");
    cmd.setTemplateBody("some body");
    cmd.setTemplateSubject("some subject");
    try {
        cmd.execute();
    } catch (ServerApiException e) {
        assertTrue(e.getErrorCode().equals(ApiErrorCode.PARAM_ERROR));
    }
    // valid template test
    cmd.setTemplateName(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY.toString());
    Mockito.when(responseBuilder.updateQuotaEmailTemplate(Mockito.eq(cmd))).thenReturn(true);
    cmd.execute();
    Mockito.verify(responseBuilder, Mockito.times(1)).updateQuotaEmailTemplate(Mockito.eq(cmd));
}
Also used : Field(java.lang.reflect.Field) ServerApiException(org.apache.cloudstack.api.ServerApiException) Test(org.junit.Test)

Example 28 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class ListDedicatedClustersCmd method execute.

@Override
public void execute() {
    Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedClusters(this);
    ListResponse<DedicateClusterResponse> response = new ListResponse<DedicateClusterResponse>();
    List<DedicateClusterResponse> Responses = new ArrayList<DedicateClusterResponse>();
    if (result != null) {
        for (DedicatedResources resource : result.first()) {
            DedicateClusterResponse clusterResponse = dedicatedService.createDedicateClusterResponse(resource);
            Responses.add(clusterResponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated clusters");
    }
}
Also used : DedicateClusterResponse(org.apache.cloudstack.api.response.DedicateClusterResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 29 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class ListDedicatedPodsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedPods(this);
    ListResponse<DedicatePodResponse> response = new ListResponse<DedicatePodResponse>();
    List<DedicatePodResponse> Responses = new ArrayList<DedicatePodResponse>();
    if (result != null) {
        for (DedicatedResources resource : result.first()) {
            DedicatePodResponse podresponse = dedicatedService.createDedicatePodResponse(resource);
            Responses.add(podresponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated pods");
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatePodResponse(org.apache.cloudstack.api.response.DedicatePodResponse) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 30 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class DedicateClusterCmd method execute.

@Override
public void execute() {
    List<? extends DedicatedResources> result = dedicatedService.dedicateCluster(getClusterId(), getDomainId(), getAccountName());
    ListResponse<DedicateClusterResponse> response = new ListResponse<DedicateClusterResponse>();
    List<DedicateClusterResponse> clusterResponseList = new ArrayList<DedicateClusterResponse>();
    // List of result should always contain single element as only one cluster will be associated with each cluster ID.
    if (result != null && result.size() == 1) {
        DedicateClusterResponse clusterResponse = dedicatedService.createDedicateClusterResponse(result.get(0));
        clusterResponse.setResponseName(getCommandName());
        this.setResponseObject(clusterResponse);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate cluster");
    }
}
Also used : DedicateClusterResponse(org.apache.cloudstack.api.response.DedicateClusterResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList)

Aggregations

ServerApiException (org.apache.cloudstack.api.ServerApiException)628 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)154 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)143 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)104 ArrayList (java.util.ArrayList)74 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)55 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)51 ListResponse (org.apache.cloudstack.api.response.ListResponse)49 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)47 UserVm (com.cloud.uservm.UserVm)47 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)43 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)42 Account (com.cloud.user.Account)32 Host (com.cloud.host.Host)30 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)29 Volume (com.cloud.storage.Volume)25 Test (org.junit.Test)23 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)20 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)15 UserAccount (com.cloud.user.UserAccount)15