use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class VolumeServiceImpl method expungeVolumeAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
VolumeApiResult result = new VolumeApiResult(volume);
if (volume.getDataStore() == null) {
s_logger.info("Expunge volume with no data store specified");
if (canVolumeBeRemoved(volume.getId())) {
s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
volDao.remove(volume.getId());
}
future.complete(result);
return future;
}
// Find out if the volume is at state of download_in_progress on secondary storage
VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
if (volumeStore != null) {
if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
String msg = "Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.";
s_logger.debug(msg);
result.setSuccess(false);
result.setResult(msg);
future.complete(result);
return future;
}
}
VolumeVO vol = volDao.findById(volume.getId());
if (vol == null) {
s_logger.debug("Volume " + volume.getId() + " is not found");
future.complete(result);
return future;
}
if (!volumeExistsOnPrimary(vol)) {
// not created on primary store
if (volumeStore == null) {
// also not created on secondary store
if (s_logger.isDebugEnabled()) {
s_logger.debug("Marking volume that was never created as destroyed: " + vol);
}
VMTemplateVO template = templateDao.findById(vol.getTemplateId());
if (template != null && !template.isDeployAsIs()) {
volDao.remove(vol.getId());
future.complete(result);
return future;
}
}
}
VolumeObject vo = (VolumeObject) volume;
if (volume.getDataStore().getRole() == DataStoreRole.Image) {
// no need to change state in volumes table
volume.processEventOnly(Event.DestroyRequested);
} else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
volume.processEvent(Event.ExpungeRequested);
}
DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<VolumeApiResult>(null, vo, future);
AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
return future;
}
use of org.apache.cloudstack.storage.command.CommandResult 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();
snapshotMgr.cleanupSnapshotsByVolume(volume.getId());
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