Search in sources :

Example 11 with ResourceAllocationException

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

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 {
    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(TransactionStatus status) throws ResourceAllocationException {
            if (displayText != null) {
                project.setDisplayText(displayText);
                _projectDao.update(projectId, project);
            }
            if (newOwnerName != null) {
                //check that the new owner exists
                Account futureOwnerAccount = _accountMgr.getActiveAccountByName(newOwnerName, project.getDomainId());
                if (futureOwnerAccount == null) {
                    throw new InvalidParameterValueException("Unable to find account name=" + newOwnerName + " in domain id=" + project.getDomainId());
                }
                Account currentOwnerAccount = getProjectOwner(projectId);
                if (currentOwnerAccount.getId() != futureOwnerAccount.getId()) {
                    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
                    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.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 12 with ResourceAllocationException

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

the class ListNicsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    try {
        List<? extends Nic> results = _networkService.listNics(this);
        ListResponse<NicResponse> response = new ListResponse<NicResponse>();
        List<NicResponse> resList = null;
        if (results != null) {
            resList = new ArrayList<NicResponse>(results.size());
            for (Nic r : results) {
                NicResponse resp = _responseGenerator.createNicResponse(r);
                resp.setObjectName("nic");
                resList.add(resp);
            }
            response.setResponses(resList);
        }
        response.setResponses(resList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Failed to list secondary ip address per nic ");
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Nic(com.cloud.vm.Nic) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 13 with ResourceAllocationException

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

the class GetUploadParamsForTemplateCmd method execute.

@Override
public void execute() throws ServerApiException {
    validateRequest();
    try {
        GetUploadParamsResponse response = _templateService.registerTemplateForPostUpload(this);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (ResourceAllocationException | MalformedURLException e) {
        s_logger.error("exception while registering template", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while registering template: " + e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) GetUploadParamsResponse(org.apache.cloudstack.api.response.GetUploadParamsResponse)

Example 14 with ResourceAllocationException

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

the class AddBaremetalPxeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BaremetalPxeVO vo = pxeMgr.addPxeServer(this);
        BaremetalPxeResponse rsp = pxeMgr.getApiResponse(vo);
        rsp.setResponseName(getCommandName());
        this.setResponseObject(rsp);
    } catch (Exception e) {
        s_logger.warn("Unable to add external pxe server with url: " + getUrl(), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BaremetalPxeResponse(com.cloud.baremetal.networkservice.BaremetalPxeResponse) 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) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Example 15 with ResourceAllocationException

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

the class AddBaremetalRctCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BaremetalRctResponse rsp = vlanMgr.addRct(this);
        this.setResponseObject(rsp);
    } catch (Exception e) {
        s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Aggregations

ResourceAllocationException (com.cloud.exception.ResourceAllocationException)58 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)40 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)40 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)37 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 ServerApiException (org.apache.cloudstack.api.ServerApiException)19 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)17 Account (com.cloud.user.Account)14 DB (com.cloud.utils.db.DB)14 ArrayList (java.util.ArrayList)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)12 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)11 ConfigurationException (javax.naming.ConfigurationException)10 TransactionStatus (com.cloud.utils.db.TransactionStatus)9 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)8 DataCenter (com.cloud.dc.DataCenter)7 StorageNetworkIpRange (com.cloud.dc.StorageNetworkIpRange)6 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)6 Date (java.util.Date)6