use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method migrateVolume.
@Override
public AsyncCallFuture<VolumeApiResult> migrateVolume(final VolumeInfo srcVolume, final DataStore destStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final VolumeApiResult res = new VolumeApiResult(srcVolume);
try {
if (!snapshotMgr.canOperateOnVolume(srcVolume)) {
s_logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now.");
res.setResult("Snapshots are being created on this volume. This volume cannot be migrated now.");
future.complete(res);
return future;
}
final VolumeInfo destVolume = volFactory.getVolume(srcVolume.getId(), destStore);
srcVolume.processEvent(Event.MigrationRequested);
final MigrateVolumeContext<VolumeApiResult> context = new MigrateVolumeContext<>(null, future, srcVolume, destVolume, destStore);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().migrateVolumeCallBack(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, caller);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume", e);
res.setResult(e.toString());
future.complete(res);
}
return future;
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method registerVolume.
@Override
public AsyncCallFuture<VolumeApiResult> registerVolume(final VolumeInfo volume, final DataStore store) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final DataObject volumeOnStore = store.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
try {
final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().registerVolumeCallback(null, null));
caller.setContext(context);
store.getDriver().createAsync(store, volumeOnStore, caller);
} catch (final CloudRuntimeException ex) {
// clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
if (volStoreVO != null) {
final VolumeInfo volObj = volFactory.getVolume(volume, store);
volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final VolumeApiResult res = new VolumeApiResult((VolumeObject) volumeOnStore);
res.setResult(ex.getMessage());
future.complete(res);
}
return future;
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeFromPrimaryToImage.
protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(final VolumeInfo srcVolume, final DataStore destStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final VolumeApiResult res = new VolumeApiResult(srcVolume);
VolumeInfo destVolume = null;
try {
destVolume = (VolumeInfo) destStore.create(srcVolume);
// this is just used for locking that src volume record in DB to avoid using lock
srcVolume.processEvent(Event.MigrationRequested);
destVolume.processEventOnly(Event.CreateOnlyRequested);
final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, caller);
return future;
} catch (final Exception e) {
s_logger.error("failed to copy volume to image store", e);
if (destVolume != null) {
destVolume.getDataStore().delete(destVolume);
}
// unlock source volume record
srcVolume.processEvent(Event.OperationFailed);
res.setResult(e.toString());
future.complete(res);
return future;
}
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeAsync.
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final DataObject volumeOnStore = dataStore.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
try {
final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
} catch (final CloudRuntimeException ex) {
// clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
if (volStoreVO != null) {
final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
volResult.setResult(ex.getMessage());
future.complete(volResult);
}
return future;
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method expungeVolumeAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(final VolumeInfo volume) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final 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
final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
if (volumeStore != null) {
if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
future.complete(result);
return future;
}
}
final VolumeVO vol = volDao.findById(volume.getId());
if (vol == null) {
s_logger.debug("Volume " + volume.getId() + " is not found");
future.complete(result);
return future;
}
final String volumePath = vol.getPath();
final Long poolId = vol.getPoolId();
if (poolId == null || volumePath == null || volumePath.trim().isEmpty()) {
// 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);
}
volDao.remove(vol.getId());
future.complete(result);
return future;
}
}
final 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);
}
final DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<>(null, vo, future);
final 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;
}
Aggregations