use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.
the class VolumeServiceImpl method createVolumeFromBaseImageAsync.
@DB
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
DataObject volumeOnPrimaryStorage = pd.create(volume);
volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
caller.setContext(context);
motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
return;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.
the class VolumeServiceImpl method migrateVolumeCallBack.
protected Void migrateVolumeCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, MigrateVolumeContext<VolumeApiResult> context) {
VolumeInfo srcVolume = context.srcVolume;
CopyCommandResult result = callback.getResult();
AsyncCallFuture<VolumeApiResult> future = context.future;
VolumeApiResult res = new VolumeApiResult(srcVolume);
try {
if (result.isFailed()) {
res.setResult(result.getResult());
srcVolume.processEvent(Event.OperationFailed);
future.complete(res);
} else {
srcVolume.processEvent(Event.OperationSuccessed);
future.complete(res);
}
} catch (Exception e) {
s_logger.error("Failed to process migrate volume callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.
the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.
@DB
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
DataObject vo = context.vo;
DataObject tmplOnPrimary = context.templateOnStore;
CopyCommandResult result = callback.getResult();
VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
if (result.isSuccess()) {
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
} else {
vo.processEvent(Event.OperationFailed);
volResult.setResult(result.getResult());
// hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
// template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
Answer ans = result.getAnswer();
if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
if (tmplOnPrimary != null) {
s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
if (templatePoolRef != null) {
long templatePoolRefId = templatePoolRef.getId();
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
try {
if (templatePoolRef == null) {
s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
} else {
templatePoolRef.setTemplateSize(0);
templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
_tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
}
} finally {
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
}
}
}
}
}
AsyncCallFuture<VolumeApiResult> future = context.getFuture();
future.complete(volResult);
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.
the class VolumeServiceImpl method copyVolumeFromImageToPrimaryCallback.
protected Void copyVolumeFromImageToPrimaryCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CopyVolumeContext<VolumeApiResult> context) {
VolumeInfo srcVolume = context.srcVolume;
VolumeInfo destVolume = context.destVolume;
CopyCommandResult result = callback.getResult();
AsyncCallFuture<VolumeApiResult> future = context.future;
VolumeApiResult res = new VolumeApiResult(destVolume);
try {
if (result.isFailed()) {
destVolume.processEvent(Event.OperationFailed);
srcVolume.processEvent(Event.OperationFailed);
res.setResult(result.getResult());
future.complete(res);
return null;
}
srcVolume.processEvent(Event.OperationSuccessed);
destVolume.processEvent(Event.OperationSuccessed, result.getAnswer());
srcVolume.getDataStore().delete(srcVolume);
future.complete(res);
} catch (Exception e) {
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.
the class VolumeServiceImpl method migrateVmWithVolumesCallBack.
protected Void migrateVmWithVolumesCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, MigrateVmWithVolumesContext<CommandResult> context) {
Map<VolumeInfo, DataStore> volumeToPool = context.volumeToPool;
CopyCommandResult result = callback.getResult();
AsyncCallFuture<CommandResult> future = context.future;
CommandResult res = new CommandResult();
try {
if (result.isFailed()) {
res.setResult(result.getResult());
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volume = entry.getKey();
volume.processEvent(Event.OperationFailed);
}
future.complete(res);
} else {
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volume = entry.getKey();
volume.processEvent(Event.OperationSuccessed);
}
future.complete(res);
}
} catch (Exception e) {
s_logger.error("Failed to process copy volume callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
Aggregations