mirror of https://github.com/apache/cloudstack.git
bug 4286: Making extractIsoCmd and extractTemplateCmd async
This commit is contained in:
parent
ab1a6b8656
commit
fceb9378ca
|
|
@ -0,0 +1,165 @@
|
|||
package com.cloud.async.executor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.cloud.async.AsyncInstanceCreateStatus;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.storage.Volume.VolumeType;
|
||||
import com.cloud.storage.upload.UploadState;
|
||||
|
||||
public class ExtractJobResultObject {
|
||||
|
||||
public ExtractJobResultObject(Long accountId, String typeName, UploadState currState, int i, Long uploadId){
|
||||
this.accountId = accountId;
|
||||
this.name = typeName;
|
||||
this.state = currState.toString();
|
||||
}
|
||||
|
||||
public ExtractJobResultObject(){
|
||||
}
|
||||
|
||||
@Param(name="id")
|
||||
private long id;
|
||||
|
||||
@Param(name="name")
|
||||
private String name;
|
||||
|
||||
@Param(name="host_id")
|
||||
private Long hostId;
|
||||
|
||||
@Param(name="uploadPercentage")
|
||||
private int uploadPercent;
|
||||
|
||||
@Param(name="uploadStatus")
|
||||
private String uploadStatus;
|
||||
|
||||
@Param(name="accountid")
|
||||
long accountId;
|
||||
|
||||
@Param(name="account")
|
||||
private String accountName;
|
||||
|
||||
@Param(name="result_string")
|
||||
String result_string;
|
||||
|
||||
public int getUploadPercent() {
|
||||
return uploadPercent;
|
||||
}
|
||||
|
||||
public void setUploadPercent(int i) {
|
||||
this.uploadPercent = i;
|
||||
}
|
||||
|
||||
public String getUploadStatus() {
|
||||
return uploadStatus;
|
||||
}
|
||||
|
||||
public void setUploadStatus(String uploadStatus) {
|
||||
this.uploadStatus = uploadStatus;
|
||||
}
|
||||
|
||||
public String getResult_string() {
|
||||
return result_string;
|
||||
}
|
||||
|
||||
public void setResult_string(String resultString) {
|
||||
result_string = resultString;
|
||||
}
|
||||
|
||||
@Param(name="created")
|
||||
private Date createdDate;
|
||||
|
||||
@Param(name="state")
|
||||
private String state;
|
||||
|
||||
@Param(name="storagetype")
|
||||
String storageType;
|
||||
|
||||
@Param(name="storage")
|
||||
private String storage;
|
||||
|
||||
@Param(name="zoneid")
|
||||
private Long zoneId;
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setZoneId(Long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
public void setZoneName(String zoneName) {
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
@Param(name="zonename")
|
||||
private String zoneName;
|
||||
|
||||
private long size;
|
||||
|
||||
public String getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(String storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public String getAccountName() {
|
||||
return accountName;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Date createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setState(String status) {
|
||||
this.state = status;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setStorageType (String storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public String getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.cloud.async.executor;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobResult;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.serializer.GsonHelper;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ExtractTemplateExecutor extends BaseAsyncJobExecutor {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(ExtractTemplateExecutor.class.getName());
|
||||
@Override
|
||||
public boolean execute() {
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
AsyncJobManager asyncMgr = getAsyncJobMgr();
|
||||
AsyncJobVO job = getJob();
|
||||
|
||||
ExtractTemplateParam param = gson.fromJson(job.getCmdInfo(), ExtractTemplateParam.class);
|
||||
ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
|
||||
|
||||
try {
|
||||
s_logger.warn("nitin extract template");
|
||||
managementServer.extractTemplate(param.getUrl(), param.getTemplateId(), param.getZoneId(), param.getEventId(), getJob().getId());
|
||||
//asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0, null);
|
||||
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to extract template: " + e.getMessage(), e);
|
||||
asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.cloud.async.executor;
|
||||
|
||||
public class ExtractTemplateParam {
|
||||
|
||||
private long userId;
|
||||
private long templateId;
|
||||
private Long zoneId;
|
||||
private long eventId;
|
||||
private String url;
|
||||
|
||||
public ExtractTemplateParam() {
|
||||
}
|
||||
|
||||
public ExtractTemplateParam(long userId, long templateId, Long zoneId, long eventId, String url) {
|
||||
this.userId = userId;
|
||||
this.templateId = templateId;
|
||||
this.zoneId = zoneId;
|
||||
this.eventId = eventId;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public long getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setEventId(long eventId) {
|
||||
this.eventId = eventId;
|
||||
}
|
||||
|
||||
public long getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue