bug 11626: return same fields in queryAsyncJobResult and listAsyncJobs API commands

status 11626: resolved fixed
This commit is contained in:
Alena Prokharchyk 2011-12-09 16:25:06 -08:00
parent 7ff1417cbb
commit 28913c791b
6 changed files with 46 additions and 84 deletions

BIN
.vmops.log.swp Normal file

Binary file not shown.

View File

@ -33,14 +33,12 @@ import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.SecurityGroupRuleResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.api.response.SecurityGroupRuleResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.security.SecurityRule;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.StringUtils;

View File

@ -22,9 +22,11 @@ import java.util.Date;
import com.cloud.api.ApiConstants;
import com.cloud.api.IdentityProxy;
import com.cloud.api.ResponseObject;
import com.cloud.async.AsyncJob;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class AsyncJobResponse extends BaseResponse {
@SerializedName("accountid") @Param(description="the account that executed the async command")
private IdentityProxy accountId = new IdentityProxy("account");
@ -59,103 +61,71 @@ public class AsyncJobResponse extends BaseResponse {
@SerializedName(ApiConstants.CREATED) @Param(description=" the created date of the job")
private Date created;
public Long getAccountId() {
return accountId.getValue();
}
public void setAccountId(Long accountId) {
this.accountId.setValue(accountId);
}
public Long getUserId() {
return userId.getValue();
}
public void setUserId(Long userId) {
this.userId.setValue(userId);
}
public String getCmd() {
return cmd;
}
public void setCmd(String cmd) {
this.cmd = cmd;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Integer getJobProcStatus() {
return jobProcStatus;
}
public void setJobProcStatus(Integer jobProcStatus) {
this.jobProcStatus = jobProcStatus;
}
public Integer getJobResultCode() {
return jobResultCode;
}
public void setJobResultCode(Integer jobResultCode) {
this.jobResultCode = jobResultCode;
}
public String getJobResultType() {
return jobResultType;
}
public void setJobResultType(String jobResultType) {
this.jobResultType = jobResultType;
}
public ResponseObject getJobResult() {
return jobResult;
}
public void setJobResult(ResponseObject jobResult) {
this.jobResult = jobResult;
}
public String getJobInstanceType() {
return jobInstanceType;
}
public void setJobInstanceType(String jobInstanceType) {
this.jobInstanceType = jobInstanceType;
if(jobInstanceType != null) {
if(jobInstanceType.equalsIgnoreCase("volume")) {
if(jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Volume.toString())) {
this.jobInstanceId.setTableName("volumes");
} else if(jobInstanceType.equalsIgnoreCase("template")) {
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Template.toString())) {
this.jobInstanceId.setTableName("vm_template");
} else if(jobInstanceType.equalsIgnoreCase("iso")) {
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Iso.toString())) {
this.jobInstanceId.setTableName("vm_template");
} else {
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.VirtualMachine.toString()) || jobInstanceType.equalsIgnoreCase(AsyncJob.Type.ConsoleProxy.toString()) || jobInstanceType.equalsIgnoreCase(AsyncJob.Type.SystemVm.toString()) || jobInstanceType.equalsIgnoreCase(AsyncJob.Type.DomainRouter.toString()) ) {
this.jobInstanceId.setTableName("vm_instance");
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Snapshot.toString())) {
this.jobInstanceId.setTableName("snapshots");
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Host.toString())) {
this.jobInstanceId.setTableName("host");
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.StoragePool.toString())) {
this.jobInstanceId.setTableName("storage_pool");
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.IpAddress.toString())) {
this.jobInstanceId.setTableName("user_ip_address");
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.SecurityGroup.toString())) {
this.jobInstanceId.setTableName("security_group");
} else if (!jobInstanceType.equalsIgnoreCase(AsyncJob.Type.None.toString())){
// TODO : when we hit here, we need to add instanceType -> UUID entity table mapping
assert(false);
}
}
}
public Long getJobInstanceId() {
return this.jobInstanceId.getValue();
}
public void setJobInstanceId(Long jobInstanceId) {
this.jobInstanceId.setValue(jobInstanceId);
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}

View File

@ -98,7 +98,6 @@ import com.cloud.api.response.VolumeResponse;
import com.cloud.api.response.VpnUsersResponse;
import com.cloud.api.response.ZoneResponse;
import com.cloud.async.AsyncJob;
import com.cloud.async.AsyncJobResult;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity;
@ -2169,20 +2168,35 @@ public class ApiResponseHelper implements ResponseGenerator {
public AsyncJobResponse createAsyncJobResponse(AsyncJob job) {
AsyncJobResponse jobResponse = new AsyncJobResponse();
jobResponse.setAccountId(job.getAccountId());
jobResponse.setUserId(job.getUserId());
jobResponse.setCmd(job.getCmd());
jobResponse.setCreated(job.getCreated());
jobResponse.setJobId(job.getId());
jobResponse.setJobStatus(job.getStatus());
jobResponse.setJobProcStatus(job.getProcessStatus());
if (job.getInstanceType() != null && job.getInstanceId() != null) {
jobResponse.setJobInstanceType(job.getInstanceType().toString());
jobResponse.setJobInstanceId(job.getInstanceId());
}
jobResponse.setJobProcStatus(job.getProcessStatus());
jobResponse.setJobResult((ResponseObject) ApiSerializerHelper.fromSerializedString(job.getResult()));
jobResponse.setJobResultCode(job.getResultCode());
jobResponse.setJobStatus(job.getStatus());
jobResponse.setUserId(job.getUserId());
boolean savedValue = SerializationContext.current().getUuidTranslation();
SerializationContext.current().setUuidTranslation(false);
jobResponse.setJobResult((ResponseObject) ApiSerializerHelper.fromSerializedString(job.getResult()));
SerializationContext.current().setUuidTranslation(savedValue);
Object resultObject = ApiSerializerHelper.fromSerializedString(job.getResult());
if (resultObject != null) {
Class<?> clz = resultObject.getClass();
if (clz.isPrimitive() || clz.getSuperclass() == Number.class || clz == String.class || clz == Date.class) {
jobResponse.setJobResultType("text");
} else {
jobResponse.setJobResultType("object");
}
}
jobResponse.setObjectName("asyncjobs");
return jobResponse;
}
@ -2459,30 +2473,8 @@ public class ApiResponseHelper implements ResponseGenerator {
@Override
public AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd) {
AsyncJobResult result = ApiDBUtils._asyncMgr.queryAsyncJobResult(cmd);
AsyncJobResponse response = new AsyncJobResponse();
response.setJobId(result.getJobId());
response.setJobStatus(result.getJobStatus());
response.setJobProcStatus(result.getProcessStatus());
response.setJobResultCode(result.getResultCode());
boolean savedValue = SerializationContext.current().getUuidTranslation();
SerializationContext.current().setUuidTranslation(false);
response.setJobResult((ResponseObject) ApiSerializerHelper.fromSerializedString(result.getResult()));
SerializationContext.current().setUuidTranslation(savedValue);
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");
}
}
return response;
AsyncJob result = ApiDBUtils._asyncMgr.queryAsyncJobResult(cmd);
return createAsyncJobResponse(result);
}
@Override

View File

@ -48,5 +48,5 @@ public interface AsyncJobManager extends Manager {
* @param cmd the command that specifies the job id
* @return an async-call result object
*/
public AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd);
public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd);
}

View File

@ -289,7 +289,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
}
@Override
public AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
Account caller = UserContext.current().getCaller();
AsyncJobVO job = _jobDao.findById(cmd.getId());
@ -310,7 +310,9 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
_accountMgr.checkAccess(caller, null, jobOwner);
}
return queryAsyncJobResult(cmd.getId());
//poll the job
queryAsyncJobResult(cmd.getId());
return _jobDao.findById(cmd.getId());
}
@Override @DB