use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class DeleteSslCertCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
_certService.deleteSslCert(this);
SuccessResponse rsp = new SuccessResponse();
rsp.setResponseName(getCommandName());
rsp.setObjectName("success");
this.setResponseObject(rsp);
} catch (Exception e) {
throw new CloudRuntimeException(e);
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class CreateApplicationLoadBalancerCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
ApplicationLoadBalancerRule rule = null;
try {
CallContext.current().setEventDetails("Load Balancer Id: " + getEntityId());
// State might be different after the rule is applied, so get new object here
rule = _entityMgr.findById(ApplicationLoadBalancerRule.class, getEntityId());
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getEntityId()));
setResponseObject(lbResponse);
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create load balancer due to exception ", ex);
} finally {
if (rule == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer");
}
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class DeployVMCmd method execute.
@Override
public void execute() {
UserVm result;
if (getStartVm()) {
try {
CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
result = _userVmService.startVirtualMachine(this);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (InsufficientCapacityException ex) {
StringBuilder message = new StringBuilder(ex.getMessage());
if (ex instanceof InsufficientServerCapacityException) {
if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
}
}
s_logger.info(ex);
s_logger.info(message.toString(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
}
} else {
result = _userVmService.getUserVm(getEntityId());
}
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm uuid:" + getEntityUuid());
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class DeployVMCmd method create.
@Override
public void create() throws ResourceAllocationException {
try {
UserVm vm = _userVmService.createVirtualMachine(this);
if (vm != null) {
setEntityId(vm.getId());
setEntityUuid(vm.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
s_logger.trace(ex.getMessage(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
}
}
use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.
the class AddNetworkServiceProviderCmdTest method testCreateProviderToPhysicalNetworkSuccess.
@Test
public void testCreateProviderToPhysicalNetworkSuccess() {
NetworkService networkService = Mockito.mock(NetworkService.class);
addNetworkServiceProviderCmd._networkService = networkService;
PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class);
Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(physicalNetworkServiceProvider);
try {
addNetworkServiceProviderCmd.create();
} catch (ResourceAllocationException e) {
e.printStackTrace();
}
}
Aggregations