Search in sources :

Example 61 with ResourceAllocationException

use of com.cloud.exception.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class IpAddressManagerImpl method assignSystemIp.

@Override
public IpAddress assignSystemIp(final long networkId, final Account owner, final boolean forElasticLb, final boolean forElasticIp) throws InsufficientAddressCapacityException {
    final Network guestNetwork = _networksDao.findById(networkId);
    final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
    IpAddress ip = null;
    if ((off.getElasticLb() && forElasticLb) || (off.getElasticIp() && forElasticIp)) {
        try {
            s_logger.debug("Allocating system IP address for load balancer rule...");
            // allocate ip
            ip = allocateIP(owner, true, guestNetwork.getDataCenterId());
            // apply ip associations
            ip = associateIPToGuestNetwork(ip.getId(), networkId, true);
        } catch (final ResourceAllocationException ex) {
            throw new CloudRuntimeException("Failed to allocate system ip due to ", ex);
        } catch (final ConcurrentOperationException ex) {
            throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
        } catch (final ResourceUnavailableException ex) {
            throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
        }
        if (ip == null) {
            throw new CloudRuntimeException("Failed to allocate system ip");
        }
    }
    return ip;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 62 with ResourceAllocationException

use of com.cloud.exception.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.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 63 with ResourceAllocationException

use of com.cloud.exception.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class TemplateManagerImpl method copy.

@Override
@DB
public boolean copy(final long userId, final VMTemplateVO template, final DataStore srcSecStore, final DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
    final long tmpltId = template.getId();
    final long dstZoneId = dstZone.getId();
    // find all eligible image stores for the destination zone
    final List<DataStore> dstSecStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dstZoneId));
    if (dstSecStores == null || dstSecStores.isEmpty()) {
        throw new StorageUnavailableException("Destination zone is not ready, no image store associated", DataCenter.class, dstZone.getId());
    }
    final AccountVO account = _accountDao.findById(template.getAccountId());
    // find the size of the template to be copied
    final TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
    _resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
    _resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()).longValue());
    // Event details
    final String copyEventType;
    if (template.getFormat().equals(ImageFormat.ISO)) {
        copyEventType = EventTypes.EVENT_ISO_COPY;
    } else {
        copyEventType = EventTypes.EVENT_TEMPLATE_COPY;
    }
    final TemplateInfo srcTemplate = _tmplFactory.getTemplate(template.getId(), srcSecStore);
    // for that zone
    for (final DataStore dstSecStore : dstSecStores) {
        final TemplateDataStoreVO dstTmpltStore = _tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId);
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
            // already downloaded on this image store
            return true;
        }
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != Status.DOWNLOAD_IN_PROGRESS) {
            _tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId());
        }
        final AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
        try {
            final TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("copy template failed for image store " + dstSecStore.getName() + ":" + result.getResult());
                // try next image store
                continue;
            }
            _tmpltDao.addTemplateToZone(template, dstZoneId);
            return true;
        } catch (final Exception ex) {
            s_logger.debug("failed to copy template to image store:" + dstSecStore.getName() + " ,will try next one");
        }
    }
    return false;
}
Also used : TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) AccountVO(com.cloud.user.AccountVO) TemplateApiResult(com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DB(com.cloud.utils.db.DB)

Example 64 with ResourceAllocationException

use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.

the class AssignVirtualMachineToBackupOfferingCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        boolean result = backupManager.assignVMToBackupOffering(getVmId(), getOfferingId());
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add VM to backup offering");
        }
    } catch (Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 65 with ResourceAllocationException

use of com.cloud.exception.ResourceAllocationException in project cloudstack by apache.

the class DeleteBackupScheduleCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        boolean result = backupManager.deleteBackupSchedule(getVmId());
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new CloudRuntimeException("Failed to delete VM backup schedule");
        }
    } catch (Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

ResourceAllocationException (com.cloud.exception.ResourceAllocationException)127 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)81 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)76 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)74 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)55 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)41 ServerApiException (org.apache.cloudstack.api.ServerApiException)37 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)33 Account (com.cloud.user.Account)33 DB (com.cloud.utils.db.DB)30 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)27 ArrayList (java.util.ArrayList)25 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)22 ConfigurationException (javax.naming.ConfigurationException)22 ServerApiException (com.cloud.api.ServerApiException)19 TransactionStatus (com.cloud.utils.db.TransactionStatus)18 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)18 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)17 ActionEvent (com.cloud.event.ActionEvent)15 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)15