bug 6969: return jobId/jobStatus for IpAddress and SecurityGroup as ids for these objects were introduced in 2.2.x

This commit is contained in:
alena 2011-02-18 17:06:43 -08:00
parent b5152e27ec
commit e4765fb32b
23 changed files with 212 additions and 57 deletions

View File

@ -102,10 +102,12 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
return _lbService.findById(id).getNetworkId();
}

View File

@ -29,6 +29,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.IPAddressResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
@ -161,11 +162,18 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
return getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.IpAddress;
}
}

View File

@ -34,6 +34,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.IngressRuleResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.network.security.IngressRule;
import com.cloud.user.Account;
@ -206,4 +207,14 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd {
}
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.SecurityGroup;
}
@Override
public Long getInstanceId() {
return getSecurityGroupId();
}
}

View File

@ -89,10 +89,12 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
return "canceling maintenance for host: " + getId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
@Override
public Long getInstanceId() {
return getId();
}

View File

@ -70,10 +70,12 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
return "primarystorage";
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.StoragePool;
}
@Override
public Long getInstanceId() {
return getId();
}

View File

@ -26,6 +26,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.IpAddress;
@ -96,10 +97,12 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
return ownerId;
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
IpAddress ip = getIpAddress(id);
return ip.getAssociatedWithNetworkId();
@ -114,4 +117,14 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
return ip;
}
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.IpAddress;
}
@Override
public Long getInstanceId() {
return getIpAddressId();
}
}

View File

@ -29,6 +29,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.IPAddressResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.async.AsyncJob;
import com.cloud.network.IpAddress;
@Implementation(description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
@ -123,5 +124,9 @@ public class ListPublicIpAddressesCmd extends BaseListCmd {
response.setResponses(ipAddrResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.IpAddress;
}
}

View File

@ -27,6 +27,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.async.AsyncJob;
import com.cloud.network.security.SecurityGroupRules;
@Implementation(description="Lists security groups", responseObject=SecurityGroupResponse.class)
@ -95,4 +96,9 @@ public class ListSecurityGroupsCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.SecurityGroup;
}
}

View File

@ -26,7 +26,6 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.VolumeResponse;
import com.cloud.async.AsyncJob;
@ -125,6 +124,7 @@ public class ListVolumesCmd extends BaseListCmd {
return s_name;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Volume;
}

View File

@ -86,10 +86,12 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
return "preparing host: " + getId() + " for maintenance";
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
@Override
public Long getInstanceId() {
return getId();
}

View File

@ -67,10 +67,12 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
return "primarystorage";
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.StoragePool;
}
@Override
public Long getInstanceId() {
return getId();
}

View File

@ -9,6 +9,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -100,4 +101,14 @@ public class RevokeSecurityGroupIngressCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to revoke security group ingress rule");
}
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.SecurityGroup;
}
@Override
public Long getInstanceId() {
return getId();
}
}

View File

@ -141,8 +141,29 @@ public class HostResponse extends BaseResponse {
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
private Integer jobStatus;
@Override
public Long getObjectId() {
return getId();
return getId();
}
@Override
public Long getJobId() {
return jobId;
}
@Override
public void setJobId(Long jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Long getId() {
@ -432,20 +453,4 @@ public class HostResponse extends BaseResponse {
public void setEvents(String events) {
this.events = events;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -81,6 +81,12 @@ public class IPAddressResponse extends BaseResponse {
@SerializedName(ApiConstants.STATE) @Param(description="State of the ip address. Can be: Allocatin, Allocated and Releasing")
private String state;
@SerializedName(ApiConstants.JOB_ID) @Param(description="shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the volume")
private Long jobId;
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
private Integer jobStatus;
public String getIpAddress() {
return ipAddress;
}
@ -232,4 +238,29 @@ public class IPAddressResponse extends BaseResponse {
public void setState(String state) {
this.state = state;
}
@Override
public Long getObjectId() {
return getId();
}
@Override
public Long getJobId() {
return jobId;
}
@Override
public void setJobId(Long jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@ -40,6 +41,12 @@ public class SecurityGroupResponse extends BaseResponse {
@SerializedName("domain") @Param(description="the domain name of the security group")
private String domainName;
@SerializedName(ApiConstants.JOB_ID) @Param(description="shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the volume")
private Long jobId;
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
private Integer jobStatus;
@SerializedName("ingressrule") @Param(description="the list of ingress rules associated with the security group", responseObject = IngressRuleResponse.class)
private List<IngressRuleResponse> ingressRules;
@ -99,4 +106,29 @@ public class SecurityGroupResponse extends BaseResponse {
public void setIngressRules(List<IngressRuleResponse> ingressRules) {
this.ingressRules = ingressRules;
}
@Override
public Long getObjectId() {
return getId();
}
@Override
public Long getJobId() {
return jobId;
}
@Override
public void setJobId(Long jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -20,7 +20,6 @@ package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ApiConstants;
import com.cloud.host.Status;
import com.cloud.serializer.Param;
import com.cloud.storage.StoragePoolStatus;
import com.google.gson.annotations.SerializedName;
@ -80,9 +79,30 @@ public class StoragePoolResponse extends BaseResponse {
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
private Integer jobStatus;
@Override
public Long getObjectId() {
return getId();
}
@Override
public Long getJobId() {
return jobId;
}
@Override
public void setJobId(Long jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Long getId() {
return id;
@ -212,19 +232,4 @@ public class StoragePoolResponse extends BaseResponse {
this.state = state;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
}

View File

@ -123,9 +123,30 @@ public class VolumeResponse extends BaseResponse {
@SerializedName("isextractable") @Param(description="true if the volume is extractable, false otherwise")
private Boolean extractable;
@Override
public Long getObjectId() {
return getId();
}
@Override
public Long getJobId() {
return jobId;
}
@Override
public void setJobId(Long jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Boolean getDestroyed() {
return destroyed;
@ -143,22 +164,6 @@ public class VolumeResponse extends BaseResponse {
this.id = id;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public String getName() {
return name;
}

View File

@ -31,7 +31,9 @@ public interface AsyncJob {
Iso,
SystemVm,
Host,
StoragePool
StoragePool,
IpAddress,
SecurityGroup,
}
Long getId();

View File

@ -445,7 +445,15 @@ public class ApiServer implements HttpRequestHandler {
private void buildAsyncListResponse(BaseListCmd command, Account account) {
List<ResponseObject> responses = ((ListResponse)command.getResponseObject()).getResponses();
if (responses != null && responses.size() > 0) {
List<? extends AsyncJob> jobs = _asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType(), account.getId());
List<? extends AsyncJob> jobs = null;
//list all jobs for ROOT admin
if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
jobs = _asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType(), null);
} else {
jobs = _asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType(), account.getId());
}
if (jobs.size() == 0) {
return;
}

View File

@ -31,7 +31,7 @@ public interface AsyncJobManager extends Manager {
public AsyncJobVO getAsyncJob(long jobId);
public AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId);
public List<? extends AsyncJob> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, long accountId);
public List<? extends AsyncJob> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId);
public long submitAsyncJob(AsyncJobVO job);
public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext);

View File

@ -106,7 +106,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
}
@Override
public List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, long accountId) {
public List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId) {
return _jobDao.findInstancePendingAsyncJobs(instanceType, accountId);
}

View File

@ -27,7 +27,7 @@ import com.cloud.utils.db.GenericDao;
public interface AsyncJobDao extends GenericDao<AsyncJobVO, Long> {
AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId);
List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, long accountId);
List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId);
List<AsyncJobVO> getExpiredJobs(Date cutTime, int limit);
void resetJobProcess(long msid);
}

View File

@ -87,10 +87,13 @@ public class AsyncJobDaoImpl extends GenericDaoBase<AsyncJobVO, Long> implements
return null;
}
public List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, long accountId) {
public List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId) {
SearchCriteria<AsyncJobVO> sc = pendingAsyncJobsSearch.create();
sc.setParameters("instanceType", instanceType);
sc.setParameters("accountId", accountId);
if (accountId != null) {
sc.setParameters("accountId", accountId);
}
sc.setParameters("status", AsyncJobResult.STATUS_IN_PROGRESS);
return listBy(sc);