use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class DataObjectManagerImpl method copyAsync.
@Override
public void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CreateCmdResult> callback) {
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
} catch (final NoTransitionException | ConcurrentOperationException e) {
s_logger.debug("failed to change state", e);
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (final Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
}
final CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to change state: " + e.toString());
callback.complete(res);
}
final CopyContext<CreateCmdResult> anotherCall = new CopyContext<>(callback, srcData, destData);
final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
motionSrv.copyAsync(srcData, destData, caller);
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromSnapshot.
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(final VolumeInfo volume, final DataStore store, final SnapshotInfo snapshot) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
try {
final DataObject volumeOnStore = store.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
snapshot.processEvent(Event.CopyingRequested);
final CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volume, store, volumeOnStore, future, snapshot);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context);
motionSrv.copyAsync(snapshot, volumeOnStore, caller);
} catch (final Exception e) {
s_logger.debug("create volume from snapshot failed", e);
final VolumeApiResult result = new VolumeApiResult(volume);
result.setResult(e.toString());
future.complete(result);
}
return future;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeCallBack.
protected Void copyVolumeCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
VolumeInfo srcVolume = context.srcVolume;
VolumeInfo destVolume = context.destVolume;
final CopyCommandResult result = callback.getResult();
final AsyncCallFuture<VolumeApiResult> future = context.future;
final VolumeApiResult res = new VolumeApiResult(destVolume);
try {
if (result.isFailed()) {
res.setResult(result.getResult());
destVolume.processEvent(Event.MigrationCopyFailed);
srcVolume.processEvent(Event.OperationFailed);
destroyVolume(destVolume.getId());
destVolume = volFactory.getVolume(destVolume.getId());
final AsyncCallFuture<VolumeApiResult> destroyFuture = expungeVolumeAsync(destVolume);
destroyFuture.get();
future.complete(res);
return null;
}
srcVolume.processEvent(Event.OperationSuccessed);
destVolume.processEvent(Event.MigrationCopySucceeded, result.getAnswer());
volDao.updateUuid(srcVolume.getId(), destVolume.getId());
try {
destroyVolume(srcVolume.getId());
srcVolume = volFactory.getVolume(srcVolume.getId());
AsyncCallFuture<VolumeApiResult> destroyFuture = expungeVolumeAsync(srcVolume);
// If volume destroy fails, this could be because of vdi is still in use state, so wait and retry.
if (destroyFuture.get().isFailed()) {
Thread.sleep(5 * 1000);
destroyFuture = expungeVolumeAsync(srcVolume);
destroyFuture.get();
}
future.complete(res);
} catch (final Exception e) {
s_logger.debug("failed to clean up volume on storage", e);
}
return null;
} catch (final Exception e) {
s_logger.debug("Failed to process copy volume callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method migrateVmWithVolumesCallBack.
protected Void migrateVmWithVolumesCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final MigrateVmWithVolumesContext<CommandResult> context) {
final Map<VolumeInfo, DataStore> volumeToPool = context.volumeToPool;
final CopyCommandResult result = callback.getResult();
final AsyncCallFuture<CommandResult> future = context.future;
final CommandResult res = new CommandResult();
try {
if (result.isFailed()) {
res.setResult(result.getResult());
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
final VolumeInfo volume = entry.getKey();
volume.processEvent(Event.OperationFailed);
}
future.complete(res);
} else {
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
final VolumeInfo volume = entry.getKey();
volume.processEvent(Event.OperationSuccessed);
}
future.complete(res);
}
} catch (final Exception e) {
s_logger.error("Failed to process copy volume callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeFromImageToPrimary.
protected AsyncCallFuture<VolumeApiResult> copyVolumeFromImageToPrimary(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);
destVolume.processEvent(Event.CopyingRequested);
srcVolume.processEvent(Event.CopyingRequested);
final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyVolumeFromImageToPrimaryCallback(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, caller);
return future;
} catch (final Exception e) {
s_logger.error("failed to copy volume from image store", e);
if (destVolume != null) {
destVolume.processEvent(Event.OperationFailed);
}
srcVolume.processEvent(Event.OperationFailed);
res.setResult(e.toString());
future.complete(res);
return future;
}
}
Aggregations