mirror of https://github.com/apache/cloudstack.git
Merge branch '2.1.refactor' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.1.refactor
Conflicts: server/src/com/cloud/server/ManagementServerImpl.java
This commit is contained in:
commit
ea415e65bb
|
|
@ -18,32 +18,20 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.AsyncJobResponse;
|
||||
import com.cloud.async.AsyncJobResult;
|
||||
import com.cloud.async.executor.IngressRuleResultObject;
|
||||
import com.cloud.async.executor.NetworkGroupResultObject;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class QueryAsyncJobResultCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(QueryAsyncJobResultCmd.class.getName());
|
||||
|
||||
private static final String s_name = "queryasyncjobresultresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.JOB_ID, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -64,57 +52,62 @@ public class QueryAsyncJobResultCmd extends BaseCmd {
|
|||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long jobId = (Long)params.get(BaseCmd.Properties.JOB_ID.getName());
|
||||
AsyncJobResult result;
|
||||
|
||||
try {
|
||||
result = getManagementServer().queryAsyncJobResult(jobId);
|
||||
} catch (PermissionDeniedException e) {
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Permission denied");
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), jobId));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_STATUS.getName(), Integer.valueOf(result.getJobStatus())));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_PROCESS_STATUS.getName(), Integer.valueOf(result.getProcessStatus())));
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_RESULT_CODE.getName(), Integer.valueOf(result.getResultCode())));
|
||||
|
||||
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 {
|
||||
@Override
|
||||
public String getResponse() {
|
||||
AsyncJobResult result = (AsyncJobResult)getResponseObject();
|
||||
|
||||
AsyncJobResponse response = new AsyncJobResponse();
|
||||
response.setId(result.getJobId());
|
||||
response.setJobStatus(result.getJobStatus());
|
||||
response.setJobProcStatus(result.getProcessStatus());
|
||||
response.setJobResultCode(result.getResultCode());
|
||||
response.setJobResult(result.getResult());
|
||||
|
||||
Object resultObject = result.getResultObject();
|
||||
if (resultObject != null) {
|
||||
Class<?> clz = resultObject.getClass();
|
||||
if(clz.isPrimitive() || clz.getSuperclass() == Number.class || clz == String.class || clz == Date.class) {
|
||||
response.setJobResultType("text");
|
||||
} else {
|
||||
response.setJobResultType("object");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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 } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValues;
|
||||
}
|
||||
}
|
||||
returnValues.add(new Pair<String, Object>(result.getCmdOriginator(), new Object[] { resultValues } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return SerializerHelper.toSerializedString(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()));
|
||||
|
|
@ -152,5 +145,6 @@ public class QueryAsyncJobResultCmd extends BaseCmd {
|
|||
resultValues.add(new Pair<String, Object>("ingressrule", ingressDataArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ public class AsyncJobResponse implements ResponseObject {
|
|||
@Param(name="jobresultcode")
|
||||
private Integer jobResultCode;
|
||||
|
||||
@Param(name="jobresulttype")
|
||||
private String jobResultType;
|
||||
|
||||
@Param(name="jobresult")
|
||||
private String jobResult;
|
||||
|
||||
|
|
@ -112,6 +115,14 @@ public class AsyncJobResponse implements ResponseObject {
|
|||
this.jobResultCode = jobResultCode;
|
||||
}
|
||||
|
||||
public String getJobResultType() {
|
||||
return jobResultType;
|
||||
}
|
||||
|
||||
public void setJobResultType(String jobResultType) {
|
||||
this.jobResultType = jobResultType;
|
||||
}
|
||||
|
||||
public String getJobResult() {
|
||||
return jobResult;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ import com.cloud.api.commands.ListVolumesCmd;
|
|||
import com.cloud.api.commands.ListZonesByCmd;
|
||||
import com.cloud.api.commands.LockAccountCmd;
|
||||
import com.cloud.api.commands.LockUserCmd;
|
||||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.commands.RebootSystemVmCmd;
|
||||
import com.cloud.api.commands.RegisterCmd;
|
||||
import com.cloud.api.commands.RemovePortForwardingServiceCmd;
|
||||
|
|
@ -1604,6 +1605,15 @@ public interface ManagementServer {
|
|||
* @return async-call result object
|
||||
*/
|
||||
AsyncJobResult queryAsyncJobResult(long jobId) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Queries for the status or final result of an async job.
|
||||
* @param cmd the command that specifies the job id
|
||||
* @return an async-call result object
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd) throws PermissionDeniedException;
|
||||
|
||||
AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId);
|
||||
AsyncJobVO findAsyncJobById(long jobId);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
|
@ -103,6 +102,7 @@ import com.cloud.api.commands.ListVolumesCmd;
|
|||
import com.cloud.api.commands.ListZonesByCmd;
|
||||
import com.cloud.api.commands.LockAccountCmd;
|
||||
import com.cloud.api.commands.LockUserCmd;
|
||||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.commands.RebootSystemVmCmd;
|
||||
import com.cloud.api.commands.RegisterCmd;
|
||||
import com.cloud.api.commands.RemovePortForwardingServiceCmd;
|
||||
|
|
@ -123,7 +123,6 @@ import com.cloud.async.AsyncJobResult;
|
|||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.async.dao.AsyncJobDao;
|
||||
import com.cloud.async.executor.CreateOrUpdateRuleParam;
|
||||
import com.cloud.async.executor.DeleteDomainParam;
|
||||
import com.cloud.async.executor.DeployVMParam;
|
||||
import com.cloud.async.executor.NetworkGroupIngressParam;
|
||||
|
|
@ -7181,6 +7180,11 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return _diskOfferingDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd) throws PermissionDeniedException {
|
||||
return queryAsyncJobResult(cmd.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncJobResult queryAsyncJobResult(long jobId) throws PermissionDeniedException {
|
||||
AsyncJobVO job = _asyncMgr.getAsyncJob(jobId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue