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");
}
}
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");
}
}
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);
}
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());
}
}
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);
}
Aggregations