Search in sources :

Example 6 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class CreateTemplateCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Template Id: " + getEntityId() + ((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
    VirtualMachineTemplate template = null;
    template = _templateService.createPrivateTemplate(this);
    if (template != null) {
        List<TemplateResponse> templateResponses;
        if (isBareMetal()) {
            templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template.getId(), vmId);
        } else {
            templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template.getId(), snapshotId, volumeId, false);
        }
        TemplateResponse response = new TemplateResponse();
        if (templateResponses != null && !templateResponses.isEmpty()) {
            response = templateResponses.get(0);
        }
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 7 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class RegisterTemplateCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        VirtualMachineTemplate template = _templateService.registerTemplate(this);
        if (template != null) {
            ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
            List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template, zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (URISyntaxException ex1) {
        s_logger.info(ex1);
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) URISyntaxException(java.net.URISyntaxException)

Example 8 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class RemoveAccountFromIAMGroupCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
    CallContext.current().setEventDetails("IAM group Id: " + getId());
    IAMGroup result = _iamApiSrv.removeAccountsFromGroup(accountIdList, id);
    if (result != null) {
        IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove accounts from iam group");
    }
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse)

Example 9 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class CreateIAMGroupCmd method create.

@Override
public void create() throws ResourceAllocationException {
    Account account = CallContext.current().getCallingAccount();
    IAMGroup result = _iamApiSrv.createIAMGroup(account, name, description);
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam group entity" + name);
    }
}
Also used : Account(com.cloud.user.Account) IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 10 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class CreateIAMPolicyCmd method execute.

@Override
public void execute() {
    IAMPolicy policy = _entityMgr.findById(IAMPolicy.class, getEntityId());
    if (policy != null) {
        IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(policy);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam policy:" + name);
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) IAMPolicy(org.apache.cloudstack.iam.api.IAMPolicy) IAMPolicyResponse(org.apache.cloudstack.api.response.iam.IAMPolicyResponse)

Aggregations

ServerApiException (org.apache.cloudstack.api.ServerApiException)628 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)154 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)143 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)104 ArrayList (java.util.ArrayList)74 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)55 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)51 ListResponse (org.apache.cloudstack.api.response.ListResponse)49 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)47 UserVm (com.cloud.uservm.UserVm)47 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)43 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)42 Account (com.cloud.user.Account)32 Host (com.cloud.host.Host)30 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)29 Volume (com.cloud.storage.Volume)25 Test (org.junit.Test)23 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)20 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)15 UserAccount (com.cloud.user.UserAccount)15