use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.
the class DeleteSslCertCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
_certService.deleteSslCert(this);
final SuccessResponse rsp = new SuccessResponse();
rsp.setResponseName(getCommandName());
rsp.setObjectName("success");
this.setResponseObject(rsp);
} catch (final Exception e) {
throw new CloudRuntimeException(e);
}
}
use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.
the class UploadSslCertCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
final SslCertResponse response = _certService.uploadSslCert(this);
setResponseObject(response);
response.setResponseName(getCommandName());
} catch (final Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.
the class CommandCreationWorker method handle.
@Override
public void handle(final DispatchTask task) {
final BaseCmd cmd = task.getCmd();
if (cmd instanceof BaseAsyncCreateCmd) {
try {
CallContext.current().setEventDisplayEnabled(cmd.isDisplay());
((BaseAsyncCreateCmd) cmd).create();
} catch (final ResourceAllocationException e) {
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, e.getMessage(), e);
}
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ATTEMP_TO_CREATE_NON_CREATION_CMD);
}
}
use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.
the class ProjectManagerImpl method updateProject.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project", async = true)
public Project updateProject(final long projectId, final String displayText, final String newOwnerName) throws ResourceAllocationException {
final Account caller = CallContext.current().getCallingAccount();
// check that the project exists
final ProjectVO project = getProject(projectId);
if (project == null) {
throw new InvalidParameterValueException("Unable to find the project id=" + projectId);
}
// verify permissions
_accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<ResourceAllocationException>() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) throws ResourceAllocationException {
if (displayText != null) {
project.setDisplayText(displayText);
_projectDao.update(projectId, project);
}
if (newOwnerName != null) {
// check that the new owner exists
final Account futureOwnerAccount = _accountMgr.getActiveAccountByName(newOwnerName, project.getDomainId());
if (futureOwnerAccount == null) {
throw new InvalidParameterValueException("Unable to find account name=" + newOwnerName + " in domain id=" + project.getDomainId());
}
final Account currentOwnerAccount = getProjectOwner(projectId);
if (currentOwnerAccount.getId() != futureOwnerAccount.getId()) {
final ProjectAccountVO futureOwner = _projectAccountDao.findByProjectIdAccountId(projectId, futureOwnerAccount.getAccountId());
if (futureOwner == null) {
throw new InvalidParameterValueException("Account " + newOwnerName + " doesn't belong to the project. Add it to the project first and then change the project's ownership");
}
// do resource limit check
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(futureOwnerAccount.getId()), ResourceType.project);
// unset the role for the old owner
final ProjectAccountVO currentOwner = _projectAccountDao.findByProjectIdAccountId(projectId, currentOwnerAccount.getId());
currentOwner.setAccountRole(Role.Regular);
_projectAccountDao.update(currentOwner.getId(), currentOwner);
_resourceLimitMgr.decrementResourceCount(currentOwnerAccount.getId(), ResourceType.project);
// set new owner
futureOwner.setAccountRole(Role.Admin);
_projectAccountDao.update(futureOwner.getId(), futureOwner);
_resourceLimitMgr.incrementResourceCount(futureOwnerAccount.getId(), ResourceType.project);
} else {
s_logger.trace("Future owner " + newOwnerName + "is already the owner of the project id=" + projectId);
}
}
}
});
return _projectDao.findById(projectId);
}
use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method takeSnapshot.
@Override
@DB
public SnapshotInfo takeSnapshot(final VolumeInfo volume) throws ResourceAllocationException {
final CreateSnapshotPayload payload = (CreateSnapshotPayload) volume.getpayload();
final Long snapshotId = payload.getSnapshotId();
final Account snapshotOwner = payload.getAccount();
final SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotId, volume.getDataStore());
snapshot.addPayload(payload);
try {
final SnapshotStrategy snapshotStrategy = this._storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy == null) {
throw new CloudRuntimeException("Can't find snapshot strategy to deal with snapshot:" + snapshotId);
}
snapshotStrategy.takeSnapshot(snapshot);
try {
SnapshotDataStoreVO snapshotStoreRef = this._snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
if (snapshotStoreRef == null) {
// The snapshot was not backed up to secondary. Find the snap on primary
snapshotStoreRef = this._snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary);
if (snapshotStoreRef == null) {
throw new CloudRuntimeException("Could not find snapshot");
}
}
// Correct the resource count of snapshot in case of delta snapshots.
this._resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getPhysicalSize()));
} catch (final Exception e) {
s_logger.debug("post process snapshot failed", e);
}
} catch (final Exception e) {
s_logger.debug("Failed to create snapshot", e);
this._resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
this._resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize()));
throw new CloudRuntimeException("Failed to create snapshot", e);
}
return snapshot;
}
Aggregations