Search in sources :

Example 46 with SuccessResponse

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

the class DeleteGlobalLoadBalancerRuleCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Deleting global Load balancer rule Id: " + getGlobalLoadBalancerId());
    boolean result = _gslbService.deleteGlobalLoadBalancerRule(this);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Global Load Balancer rule.");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 47 with SuccessResponse

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

the class ApiResponseSerializer method toJSONSerializedString.

public static String toJSONSerializedString(ResponseObject result, StringBuilder log) {
    if (result != null && log != null) {
        Gson responseBuilder = ApiResponseGsonHelper.getBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
        Gson logBuilder = ApiResponseGsonHelper.getLogBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
        StringBuilder sb = new StringBuilder();
        sb.append("{\"").append(result.getResponseName()).append("\":");
        log.append("{\"").append(result.getResponseName()).append("\":");
        if (result instanceof ListResponse) {
            List<? extends ResponseObject> responses = ((ListResponse) result).getResponses();
            Integer count = ((ListResponse) result).getCount();
            boolean nonZeroCount = (count != null && count.longValue() != 0);
            if (nonZeroCount) {
                sb.append("{\"").append(ApiConstants.COUNT).append("\":").append(count);
                log.append("{\"").append(ApiConstants.COUNT).append("\":").append(count);
            }
            if ((responses != null) && !responses.isEmpty()) {
                String jsonStr = responseBuilder.toJson(responses.get(0));
                jsonStr = unescape(jsonStr);
                String logStr = logBuilder.toJson(responses.get(0));
                logStr = unescape(logStr);
                if (nonZeroCount) {
                    sb.append(",\"").append(responses.get(0).getObjectName()).append("\":[").append(jsonStr);
                    log.append(",\"").append(responses.get(0).getObjectName()).append("\":[").append(logStr);
                }
                for (int i = 1; i < ((ListResponse) result).getResponses().size(); i++) {
                    jsonStr = responseBuilder.toJson(responses.get(i));
                    jsonStr = unescape(jsonStr);
                    logStr = logBuilder.toJson(responses.get(i));
                    logStr = unescape(logStr);
                    sb.append(",").append(jsonStr);
                    log.append(",").append(logStr);
                }
                sb.append("]}");
                log.append("]}");
            } else {
                if (!nonZeroCount) {
                    sb.append("{");
                    log.append("{");
                }
                sb.append("}");
                log.append("}");
            }
        } else if (result instanceof SuccessResponse || result instanceof ExceptionResponse) {
            final String jsonErrorText = unescape(responseBuilder.toJson(result));
            sb.append(jsonErrorText);
            log.append(jsonErrorText);
        } else {
            String jsonStr = responseBuilder.toJson(result);
            if (jsonStr != null && !jsonStr.isEmpty()) {
                jsonStr = unescape(jsonStr);
                if (result instanceof AsyncJobResponse || result instanceof CreateCmdResponse || result instanceof AuthenticationCmdResponse) {
                    sb.append(jsonStr);
                } else {
                    sb.append("{\"").append(result.getObjectName()).append("\":").append(jsonStr).append("}");
                }
            } else {
                sb.append("{}");
            }
            String logStr = logBuilder.toJson(result);
            if (logStr != null && !logStr.isEmpty()) {
                logStr = unescape(logStr);
                if (result instanceof AsyncJobResponse || result instanceof CreateCmdResponse || result instanceof AuthenticationCmdResponse) {
                    log.append(logStr);
                } else {
                    log.append("{\"").append(result.getObjectName()).append("\":").append(logStr).append("}");
                }
            } else {
                log.append("{}");
            }
        }
        sb.append("}");
        log.append("}");
        return sb.toString();
    }
    return null;
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ExceptionResponse(org.apache.cloudstack.api.response.ExceptionResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) AsyncJobResponse(org.apache.cloudstack.api.response.AsyncJobResponse) Gson(com.google.gson.Gson) CreateCmdResponse(org.apache.cloudstack.api.response.CreateCmdResponse) AuthenticationCmdResponse(org.apache.cloudstack.api.response.AuthenticationCmdResponse)

Example 48 with SuccessResponse

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

the class ResetApiLimitCmd method execute.

@Override
public void execute() {
    boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
    if (!apiLimitEnabled) {
        throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
    }
    boolean result = _apiLimitService.resetApiLimit(this.accountId);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset api limit counter");
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 49 with SuccessResponse

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

the class DeleteF5LoadBalancerCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        boolean result = _f5DeviceManagerService.deleteF5LoadBalancer(this);
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete F5 load balancer.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 50 with SuccessResponse

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

the class DeleteCiscoVnmcResourceCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        boolean result = _ciscoVnmcElementService.deleteCiscoVnmcResource(this);
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Cisco Vnmc resource.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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