use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.
the class SnapshotServiceImpl method copySnapshotAsyncCallback.
protected Void copySnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, CopySnapshotContext<CommandResult> context) {
CopyCommandResult result = callback.getResult();
SnapshotInfo destSnapshot = context.destSnapshot;
SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
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 (NoTransitionException e) {
s_logger.debug("Failed to update state: " + e.toString());
}
snapResult.setResult(result.getResult());
future.complete(snapResult);
return null;
}
try {
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 (Exception e) {
s_logger.debug("Failed to update snapshot state", e);
snapResult.setResult(e.toString());
future.complete(snapResult);
}
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.
the class SnapshotServiceImpl method syncSnapshotCallBack.
protected Void syncSnapshotCallBack(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, CopySnapshotContext<CommandResult> context) {
CopyCommandResult result = callback.getResult();
SnapshotInfo destSnapshot = context.destSnapshot;
SnapshotResult res = new SnapshotResult(destSnapshot, null);
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 (Exception e) {
s_logger.debug("Failed to process sync snapshot callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.
the class SnapshotServiceImpl method revertSnapshot.
@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
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");
}
PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future);
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 (InterruptedException e) {
s_logger.debug("revert snapshot is failed: " + e.toString());
} catch (ExecutionException e) {
s_logger.debug("revert snapshot is failed: " + e.toString());
}
return false;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.
the class SnapshotServiceImpl method findSnapshotImageStore.
// if a snapshot has parent snapshot, the new snapshot should be stored in
// the same store as its parent since
// we are taking delta snapshot
private DataStore findSnapshotImageStore(SnapshotInfo snapshot) {
Boolean fullSnapshot = true;
Object payload = snapshot.getPayload();
if (payload != null) {
fullSnapshot = (Boolean) payload;
}
if (fullSnapshot) {
return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
} else {
SnapshotInfo parentSnapshot = snapshot.getParent();
// Note that DataStore information in parentSnapshot is for primary
// data store here, we need to
// find the image store where the parent snapshot backup is located
SnapshotDataStoreVO parentSnapshotOnBackupStore = null;
if (parentSnapshot != null) {
parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
}
if (parentSnapshotOnBackupStore == null) {
return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
}
return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.
the class SnapshotServiceImpl method syncSnapshotToRegionStore.
// push one individual snapshots currently on cache store to region store if it is not there already
private void syncSnapshotToRegionStore(long snapshotId, DataStore store) {
// if snapshot is already on region wide object store, check if it is really downloaded there (by checking install_path). Sync snapshot to region
// wide store if it is not there physically.
SnapshotInfo snapOnStore = _snapshotFactory.getSnapshot(snapshotId, store);
if (snapOnStore == null) {
throw new CloudRuntimeException("Cannot find an entry in snapshot_store_ref for snapshot " + snapshotId + " on region store: " + store.getName());
}
if (snapOnStore.getPath() == null || snapOnStore.getPath().length() == 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("sync snapshot " + snapshotId + " from cache to object store...");
}
// snapshot is not on region store yet, sync to region store
SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId);
if (srcSnapshot == null) {
throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + " on cache store");
}
AsyncCallFuture<SnapshotResult> future = syncToRegionStoreAsync(srcSnapshot, store);
try {
SnapshotResult result = future.get();
if (result.isFailed()) {
throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName() + ":" + result.getResult());
}
// reduce reference count for template on cache, so it can recycled by schedule
_cacheMgr.releaseCacheObject(srcSnapshot);
} catch (Exception ex) {
throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName());
}
}
}
Aggregations