bug 7063: AsyncJobResult should now return the correct success and error tags upon the completion of a async job. It should now follow either the format ... jobresult.success or jobresult.errorcode and jobresult.errortext

- Fixed a lot of other Async related packaging issues.  It's not all done but will continue to refactor this later.
This commit is contained in:
will 2010-11-05 17:29:47 -07:00
parent df8222ef31
commit 05ab3bf673
16 changed files with 245 additions and 254 deletions

View File

@ -1,118 +0,0 @@
package com.cloud.api;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import org.apache.log4j.Logger;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.annotations.SerializedName;
public class ResponseObjectTypeAdapter implements JsonSerializer<ResponseObject> {
private static final Logger s_logger = Logger.getLogger(ResponseObjectTypeAdapter.class.getName());
private static final GsonBuilder s_gBuilder;
static {
s_gBuilder = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT);
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
}
@Override
public JsonElement serialize(ResponseObject responseObj, Type typeOfResponseObj, JsonSerializationContext ctx) {
JsonObject obj = new JsonObject();
// Get the declared fields from the response obj, create a new JSON Object, add props to it.
// Once that object is done, create a new JSON Object with the response name and the JSON Obj as the name/value pair. Return that as the serialized element.
Field[] fields = responseObj.getClass().getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & Modifier.TRANSIENT) != 0) {
continue; // skip transient fields
}
SerializedName serializedName = field.getAnnotation(SerializedName.class);
if (serializedName == null) {
continue; // skip fields w/o serialized name
}
String propName = field.getName();
Method method = getGetMethod(responseObj, propName);
if (method != null) {
try {
Object fieldValue = method.invoke(responseObj);
if (fieldValue != null) {
if (fieldValue instanceof ResponseObject) {
ResponseObject subObj = (ResponseObject)fieldValue;
obj.add(serializedName.value(), serialize(subObj, subObj.getClass(), ctx));
} else {
if (fieldValue instanceof Number) {
obj.addProperty(serializedName.value(), (Number)fieldValue);
} else if (fieldValue instanceof Character) {
obj.addProperty(serializedName.value(), (Character)fieldValue);
} else if (fieldValue instanceof Boolean) {
obj.addProperty(serializedName.value(), (Boolean)fieldValue);
} else {
obj.addProperty(serializedName.value(), fieldValue.toString());
}
}
}
} catch (IllegalArgumentException e) {
s_logger.error("Illegal argument exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (IllegalAccessException e) {
s_logger.error("Illegal access exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (InvocationTargetException e) {
s_logger.error("Invocation target exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
}
}
}
JsonObject response = new JsonObject();
response.add(responseObj.getResponseName(), obj);
return response;
}
private static Method getGetMethod(Object o, String propName) {
Method method = null;
String methodName = getGetMethodName("get", propName);
try {
method = o.getClass().getMethod(methodName);
} catch (SecurityException e1) {
s_logger.error("Security exception in getting ResponseObject " + o.getClass().getName() + " get method for property: " + propName);
} catch (NoSuchMethodException e1) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("ResponseObject " + o.getClass().getName() + " does not have " + methodName + "() method for property: " + propName + ", will check is-prefixed method to see if it is boolean property");
}
}
if( method != null)
return method;
methodName = getGetMethodName("is", propName);
try {
method = o.getClass().getMethod(methodName);
} catch (SecurityException e1) {
s_logger.error("Security exception in getting ResponseObject " + o.getClass().getName() + " get method for property: " + propName);
} catch (NoSuchMethodException e1) {
s_logger.warn("ResponseObject " + o.getClass().getName() + " does not have " + methodName + "() method for property: " + propName);
}
return method;
}
private static String getGetMethodName(String prefix, String fieldName) {
StringBuffer sb = new StringBuffer(prefix);
if(fieldName.length() >= prefix.length() && fieldName.substring(0, prefix.length()).equals(prefix)) {
return fieldName;
} else {
sb.append(fieldName.substring(0, 1).toUpperCase());
sb.append(fieldName.substring(1));
}
return sb.toString();
}
}

View File

@ -25,8 +25,6 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.transport.ArrayTypeAdaptor;
import com.cloud.agent.transport.VolListTypeAdaptor;
import com.cloud.api.ResponseObject;
import com.cloud.api.ResponseObjectTypeAdapter;
import com.cloud.storage.VolumeVO;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
@ -40,7 +38,6 @@ public class GsonHelper {
s_gBuilder.registerTypeAdapter(Answer[].class, new ArrayTypeAdaptor<Answer>());
Type listType = new TypeToken<List<VolumeVO>>() {}.getType();
s_gBuilder.registerTypeAdapter(listType, new VolListTypeAdaptor());
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
}
public static GsonBuilder getBuilder() {

View File

@ -18,17 +18,16 @@
package com.cloud.serializer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ResponseObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.utils.DateUtil;
import com.cloud.utils.Pair;
import com.google.gson.Gson;
@ -44,12 +43,7 @@ public class SerializerHelper {
if(result != null) {
Class<?> clz = result.getClass();
Gson gson = GsonHelper.getBuilder().create();
if (result instanceof ResponseObject) {
return clz.getName() + token + ((ResponseObject)result).getResponseName() + token + gson.toJson(result);
} else {
return clz.getName() + token + gson.toJson(result);
}
return clz.getName() + token + gson.toJson(result);
}
return null;
}
@ -83,9 +77,6 @@ public class SerializerHelper {
Gson gson = GsonHelper.getBuilder().create();
Object obj = gson.fromJson(content, clz);
if (nameField != null) {
((ResponseObject)obj).setResponseName(nameField);
}
return obj;
}
return null;

View File

@ -25,16 +25,12 @@ import org.apache.log4j.Logger;
import junit.framework.Assert;
import com.cloud.async.AsyncJobResult;
import com.cloud.async.AsyncJobVO;
import com.cloud.async.dao.AsyncJobDao;
import com.cloud.async.dao.AsyncJobDaoImpl;
import com.cloud.maid.StackMaid;
import com.cloud.maid.StackMaidVO;
import com.cloud.maid.dao.StackMaidDao;
import com.cloud.maid.dao.StackMaidDaoImpl;
import com.cloud.serializer.Param;
import com.cloud.serializer.SerializerHelper;
import com.cloud.utils.ActionDelegate;
import com.cloud.utils.Pair;
import com.cloud.utils.db.Transaction;

View File

@ -0,0 +1,16 @@
package com.cloud.api;
import com.google.gson.GsonBuilder;
public class ApiGsonHelper {
private static final GsonBuilder s_gBuilder;
static {
s_gBuilder = new GsonBuilder();
s_gBuilder.setVersion(1.3);
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
}
public static GsonBuilder getBuilder() {
return s_gBuilder;
}
}

View File

@ -0,0 +1,66 @@
package com.cloud.api;
import org.apache.log4j.Logger;
import com.cloud.serializer.GsonHelper;
import com.google.gson.Gson;
public class ApiSerializerHelper {
public static final Logger s_logger = Logger.getLogger(ApiSerializerHelper.class.getName());
public static String token = "/";
public static String toSerializedStringOld(Object result) {
if(result != null) {
Class<?> clz = result.getClass();
Gson gson = ApiGsonHelper.getBuilder().create();
if (result instanceof ResponseObject) {
return clz.getName() + token + ((ResponseObject)result).getResponseName() + token + gson.toJson(result);
} else {
return clz.getName() + token + gson.toJson(result);
}
}
return null;
}
public static Object fromSerializedString(String result) {
try {
if(result != null && !result.isEmpty()) {
String[] serializedParts = result.split(token);
if (serializedParts.length < 2) {
return null;
}
String clzName = serializedParts[0];
String nameField = null;
String content = null;
if (serializedParts.length == 2) {
content = serializedParts[1];
} else {
nameField = serializedParts[1];
int index = result.indexOf(token + nameField + token);
content = result.substring(index + nameField.length() + 2);
}
Class<?> clz;
try {
clz = Class.forName(clzName);
} catch (ClassNotFoundException e) {
return null;
}
Gson gson = ApiGsonHelper.getBuilder().create();
Object obj = gson.fromJson(content, clz);
if (nameField != null) {
((ResponseObject)obj).setResponseName(nameField);
}
return obj;
}
return null;
} catch(RuntimeException e) {
s_logger.error("Caught runtime exception when doing GSON deserialization on: " + result);
throw e;
}
}
}

View File

@ -88,7 +88,6 @@ import com.cloud.domain.DomainVO;
import com.cloud.event.EventUtils;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.maid.StackMaid;
import com.cloud.serializer.GsonHelper;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.User;
@ -390,7 +389,7 @@ public class ApiServer implements HttpRequestHandler {
job.setAccountId(1L);
}
job.setCmd(cmdObj.getClass().getName());
job.setCmdInfo(GsonHelper.getBuilder().create().toJson(params));
job.setCmdInfo(ApiGsonHelper.getBuilder().create().toJson(params));
long jobId = _asyncMgr.submitAsyncJob(job);
if (objectId != null) {

View File

@ -0,0 +1,137 @@
package com.cloud.api;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import org.apache.log4j.Logger;
import com.cloud.api.response.ExceptionResponse;
import com.cloud.api.response.SuccessResponse;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.annotations.SerializedName;
public class ResponseObjectTypeAdapter implements JsonSerializer<ResponseObject> {
public static final Logger s_logger = Logger
.getLogger(ResponseObjectTypeAdapter.class.getName());
@Override
public JsonElement serialize(ResponseObject responseObj, Type typeOfResponseObj, JsonSerializationContext ctx) {
JsonObject obj = new JsonObject();
if (responseObj instanceof SuccessResponse) {
obj.addProperty("success", ((SuccessResponse)responseObj).getSuccess());
return obj;
} else if (responseObj instanceof ExceptionResponse) {
obj.addProperty("errorcode", ((ExceptionResponse)responseObj).getErrorCode());
obj.addProperty("errortext", ((ExceptionResponse)responseObj).getErrorText());
return obj;
} else {
// Get the declared fields from the response obj, create a new JSON Object, add props to it.
// Once that object is done, create a new JSON Object with the response name and the JSON Obj as the name/value pair. Return that as the serialized element.
Field[] fields = responseObj.getClass().getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & Modifier.TRANSIENT) != 0) {
continue; // skip transient fields
}
SerializedName serializedName = field.getAnnotation(SerializedName.class);
if (serializedName == null) {
continue; // skip fields w/o serialized name
}
String propName = field.getName();
Method method = getGetMethod(responseObj, propName);
if (method != null) {
try {
Object fieldValue = method.invoke(responseObj);
if (fieldValue != null) {
if (fieldValue instanceof ResponseObject) {
ResponseObject subObj = (ResponseObject)fieldValue;
obj.add(serializedName.value(), serialize(subObj, subObj.getClass(), ctx));
} else {
if (fieldValue instanceof Number) {
obj.addProperty(serializedName.value(), (Number)fieldValue);
} else if (fieldValue instanceof Character) {
obj.addProperty(serializedName.value(), (Character)fieldValue);
} else if (fieldValue instanceof Boolean) {
obj.addProperty(serializedName.value(), (Boolean)fieldValue);
} else {
obj.addProperty(serializedName.value(), fieldValue.toString());
}
}
}
} catch (IllegalArgumentException e) {
s_logger.error("Illegal argument exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (IllegalAccessException e) {
s_logger.error("Illegal access exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (InvocationTargetException e) {
s_logger.error("Invocation target exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
}
}
}
JsonObject response = new JsonObject();
response.add(responseObj.getResponseName(), obj);
return response;
}
}
private static Method getGetMethod(Object o, String propName) {
Method method = null;
String methodName = getGetMethodName("get", propName);
try {
method = o.getClass().getMethod(methodName);
} catch (SecurityException e1) {
s_logger.error("Security exception in getting ResponseObject "
+ o.getClass().getName() + " get method for property: "
+ propName);
} catch (NoSuchMethodException e1) {
if (s_logger.isTraceEnabled()) {
s_logger
.trace("ResponseObject "
+ o.getClass().getName()
+ " does not have "
+ methodName
+ "() method for property: "
+ propName
+ ", will check is-prefixed method to see if it is boolean property");
}
}
if (method != null)
return method;
methodName = getGetMethodName("is", propName);
try {
method = o.getClass().getMethod(methodName);
} catch (SecurityException e1) {
s_logger.error("Security exception in getting ResponseObject "
+ o.getClass().getName() + " get method for property: "
+ propName);
} catch (NoSuchMethodException e1) {
s_logger.warn("ResponseObject " + o.getClass().getName()
+ " does not have " + methodName
+ "() method for property: " + propName);
}
return method;
}
private static String getGetMethodName(String prefix, String fieldName) {
StringBuffer sb = new StringBuffer(prefix);
if (fieldName.length() >= prefix.length()
&& fieldName.substring(0, prefix.length()).equals(prefix)) {
return fieldName;
} else {
sb.append(fieldName.substring(0, 1).toUpperCase());
sb.append(fieldName.substring(1));
}
return sb.toString();
}
}

View File

@ -22,6 +22,7 @@ import java.util.Date;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -29,7 +30,6 @@ import com.cloud.api.ResponseObject;
import com.cloud.api.response.AsyncJobResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.async.AsyncJobVO;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="searchForAsyncJobs", description="Lists all pending asynchronous jobs for the account.")
public class ListAsyncJobsCmd extends BaseListCmd {
@ -89,7 +89,7 @@ public class ListAsyncJobsCmd extends BaseListCmd {
jobResponse.setJobInstanceId(job.getInstanceId());
jobResponse.setJobInstanceType(job.getInstanceType());
jobResponse.setJobProcStatus(job.getProcessStatus());
jobResponse.setJobResult((ResponseObject)SerializerHelper.fromSerializedString(job.getResult()));
jobResponse.setJobResult((ResponseObject)ApiSerializerHelper.fromSerializedString(job.getResult()));
jobResponse.setJobResultCode(job.getResultCode());
jobResponse.setJobStatus(job.getStatus());
jobResponse.setUserId(job.getUserId());

View File

@ -23,13 +23,13 @@ import java.util.Date;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ResponseObject;
import com.cloud.api.response.AsyncJobResponse;
import com.cloud.async.AsyncJobResult;
import com.cloud.serializer.SerializerHelper;
@Implementation(method="queryAsyncJobResult", description="Retrieves the current status of asynchronous job.")
public class QueryAsyncJobResultCmd extends BaseCmd {
@ -70,7 +70,7 @@ public class QueryAsyncJobResultCmd extends BaseCmd {
response.setJobStatus(result.getJobStatus());
response.setJobProcStatus(result.getProcessStatus());
response.setJobResultCode(result.getResultCode());
response.setJobResult((ResponseObject)SerializerHelper.fromSerializedString(result.getResult()));
response.setJobResult((ResponseObject)ApiSerializerHelper.fromSerializedString(result.getResult()));
Object resultObject = result.getResultObject();
if (resultObject != null) {
@ -82,74 +82,7 @@ public class QueryAsyncJobResultCmd extends BaseCmd {
}
}
/*
Object resultObject = result.getResultObject();
if (resultObject != null) {
Class<?> clz = resultObject.getClass();
if(clz.isPrimitive() || clz.getSuperclass() == Number.class || clz == String.class || clz == Date.class) {
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_RESULT_TYPE.getName(), "text"));
SerializerHelper.appendPairList(returnValues, resultObject, BaseCmd.Properties.JOB_RESULT.getName());
} else {
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_RESULT_TYPE.getName(), "object"));
if(result.getCmdOriginator() != null && !result.getCmdOriginator().isEmpty()) {
List<Pair<String, Object>> resultValues = new ArrayList<Pair<String, Object>>();
if (resultObject instanceof NetworkGroupResultObject) {
serializeNetworkGroupResults(resultValues, (NetworkGroupResultObject)resultObject);
} else {
SerializerHelper.appendPairList(resultValues, resultObject, BaseCmd.Properties.JOB_RESULT.getName());
}
returnValues.add(new Pair<String, Object>(result.getCmdOriginator(), new Object[] { resultValues } ));
}
}
}
*/
response.setResponseName(getName());
return response;
}
// For now network groups are the only objects with nested objects inside, so we special case serialization to handle this one case.
// In the future, if a generic serialization that handles nested objects is implemented then this special case can be removed.
/*
private void serializeNetworkGroupResults(List<Pair<String, Object>> resultValues, NetworkGroupResultObject resultObject) {
if (resultObject != null) {
resultValues.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), resultObject.getId().toString()));
resultValues.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), resultObject.getName()));
resultValues.add(new Pair<String, Object>(BaseCmd.Properties.DESCRIPTION.getName(), resultObject.getDescription()));
resultValues.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), resultObject.getAccountName()));
resultValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), resultObject.getDomainId().toString()));
List<IngressRuleResultObject> ingressRules = resultObject.getIngressRules();
if ((ingressRules != null) && !ingressRules.isEmpty()) {
Object[] ingressDataArray = new Object[ingressRules.size()];
int j = 0;
for (IngressRuleResultObject ingressRule : ingressRules) {
List<Pair<String, Object>> ingressData = new ArrayList<Pair<String, Object>>();
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.RULE_ID.getName(), ingressRule.getId().toString()));
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.PROTOCOL.getName(), ingressRule.getProtocol()));
if ("icmp".equalsIgnoreCase(ingressRule.getProtocol())) {
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.ICMP_TYPE.getName(), Integer.valueOf(ingressRule.getStartPort()).toString()));
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.ICMP_CODE.getName(), Integer.valueOf(ingressRule.getEndPort()).toString()));
} else {
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.START_PORT.getName(), Integer.valueOf(ingressRule.getStartPort()).toString()));
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.END_PORT.getName(), Integer.valueOf(ingressRule.getEndPort()).toString()));
}
if (ingressRule.getAllowedNetworkGroup() != null) {
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_GROUP_NAME.getName(), ingressRule.getAllowedNetworkGroup()));
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), ingressRule.getAllowedNetGroupAcct()));
} else if (ingressRule.getAllowedSourceIpCidr() != null) {
ingressData.add(new Pair<String, Object>(BaseCmd.Properties.CIDR.getName(), ingressRule.getAllowedSourceIpCidr()));
}
ingressDataArray[j++] = ingressData;
}
resultValues.add(new Pair<String, Object>("ingressrule", ingressDataArray));
}
}
}
*/
}

View File

@ -10,9 +10,9 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiGsonHelper;
import com.cloud.api.BaseCmd;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.GsonHelper;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
@ -29,7 +29,7 @@ public class ApiResponseSerializer {
private static String toJSONSerializedString(ResponseObject result) {
if (result != null) {
Gson gson = GsonHelper.getBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Gson gson = ApiGsonHelper.getBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
StringBuilder sb = new StringBuilder();
sb.append("{ \"" + result.getResponseName() + "\" : ");
@ -47,33 +47,6 @@ public class ApiResponseSerializer {
} else {
sb.append("{ }");
}
/*
* 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("{ }");
// }
// }
} else {
String jsonStr = gson.toJson(result);
if ((jsonStr != null) && !"".equals(jsonStr)) {

View File

@ -35,6 +35,8 @@ import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import com.cloud.api.ApiDispatcher;
import com.cloud.api.ApiGsonHelper;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
@ -43,7 +45,6 @@ import com.cloud.async.dao.AsyncJobDao;
import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.maid.StackMaid;
import com.cloud.serializer.GsonHelper;
import com.cloud.serializer.SerializerHelper;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -154,7 +155,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager {
job.setInstanceId(null);
if (resultObject != null) {
job.setResult(SerializerHelper.toSerializedStringOld(resultObject));
job.setResult(ApiSerializerHelper.toSerializedStringOld(resultObject));
}
job.setLastUpdated(DateUtil.currentGMTTime());
@ -186,7 +187,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager {
job.setProcessStatus(processStatus);
if(resultObject != null)
job.setResult(SerializerHelper.toSerializedStringOld(resultObject));
job.setResult(ApiSerializerHelper.toSerializedStringOld(resultObject));
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
@ -340,7 +341,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager {
cmdObj.setJob(job);
Type mapType = new TypeToken<Map<String, String>>() {}.getType();
Gson gson = GsonHelper.getBuilder().create();
Gson gson = ApiGsonHelper.getBuilder().create();
Map<String, String> params = gson.fromJson(job.getCmdInfo(), mapType);
// whenever we deserialize, the UserContext needs to be updated

View File

@ -18,7 +18,7 @@
package com.cloud.async;
import com.cloud.serializer.SerializerHelper;
import com.cloud.api.ApiSerializerHelper;
public class AsyncJobResult {
public static final int STATUS_IN_PROGRESS = 0;
@ -89,11 +89,11 @@ public class AsyncJobResult {
}
public Object getResultObject() {
return SerializerHelper.fromSerializedString(result);
return ApiSerializerHelper.fromSerializedString(result);
}
public void setResultObject(Object result) {
this.result = SerializerHelper.toSerializedStringOld(result);
this.result = ApiSerializerHelper.toSerializedStringOld(result);
}
public String toString() {