Search in sources :

Example 31 with ServerApiException

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

the class DedicateZoneCmd method execute.

@Override
public void execute() {
    List<? extends DedicatedResources> result = dedicatedService.dedicateZone(getZoneId(), getDomainId(), getAccountName());
    ListResponse<DedicateZoneResponse> response = new ListResponse<DedicateZoneResponse>();
    List<DedicateZoneResponse> zoneResponseList = new ArrayList<DedicateZoneResponse>();
    if (result != null) {
        for (DedicatedResources resource : result) {
            DedicateZoneResponse zoneresponse = dedicatedService.createDedicateZoneResponse(resource);
            zoneResponseList.add(zoneresponse);
        }
        response.setResponses(zoneResponseList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate zone");
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) DedicateZoneResponse(org.apache.cloudstack.api.response.DedicateZoneResponse)

Example 32 with ServerApiException

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

the class ReleaseDedicatedZoneCmd method execute.

@Override
public void execute() {
    boolean result = dedicatedService.releaseDedicatedResource(getZoneId(), null, null, null);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to release dedicated zone");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 33 with ServerApiException

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

the class UpdateVmwareDcCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final VmwareDatacenter vmwareDatacenter = vmwareDatacenterService.updateVmwareDatacenter(this);
    if (vmwareDatacenter == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VMware datacenter");
    }
    final VmwareDatacenterResponse response = new VmwareDatacenterResponse();
    response.setId(vmwareDatacenter.getUuid());
    response.setName(vmwareDatacenter.getVmwareDatacenterName());
    response.setResponseName(getCommandName());
    response.setObjectName("vmwaredc");
    setResponseObject(response);
}
Also used : VmwareDatacenterResponse(org.apache.cloudstack.api.response.VmwareDatacenterResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) VmwareDatacenter(com.cloud.hypervisor.vmware.VmwareDatacenter)

Example 34 with ServerApiException

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

the class RemoveVmwareDcCmd method execute.

@Override
public void execute() {
    SuccessResponse response = new SuccessResponse();
    try {
        boolean result = _vmwareDatacenterService.removeVmwareDatacenter(this);
        if (result) {
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove VMware datacenter from zone");
        }
    } catch (ResourceInUseException ex) {
        s_logger.warn("The zone has one or more resources (like cluster), hence not able to remove VMware datacenter from zone." + " Please remove all resource from zone, and retry. Exception: ", ex);
        ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
        for (String proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj);
        }
        throw e;
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    } catch (CloudRuntimeException runtimeEx) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeEx.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException)

Example 35 with ServerApiException

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

the class ImportVsphereStoragePoliciesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final DataCenter dataCenter = _resourceService.getZone(getZoneId());
    if (dataCenter == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId());
    }
    List<? extends VsphereStoragePolicy> storagePolicies = _vmwareDatacenterService.importVsphereStoragePolicies(this);
    final ListResponse<VsphereStoragePoliciesResponse> responseList = new ListResponse<>();
    final List<VsphereStoragePoliciesResponse> storagePoliciesResponseList = new ArrayList<>();
    for (VsphereStoragePolicy storagePolicy : storagePolicies) {
        final VsphereStoragePoliciesResponse storagePoliciesResponse = new VsphereStoragePoliciesResponse();
        storagePoliciesResponse.setZoneId(dataCenter.getUuid());
        storagePoliciesResponse.setId(storagePolicy.getUuid());
        storagePoliciesResponse.setName(storagePolicy.getName());
        storagePoliciesResponse.setPolicyId(storagePolicy.getPolicyId());
        storagePoliciesResponse.setDescription(storagePolicy.getDescription());
        storagePoliciesResponse.setObjectName("StoragePolicy");
        storagePoliciesResponseList.add(storagePoliciesResponse);
    }
    responseList.setResponses(storagePoliciesResponseList);
    responseList.setResponseName(getCommandName());
    setResponseObject(responseList);
}
Also used : VsphereStoragePoliciesResponse(org.apache.cloudstack.api.response.VsphereStoragePoliciesResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) VsphereStoragePolicy(com.cloud.dc.VsphereStoragePolicy)

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