use of com.cloud.engine.subsystem.api.storage.SnapshotResult in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method revertSnapshotCallback.
protected Void revertSnapshotCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, final RevertSnapshotContext<CommandResult> context) {
final CommandResult result = callback.getResult();
final AsyncCallFuture<SnapshotResult> future = context.future;
SnapshotResult res = null;
try {
if (result.isFailed()) {
s_logger.debug("revert snapshot failed" + result.getResult());
res = new SnapshotResult(context.snapshot, null);
res.setResult(result.getResult());
} else {
res = new SnapshotResult(context.snapshot, null);
}
} catch (final Exception e) {
s_logger.debug("Failed to in revertSnapshotCallback", e);
res.setResult(e.toString());
}
future.complete(res);
return null;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotResult in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method syncToRegionStoreAsync.
private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(final SnapshotInfo snapshot, final DataStore store) {
final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
// no need to create entry on snapshot_store_ref here, since entries are already created when updateCloudToUseObjectStore is invoked.
// But we need to set default install path so that sync can be done in the right s3 path
final SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store);
final String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId();
((SnapshotObject) snapshotOnStore).setPath(installPath);
final CopySnapshotContext<CommandResult> context = new CopySnapshotContext<>(null, snapshot, snapshotOnStore, future);
final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().syncSnapshotCallBack(null, null)).setContext(context);
motionSrv.copyAsync(snapshot, snapshotOnStore, caller);
return future;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotResult in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method backupSnapshot.
@Override
public SnapshotInfo backupSnapshot(final SnapshotInfo snapshot) {
final SnapshotObject snapObj = (SnapshotObject) snapshot;
final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
final SnapshotResult result = new SnapshotResult(snapshot, null);
try {
snapObj.processEvent(Snapshot.Event.BackupToSecondary);
final DataStore imageStore = findSnapshotImageStore(snapshot);
if (imageStore == null) {
throw new CloudRuntimeException("can not find an image stores");
}
final SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
final CopySnapshotContext<CommandResult> context = new CopySnapshotContext<>(null, snapshot, snapshotOnImageStore, future);
final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
} catch (final Exception e) {
s_logger.debug("Failed to copy snapshot", e);
result.setResult("Failed to copy snapshot:" + e.toString());
try {
snapObj.processEvent(Snapshot.Event.OperationFailed);
} catch (final NoTransitionException e1) {
s_logger.debug("Failed to change state: " + e1.toString());
}
future.complete(result);
}
try {
final SnapshotResult res = future.get();
if (res.isFailed()) {
throw new CloudRuntimeException(res.getResult());
}
final SnapshotInfo destSnapshot = res.getSnashot();
return destSnapshot;
} catch (final InterruptedException e) {
s_logger.debug("failed copy snapshot", e);
throw new CloudRuntimeException("Failed to copy snapshot", e);
} catch (final ExecutionException e) {
s_logger.debug("Failed to copy snapshot", e);
throw new CloudRuntimeException("Failed to copy snapshot", e);
}
}
Aggregations