Search in sources :

Example 71 with SuccessResponse

use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.

the class AddAccountToProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    if (accountName == null && email == null) {
        throw new InvalidParameterValueException("Either accountName or email is required");
    }
    CallContext.current().setEventDetails("Project ID: " + projectId + "; accountName " + accountName);
    boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail(), getProjectRoleId(), getRoleType());
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add account to the project");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 72 with SuccessResponse

use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.

the class DeleteVPCOfferingCmd method execute.

@Override
public void execute() {
    boolean result = _vpcProvSvc.deleteVpcOffering(getId());
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC offering");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 73 with SuccessResponse

use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.

the class DeleteVPCCmd method execute.

@Override
public void execute() {
    try {
        boolean result = _vpcService.deleteVpc(getId());
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC");
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 74 with SuccessResponse

use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.

the class RemoveVpnUserCmd method execute.

@Override
public void execute() {
    Account owner = _accountService.getAccount(getEntityOwnerId());
    long ownerId = owner.getId();
    boolean result = _ravService.removeVpnUser(ownerId, userName, CallContext.current().getCallingAccount());
    if (!result) {
        String errorMessage = String.format("Failed to remove VPN user=[%s]. VPN owner id=[%s].", userName, ownerId);
        s_logger.error(errorMessage);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage);
    }
    boolean appliedVpnUsers = false;
    try {
        appliedVpnUsers = _ravService.applyVpnUsers(ownerId, userName, true);
    } catch (ResourceUnavailableException ex) {
        String errorMessage = String.format("Failed to refresh VPN user=[%s] due to resource unavailable. VPN owner id=[%s].", userName, ownerId);
        s_logger.error(errorMessage, ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage, ex);
    }
    if (!appliedVpnUsers) {
        String errorMessage = String.format("Failed to refresh VPN user=[%s]. VPN owner id=[%s].", userName, ownerId);
        s_logger.debug(errorMessage);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage);
    }
    SuccessResponse response = new SuccessResponse(getCommandName());
    setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 75 with SuccessResponse

use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.

the class DeleteVpnCustomerGatewayCmd method execute.

@Override
public void execute() {
    boolean result = _s2sVpnService.deleteCustomerGateway(this);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete customer VPN gateway");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)171 ServerApiException (org.apache.cloudstack.api.ServerApiException)154 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)19 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)14 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)13 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)13 ResourceInUseException (com.cloud.exception.ResourceInUseException)4 Host (com.cloud.host.Host)3 Account (com.cloud.user.Account)3 ArrayList (java.util.ArrayList)3 List (java.util.List)2 EntityExistsException (javax.persistence.EntityExistsException)2 ProjectRole (org.apache.cloudstack.acl.ProjectRole)2 ProjectRolePermission (org.apache.cloudstack.acl.ProjectRolePermission)2 Role (org.apache.cloudstack.acl.Role)2 RolePermission (org.apache.cloudstack.acl.RolePermission)2 Domain (com.cloud.domain.Domain)1