bug 6998: return embedded job result object in queryAsyncJobResult command

status 6998: resolved fixed
This commit is contained in:
alena 2010-11-05 11:56:16 -07:00
parent d0e51c1f79
commit b9ad299ac6
50 changed files with 88 additions and 119 deletions

View File

@ -99,7 +99,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
public SuccessResponse getResponse() {
SuccessResponse response = new SuccessResponse();
response.setSuccess(Boolean.TRUE);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -108,7 +108,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
response.setVirtualMachineId(virtualMachineId);
response.setVirtualMachineName(vmInstance.getHostName());
response.setVirtualMachineState(vmInstance.getState().toString());
response.setResponseName(getName());
response.setResponseName("iso");
return response;
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso");

View File

@ -110,7 +110,7 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
public VolumeResponse getResponse() {
VolumeVO volume = (VolumeVO)getResponseObject();
VolumeResponse response = ApiResponseHelper.createVolumeResponse(volume);
response.setResponseName(getName());
response.setResponseName("volume");
return response;
}
}

View File

@ -238,7 +238,7 @@ public class AuthorizeNetworkGroupIngressCmd extends BaseAsyncCmd {
response.setResponses(responses);
}
response.setResponseName(getName());
response.setResponseName("networkgroup");
return response;
}
}

View File

@ -92,7 +92,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
public HostResponse getResponse() {
HostVO host = (HostVO)getResponseObject();
HostResponse response = ApiResponseHelper.createHostResponse(host);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -92,7 +92,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
public StoragePoolResponse getResponse() {
StoragePoolVO primaryStorage = (StoragePoolVO)getResponseObject();
StoragePoolResponse response = ApiResponseHelper.createStoragePoolResponse(primaryStorage);
response.setResponseName(getName());
response.setResponseName("storagepool");
return response;
}
}

View File

@ -175,7 +175,7 @@ public class CopyIsoCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy iso");
}
isoResponse.setResponseName(getName());
isoResponse.setResponseName("iso");
return isoResponse;
}

View File

@ -178,7 +178,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy template");
}
templateResponse.setResponseName(getName());
templateResponse.setResponseName("template");
return templateResponse;
}
}

View File

@ -110,7 +110,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
response.setAccountName(responseObj.getAccountName());
response.setDomainId(responseObj.getDomainId());
response.setDomainName(ApiDBUtils.findDomainById(responseObj.getDomainId()).getName());
response.setResponseName(getName());
response.setResponseName("remoteaccessvpn");
response.setPresharedKey(responseObj.getIpsecPresharedKey());
return response;
}

View File

@ -109,7 +109,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
if (snapshot != null) {
SnapshotResponse response = ApiResponseHelper.createSnapshotResponse(snapshot);
response.setResponseName(getName());
response.setResponseName("snapshot");
return response;
}

View File

@ -116,7 +116,7 @@ public class CreateSnapshotInternalCmd extends BaseAsyncCmd {
response.setCreated(snapshot.getCreated());
response.setName(snapshot.getName());
response.setResponseName(getName());
response.setResponseName("snapshot");
return response;
}
}

View File

@ -211,7 +211,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
response.setZoneName(zone.getName());
}
response.setResponseName(getName());
response.setResponseName("template");
return response;
}
}

View File

@ -146,7 +146,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
VolumeResponse response = ApiResponseHelper.createVolumeResponse(volume);
//FIXME - have to be moved to ApiResponseHelper
response.setSnapshotId(getSnapshotId()); // if the volume was created from a snapshot, snapshotId will be set so we pass it back in the response
response.setResponseName(getName());
response.setResponseName("volume");
return response;
}
}

View File

@ -100,7 +100,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete host");
}
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -84,7 +84,7 @@ public class DeleteIsoCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete iso");
}
response.setResponseName(getName());
response.setResponseName("success");
return response;
}

View File

@ -84,7 +84,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -82,7 +82,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}

View File

@ -100,7 +100,7 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -78,7 +78,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}

View File

@ -93,7 +93,7 @@ public class DeleteUserCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -196,7 +196,7 @@ public class DeployVMCmd extends BaseAsyncCmd {
// if (templatePasswordEnabled) {
// response.setPassword(getPassword());
// }
response.setResponseName(getName());
response.setResponseName("virtualmachine");
return response;
}
}

View File

@ -87,7 +87,7 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -85,7 +85,7 @@ public class DestroyVMCmd extends BaseAsyncCmd {
public UserVmResponse getResponse() {
UserVm userVm = (UserVm)getResponseObject();
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
recoverVmResponse.setResponseName(getName());
recoverVmResponse.setResponseName("virtualmachine");
return recoverVmResponse;
}
}

View File

@ -85,7 +85,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("iso");
return response;
}
}

View File

@ -120,7 +120,7 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
public VolumeResponse getResponse() {
VolumeVO volume = (VolumeVO)getResponseObject();
VolumeResponse response = ApiResponseHelper.createVolumeResponse(volume);
response.setResponseName(getName());
response.setResponseName("volume");
return response;
}
}

View File

@ -91,7 +91,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
public AccountResponse getResponse() {
AccountVO account = (AccountVO)getResponseObject();
AccountResponse response = ApiResponseHelper.createAccountResponse(account);
response.setResponseName(getName());
response.setResponseName("account");
return response;
}
}

View File

@ -83,7 +83,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
public UserResponse getResponse() {
UserAccount user = (UserAccount)getResponseObject();
UserResponse response = ApiResponseHelper.createUserResponse(user);
response.setResponseName(getName());
response.setResponseName("user");
return response;
}
}

View File

@ -108,7 +108,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
ExtractResponse response = new ExtractResponse();
response.setResponseName(getName());
response.setResponseName("iso");
response.setId(id);
response.setName(ApiDBUtils.findTemplateById(id).getName());
response.setZoneId(zoneId);

View File

@ -113,7 +113,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
ExtractResponse response = new ExtractResponse();
response.setResponseName(getName());
response.setResponseName("template");
response.setId(id);
response.setName(ApiDBUtils.findTemplateById(id).getName());
response.setZoneId(zoneId);

View File

@ -111,7 +111,7 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
ExtractResponse response = new ExtractResponse();
response.setResponseName(getName());
response.setResponseName("volume");
response.setId(id);
response.setName(ApiDBUtils.findVolumeById(id).getName());
response.setZoneId(zoneId);

View File

@ -89,7 +89,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
public HostResponse getResponse() {
HostVO host = (HostVO)getResponseObject();
HostResponse response = ApiResponseHelper.createHostResponse(host);
response.setResponseName(getName());
response.setResponseName("host");
return response;
}
}

View File

@ -88,7 +88,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
public StoragePoolResponse getResponse() {
StoragePoolVO primaryStorage = (StoragePoolVO)getResponseObject();
StoragePoolResponse response = ApiResponseHelper.createStoragePoolResponse(primaryStorage);
response.setResponseName(getName());
response.setResponseName("storagepool");
return response;
}
}

View File

@ -86,7 +86,7 @@ public class RebootRouterCmd extends BaseAsyncCmd {
public DomainRouterResponse getResponse() {
DomainRouter router = (DomainRouter)getResponseObject();
DomainRouterResponse response = ApiResponseHelper.createDomainRouterResponse(router);
response.setResponseName(getName());
response.setResponseName("router");
return response;
}
}

View File

@ -86,7 +86,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
public SystemVmResponse getResponse() {
VMInstanceVO instance = (VMInstanceVO)getResponseObject();
SystemVmResponse response = ApiResponseHelper.createSystemVmResponse(instance);
response.setResponseName(getName());
response.setResponseName("systemvm");
return response;
}
}

View File

@ -85,7 +85,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
public UserVmResponse getResponse() {
UserVm userVm = (UserVm)getResponseObject();
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
recoverVmResponse.setResponseName(getName());
recoverVmResponse.setResponseName("virtualmachine");
return recoverVmResponse;
}
}

View File

@ -90,7 +90,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
public HostResponse getResponse() {
HostVO host = (HostVO)getResponseObject();
HostResponse response = ApiResponseHelper.createHostResponse(host);
response.setResponseName(getName());
response.setResponseName("host");
return response;
}

View File

@ -108,7 +108,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -87,7 +87,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}

View File

@ -104,7 +104,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
// if (templatePasswordEnabled) {
// response.setPassword(getPassword());
// }
response.setResponseName(getName());
response.setResponseName("virtualmachine");
return response;
}
}

View File

@ -183,7 +183,7 @@ public class RevokeNetworkGroupIngressCmd extends BaseAsyncCmd {
Boolean success = (Boolean)getResponseObject();
SuccessResponse response = new SuccessResponse();
response.setSuccess(success);
response.setResponseName(getName());
response.setResponseName("success");
return response;
}
}

View File

@ -92,7 +92,7 @@ public class StartRouterCmd extends BaseAsyncCmd {
public DomainRouterResponse getResponse() {
DomainRouter router = (DomainRouter)getResponseObject();
DomainRouterResponse routerResponse = ApiResponseHelper.createDomainRouterResponse(router);
routerResponse.setResponseName(getName());
routerResponse.setResponseName("router");
return routerResponse;
}
}

View File

@ -90,7 +90,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
public SystemVmResponse getResponse() {
VMInstanceVO instance = (VMInstanceVO)getResponseObject();
SystemVmResponse response = ApiResponseHelper.createSystemVmResponse(instance);
response.setResponseName(getName());
response.setResponseName("systemvm");
return response;
}
}

View File

@ -89,7 +89,7 @@ public class StartVMCmd extends BaseAsyncCmd {
public UserVmResponse getResponse() {
UserVm userVm = (UserVm)getResponseObject();
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
recoverVmResponse.setResponseName(getName());
recoverVmResponse.setResponseName("virtualmachine");
return recoverVmResponse;
}
}

View File

@ -87,7 +87,7 @@ public class StopRouterCmd extends BaseAsyncCmd {
public DomainRouterResponse getResponse() {
DomainRouter router = (DomainRouter)getResponseObject();
DomainRouterResponse response =ApiResponseHelper.createDomainRouterResponse(router);
response.setResponseName(getName());
response.setResponseName("router");
return response;
}
}

View File

@ -21,7 +21,7 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -30,8 +30,6 @@ import com.cloud.event.EventTypes;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.VMInstanceVO;
@Implementation(method="stopSystemVM", manager=ManagementServer.class, description="Stops a system VM.")
@ -87,49 +85,8 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
@Override @SuppressWarnings("unchecked")
public SystemVmResponse getResponse() {
VMInstanceVO instance = (VMInstanceVO)getResponseObject();
SystemVmResponse response = new SystemVmResponse();
response.setId(instance.getId());
response.setName(instance.getHostName());
response.setZoneId(instance.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(instance.getDataCenterId()).getName());
response.setPodId(instance.getPodId());
response.setHostId(instance.getHostId());
if (response.getHostId() != null) {
response.setHostName(ApiDBUtils.findHostById(instance.getHostId()).getName());
}
response.setPrivateIp(instance.getPrivateIpAddress());
response.setPrivateMacAddress(instance.getPrivateMacAddress());
response.setPrivateNetmask(instance.getPrivateNetmask());
response.setTemplateId(instance.getTemplateId());
response.setCreated(instance.getCreated());
response.setState(instance.getState().toString());
if (instance instanceof SecondaryStorageVmVO) {
SecondaryStorageVmVO ssVm = (SecondaryStorageVmVO) instance;
response.setDns1(ssVm.getDns1());
response.setDns2(ssVm.getDns2());
response.setNetworkDomain(ssVm.getDomain());
response.setGateway(ssVm.getGateway());
response.setPublicIp(ssVm.getPublicIpAddress());
response.setPublicMacAddress(ssVm.getPublicMacAddress());
response.setPublicNetmask(ssVm.getPublicNetmask());
} else if (instance instanceof ConsoleProxyVO) {
ConsoleProxyVO proxy = (ConsoleProxyVO)instance;
response.setDns1(proxy.getDns1());
response.setDns2(proxy.getDns2());
response.setNetworkDomain(proxy.getDomain());
response.setGateway(proxy.getGateway());
response.setPublicIp(proxy.getPublicIpAddress());
response.setPublicMacAddress(proxy.getPublicMacAddress());
response.setPublicNetmask(proxy.getPublicNetmask());
response.setActiveViewerSessions(proxy.getActiveSession());
}
response.setResponseName(getName());
SystemVmResponse response = ApiResponseHelper.createSystemVmResponse(instance);
response.setResponseName("systemvm");
return response;
}
}

View File

@ -89,7 +89,7 @@ public class StopVMCmd extends BaseAsyncCmd {
public UserVmResponse getResponse() {
UserVm userVm = (UserVm)getResponseObject();
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
recoverVmResponse.setResponseName(getName());
recoverVmResponse.setResponseName("virtualmachine");
return recoverVmResponse;
}
}

View File

@ -104,7 +104,7 @@ public class UpdateIPForwardingRuleCmd extends BaseAsyncCmd {
public FirewallRuleResponse getResponse() {
FirewallRuleVO fwRule = (FirewallRuleVO)getResponseObject();
FirewallRuleResponse response = ApiResponseHelper.createFirewallRuleResponse(fwRule);
response.setResponseName(getName());
response.setResponseName("portforwardingrule");
return response;
}
}

View File

@ -111,7 +111,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
public LoadBalancerResponse getResponse() {
LoadBalancerVO loadBalancer = (LoadBalancerVO)getResponseObject();
LoadBalancerResponse response = ApiResponseHelper.createLoadBalancerResponse(loadBalancer);
response.setResponseName(getName());
response.setResponseName("loadbalancerrule");
return response;
}
}

View File

@ -23,7 +23,6 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.CustomCertificateResponse;
import com.cloud.event.EventTypes;
import com.cloud.user.Account;
@ -45,7 +44,7 @@ public class UploadCustomCertificateCmd extends BaseAsyncCmd {
public CustomCertificateResponse getResponse() {
String updatedCpIdList = (String)getResponseObject();
CustomCertificateResponse response = new CustomCertificateResponse();
response.setResponseName(s_name);
response.setResponseName("customcertificate");
response.setUpdatedConsoleProxyIdList(updatedCpIdList);
return response;
}

View File

@ -51,28 +51,29 @@ public class ApiResponseSerializer {
* If the old style (2.1.x) async job responses are desired, uncomment the following code. Note: Many of the commands will need to set the response name to
* something like "getResultObjectName()" [see StopVMCmd for an example] in order to truly reinstate the old behavior. The current response names are based
* on the new style. Also, this is done for JSON, so the XML Serializer will need to be fixed up to compensate, but the following code can be used to guide
* the changes to XML serializer.
} else if (result instanceof AsyncJobResponse) {
// this code is in here to preserve old behavior for the async job result response
AsyncJobResponse asyncResponse = (AsyncJobResponse)result;
if ("object".equalsIgnoreCase(asyncResponse.getJobResultType())) {
// we require special handling for object, otherwise we serialize it the standard way
ResponseObject subResponse = asyncResponse.getJobResult();
asyncResponse.setJobResult(null);
String jsonStr = gson.toJson(result);
int index = jsonStr.lastIndexOf('}');
sb.append(jsonStr.substring(0, index));
String subRespJson = gson.toJson(subResponse);
sb.append(", \"" + subResponse.getResponseName() + "\" : [ " + subRespJson + " ] }");
} else {
String jsonStr = gson.toJson(result);
if ((jsonStr != null) && !"".equals(jsonStr)) {
sb.append(jsonStr);
} else {
sb.append("{ }");
}
}
*/
* the changes to XML serializer. */
// } else if (result instanceof AsyncJobResponse) {
// // this code is in here to preserve old behavior for the async job result response
// AsyncJobResponse asyncResponse = (AsyncJobResponse)result;
// if ("object".equalsIgnoreCase(asyncResponse.getJobResultType())) {
// // we require special handling for object, otherwise we serialize it the standard way
// ResponseObject subResponse = asyncResponse.getJobResult();
// asyncResponse.setJobResult(null);
// String jsonStr = gson.toJson(result);
// int index = jsonStr.lastIndexOf('}');
// sb.append(jsonStr.substring(0, index));
// String subRespJson = gson.toJson(subResponse);
// sb.append(", \"" + subResponse.getResponseName() + "\" : [ " + subRespJson + " ] }");
// } else {
// String jsonStr = gson.toJson(result);
// if ((jsonStr != null) && !"".equals(jsonStr)) {
// sb.append(jsonStr);
// } else {
// sb.append("{ }");
// }
// }
} else {
String jsonStr = gson.toJson(result);
if ((jsonStr != null) && !"".equals(jsonStr)) {
@ -108,12 +109,18 @@ public class ApiResponseSerializer {
}
private static void serializeResponseObjXML(StringBuilder sb, ResponseObject obj) {
sb.append("<" + obj.getResponseName() + ">");
if (!(obj instanceof SuccessResponse)&& !(obj instanceof ExceptionResponse))
sb.append("<" + obj.getResponseName() + ">");
serializeResponseObjFieldsXML(sb, obj);
sb.append("</" + obj.getResponseName() + ">");
if (!(obj instanceof SuccessResponse) && !(obj instanceof ExceptionResponse))
sb.append("</" + obj.getResponseName() + ">");
}
private static void serializeResponseObjFieldsXML(StringBuilder sb, ResponseObject obj) {
boolean isAsync = false;
if (obj instanceof AsyncJobResponse)
isAsync = true;
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & Modifier.TRANSIENT) != 0) {
@ -133,7 +140,13 @@ public class ApiResponseSerializer {
if (fieldValue != null) {
if (fieldValue instanceof ResponseObject) {
ResponseObject subObj = (ResponseObject)fieldValue;
if (isAsync) {
sb.append("<jobresult>");
}
serializeResponseObjXML(sb, subObj);
if (isAsync) {
sb.append("</jobresult>");
}
} else if (fieldValue instanceof Date) {
sb.append("<" + serializedName.value() + ">" + BaseCmd.getDateString((Date)fieldValue) + "</" + serializedName.value() + ">");
} else {