use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromSnapshotCallback.
protected Void createVolumeFromSnapshotCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeInfo volume = (VolumeInfo) context.templateOnStore;
final SnapshotInfo snapshot = context.snapshot;
final VolumeApiResult apiResult = new VolumeApiResult(volume);
Event event = null;
if (result.isFailed()) {
apiResult.setResult(result.getResult());
event = Event.OperationFailed;
} else {
event = Event.OperationSuccessed;
}
try {
if (result.isSuccess()) {
volume.processEvent(event, result.getAnswer());
} else {
volume.processEvent(event);
}
snapshot.processEvent(event);
} catch (final Exception e) {
s_logger.debug("create volume from snapshot failed", e);
apiResult.setResult(e.toString());
}
final AsyncCallFuture<VolumeApiResult> future = context.future;
future.complete(apiResult);
return null;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class SnapshotDataFactoryImpl method listSnapshotOnCache.
@Override
public List<SnapshotInfo> listSnapshotOnCache(final long snapshotId) {
final List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
final List<SnapshotInfo> snapObjs = new ArrayList<>();
for (final SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
final long storeId = cacheSnap.getDataStoreId();
final DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
final SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
snapObjs.add(tmplObj);
}
return snapObjs;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method copySnapshotAsyncCallback.
protected Void copySnapshotAsyncCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
final CopyCommandResult result = callback.getResult();
final SnapshotInfo destSnapshot = context.destSnapshot;
final SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
final AsyncCallFuture<SnapshotResult> future = context.future;
SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
if (result.isFailed()) {
try {
destSnapshot.processEvent(Event.OperationFailed);
// if backup snapshot failed, mark srcSnapshot in snapshot_store_ref as failed also
srcSnapshot.processEvent(Event.DestroyRequested);
srcSnapshot.processEvent(Event.OperationSuccessed);
srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
_snapshotDao.remove(srcSnapshot.getId());
} catch (final NoTransitionException e) {
s_logger.debug("Failed to update state: " + e.toString());
}
snapResult.setResult(result.getResult());
future.complete(snapResult);
return null;
}
try {
final CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) result.getAnswer();
destSnapshot.processEvent(Event.OperationSuccessed, copyCmdAnswer);
srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer);
future.complete(snapResult);
} catch (final Exception e) {
s_logger.debug("Failed to update snapshot state", e);
snapResult.setResult(e.toString());
future.complete(snapResult);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method revertSnapshot.
@Override
public boolean revertSnapshot(final SnapshotInfo snapshot) {
final SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotOnPrimaryStore == null) {
throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools");
}
final PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
final RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<>(null, snapshot, future);
final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context);
((PrimaryDataStoreDriver) store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller);
SnapshotResult result = null;
try {
result = future.get();
if (result.isFailed()) {
throw new CloudRuntimeException(result.getResult());
}
return true;
} catch (final InterruptedException e) {
s_logger.debug("revert snapshot is failed: " + e.toString());
} catch (final ExecutionException e) {
s_logger.debug("revert snapshot is failed: " + e.toString());
}
return false;
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method syncSnapshotCallBack.
protected Void syncSnapshotCallBack(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
final CopyCommandResult result = callback.getResult();
final SnapshotInfo destSnapshot = context.destSnapshot;
final SnapshotResult res = new SnapshotResult(destSnapshot, null);
final AsyncCallFuture<SnapshotResult> future = context.future;
try {
if (result.isFailed()) {
res.setResult(result.getResult());
// no change to existing snapshot_store_ref, will try to re-sync later if other call triggers this sync operation
} else {
// this will update install path properly, next time it will not sync anymore.
destSnapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
}
future.complete(res);
} catch (final Exception e) {
s_logger.debug("Failed to process sync snapshot callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
Aggregations