use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.
the class DeleteSrxFirewallCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
boolean result = _srxElementService.deleteSrxFirewall(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete SRX firewall device");
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.
the class DeleteSspCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
s_logger.trace("execute");
SuccessResponse resp = new SuccessResponse();
resp.setSuccess(_service.deleteSspHost(this));
this.setResponseObject(resp);
}
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) {
sb.append("{\"success\":\"").append(((SuccessResponse) result).getSuccess()).append("\"}");
log.append("{\"success\":\"").append(((SuccessResponse) result).getSuccess()).append("\"}");
} else if (result instanceof ExceptionResponse) {
String jsonErrorText = responseBuilder.toJson(result);
jsonErrorText = unescape(jsonErrorText);
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;
}
use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.
the class DeleteBrocadeVcsDeviceCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
boolean result = brocadeVcsElementService.deleteBrocadeVcsDevice(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Brocade VCS Switch.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
use of org.apache.cloudstack.api.response.SuccessResponse in project cloudstack by apache.
the class DeleteNetscalerLoadBalancerCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
boolean result = _netsclarLbService.deleteNetscalerLoadBalancer(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete netscaler load balancer.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
Aggregations