use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class UnmanageVMInstanceCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
UnmanageVMInstanceResponse response = new UnmanageVMInstanceResponse();
try {
CallContext.current().setEventDetails("VM ID = " + vmId);
boolean result = unmanagedVMsManager.unmanageVMInstance(vmId);
response.setSuccess(result);
if (result) {
response.setDetails("VM unmanaged successfully");
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
response.setResponseName(getCommandName());
response.setObjectName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class CreateBackupCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.createBackup(getVmId());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new CloudRuntimeException("Error while creating backup of VM");
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class RemoveVirtualMachineFromBackupOfferingCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.removeVMFromBackupOffering(getVmId(), getForced());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove VM from backup offering");
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class RestoreVolumeFromBackupAndAttachToVMCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.restoreBackupVolumeAndAttachToVM(volumeUuid, backupId, vmId);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new CloudRuntimeException("Error restoring volume and attaching to VM");
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class CreateLoadBalancerRuleCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
CallContext callerContext = CallContext.current();
boolean success = true;
LoadBalancer rule = null;
try {
CallContext.current().setEventDetails("Rule Id: " + getEntityId());
if (getOpenFirewall()) {
success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCallingAccount());
}
// State might be different after the rule is applied, so get new object here
rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
LoadBalancerResponse lbResponse = new LoadBalancerResponse();
if (rule != null) {
lbResponse = _responseGenerator.createLoadBalancerResponse(rule);
setResponseObject(lbResponse);
}
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create LB rule due to exception ", ex);
} finally {
if (!success || rule == null) {
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(), true);
}
// no need to apply the rule on the backend as it exists in the db only
_lbService.deleteLoadBalancerRule(getEntityId(), false);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer rule");
}
}
}
Aggregations