use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class SnapshotServiceImpl method backupSnapshot.
@Override
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
SnapshotObject snapObj = (SnapshotObject) snapshot;
AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
SnapshotResult result = new SnapshotResult(snapshot, null);
Snapshot.State origState = snapObj.getState();
try {
snapObj.processEvent(Snapshot.Event.BackupToSecondary);
DataStore imageStore = findSnapshotImageStore(snapshot);
if (imageStore == null) {
throw new CloudRuntimeException("can not find an image stores");
}
SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnImageStore, future);
AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
} catch (Exception e) {
s_logger.debug("Failed to copy snapshot", e);
result.setResult("Failed to copy snapshot:" + e.toString());
try {
// This will ensure that the original snapshot does not get deleted
if (origState.equals(Snapshot.State.BackedUp)) {
snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
} else {
snapObj.processEvent(Snapshot.Event.OperationFailed);
}
} catch (NoTransitionException e1) {
s_logger.debug("Failed to change state: " + e1.toString());
}
future.complete(result);
}
try {
SnapshotResult res = future.get();
if (res.isFailed()) {
throw new CloudRuntimeException(res.getResult());
}
SnapshotInfo destSnapshot = res.getSnapshot();
return destSnapshot;
} catch (InterruptedException e) {
s_logger.debug("failed copy snapshot", e);
throw new CloudRuntimeException("Failed to copy snapshot", e);
} catch (ExecutionException e) {
s_logger.debug("Failed to copy snapshot", e);
throw new CloudRuntimeException("Failed to copy snapshot", e);
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CephSnapshotStrategyTest method configureAndVerifyCanHandle.
private void configureAndVerifyCanHandle(Date removed, boolean isSnapshotStoredOnRbdStoragePool) {
Snapshot snapshot = Mockito.mock(Snapshot.class);
SnapshotOperation[] snapshotOps = SnapshotOperation.values();
Mockito.when(snapshot.getVolumeId()).thenReturn(0l);
VolumeVO volumeVO = Mockito.mock(VolumeVO.class);
Mockito.when(volumeVO.getRemoved()).thenReturn(removed);
Mockito.when(volumeDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(volumeVO);
Mockito.lenient().doReturn(isSnapshotStoredOnRbdStoragePool).when(cephSnapshotStrategy).isSnapshotStoredOnRbdStoragePool(Mockito.any());
for (int i = 0; i < snapshotOps.length - 1; i++) {
StrategyPriority strategyPriority = cephSnapshotStrategy.canHandle(snapshot, snapshotOps[i]);
if (snapshotOps[i] == SnapshotOperation.REVERT && isSnapshotStoredOnRbdStoragePool) {
Assert.assertEquals(StrategyPriority.HIGHEST, strategyPriority);
} else {
Assert.assertEquals(StrategyPriority.CANT_HANDLE, strategyPriority);
}
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method canHandle.
@Override
public StrategyPriority canHandle(Snapshot snapshot, SnapshotOperation op) {
Snapshot.LocationType locationType = snapshot.getLocationType();
// If the snapshot exists on Secondary Storage, we can't delete it.
if (SnapshotOperation.DELETE.equals(op)) {
if (Snapshot.LocationType.SECONDARY.equals(locationType)) {
return StrategyPriority.CANT_HANDLE;
}
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
// If the snapshot exists on Secondary Storage, we can't delete it.
if (snapshotStore != null) {
return StrategyPriority.CANT_HANDLE;
}
snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore == null) {
return StrategyPriority.CANT_HANDLE;
}
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(snapshotStoragePoolId, DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
return storageSystemSupportsCapability ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE;
}
long volumeId = snapshot.getVolumeId();
VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
long volumeStoragePoolId = volumeVO.getPoolId();
if (SnapshotOperation.REVERT.equals(op)) {
boolean baseVolumeExists = volumeVO.getRemoved() == null;
if (baseVolumeExists) {
boolean acceptableFormat = isAcceptableRevertFormat(volumeVO);
if (acceptableFormat) {
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshot.getId());
if (usingBackendSnapshot) {
if (snapshotStore != null) {
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(snapshotStoragePoolId, DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString());
if (storageSystemSupportsCapability) {
return StrategyPriority.HIGHEST;
}
storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString());
if (storageSystemSupportsCapability) {
return StrategyPriority.HIGHEST;
}
}
} else {
if (snapshotStore != null) {
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
StoragePoolVO storagePoolVO = storagePoolDao.findById(snapshotStoragePoolId);
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
StoragePoolVO storagePoolVO = storagePoolDao.findById(volumeStoragePoolId);
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
}
}
return StrategyPriority.CANT_HANDLE;
}
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
return storageSystemSupportsCapability ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE;
}
Aggregations