Search in sources :

Example 11 with ResourceAllocationException

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);
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ServerApiException(com.cloud.api.ServerApiException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException)

Example 12 with ResourceAllocationException

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());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) SslCertResponse(com.cloud.api.response.SslCertResponse) ServerApiException(com.cloud.api.ServerApiException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException)

Example 13 with ResourceAllocationException

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);
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) BaseAsyncCreateCmd(com.cloud.api.BaseAsyncCreateCmd) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) BaseCmd(com.cloud.api.BaseCmd)

Example 14 with ResourceAllocationException

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);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 15 with ResourceAllocationException

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;
}
Also used : Account(com.cloud.legacymodel.user.Account) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) SnapshotStrategy(com.cloud.engine.subsystem.api.storage.SnapshotStrategy) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConfigurationException(javax.naming.ConfigurationException) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Aggregations

ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)37 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)20 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)19 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)18 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)18 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)17 ServerApiException (com.cloud.api.ServerApiException)14 DB (com.cloud.utils.db.DB)13 Account (com.cloud.legacymodel.user.Account)11 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)8 ArrayList (java.util.ArrayList)8 ConfigurationException (javax.naming.ConfigurationException)8 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)7 TransactionStatus (com.cloud.utils.db.TransactionStatus)7 ExecutionException (java.util.concurrent.ExecutionException)6 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)5 Network (com.cloud.legacymodel.network.Network)5 HypervisorType (com.cloud.model.enumeration.HypervisorType)5 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)5 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4