use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTestWithFakeData method testTakeSnapshotWithFailed.
// @Test
public void testTakeSnapshotWithFailed() throws URISyntaxException {
SnapshotVO snapshotVO = createSnapshotInDb();
DataStore store = null;
try {
store = createDataStore();
FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver) store.getDriver();
dataStoreDriver.makeTakeSnapshotSucceed(false);
SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
Assert.assertFalse(result.isSuccess());
SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
Assert.assertTrue(storeRef == null);
} finally {
snapshotDao.expunge(snapshotVO.getId());
if (store != null) {
primaryDataStoreDao.remove(store.getId());
}
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTestWithFakeData method testTakeSnapshot.
// @Test
public void testTakeSnapshot() throws URISyntaxException {
SnapshotVO snapshotVO = createSnapshotInDb();
DataStore store = createDataStore();
try {
SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
Assert.assertTrue(result.isSuccess());
SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
Assert.assertTrue(storeRef != null);
Assert.assertTrue(storeRef.getState() == ObjectInDataStoreStateMachine.State.Ready);
snapshotInfo = result.getSnapshot();
boolean deletResult = snapshotService.deleteSnapshot(snapshotInfo);
Assert.assertTrue(deletResult);
snapshotDataStoreDao.expunge(storeRef.getId());
} finally {
snapshotDao.expunge(snapshotVO.getId());
primaryDataStoreDao.remove(store.getId());
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleCreateManagedVolumeFromManagedSnapshot.
private void handleCreateManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
boolean useCloning = true;
try {
verifyFormat(snapshotInfo);
HostVO hostVO = getHost(snapshotInfo);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
boolean computeClusterSupportsVolumeClone = true;
if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(hostVO.getClusterId());
if (usingBackendSnapshot && !computeClusterSupportsVolumeClone) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
LOGGER.warn(noSupportForResignErrMsg);
throw new CloudRuntimeException(noSupportForResignErrMsg);
}
}
boolean canStorageSystemCreateVolumeFromVolume = canStorageSystemCreateVolumeFromVolume(snapshotInfo.getDataStore().getId());
useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsVolumeClone);
VolumeDetailVO volumeDetail = null;
if (useCloning) {
volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), false);
volumeDetail = volumeDetailsDao.persist(volumeDetail);
}
// at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
_volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
VolumeApiResult result = future.get();
if (volumeDetail != null) {
volumeDetailsDao.remove(volumeDetail.getId());
}
if (result.isFailed()) {
LOGGER.warn("Failed to create a volume: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
volumeInfo.processEvent(Event.MigrationRequested);
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType()) || HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
if (useCloning) {
Map<String, String> extraDetails = null;
if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
extraDetails = new HashMap<>();
String extraDetailsVmdk = getSnapshotProperty(snapshotInfo.getId(), DiskTO.VMDK);
extraDetails.put(DiskTO.VMDK, extraDetailsVmdk);
}
copyCmdAnswer = performResignature(volumeInfo, hostVO, extraDetails);
// If using VMware, have the host rescan its software HBA if dynamic discovery is in use.
if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
disconnectHostFromVolume(hostVO, volumeInfo.getPoolId(), volumeInfo.get_iScsiName());
}
} else {
// asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning
// even when we don't need those hosts to do this kind of copy work
hostVO = getHost(snapshotInfo.getDataCenterId(), snapshotInfo.getHypervisorType(), false);
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
}
verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
} else if (HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
VolumeObjectTO newVolume = new VolumeObjectTO();
newVolume.setSize(volumeInfo.getSize());
newVolume.setPath(volumeInfo.get_iScsiName());
newVolume.setFormat(volumeInfo.getFormat());
copyCmdAnswer = new CopyCmdAnswer(newVolume);
} else {
throw new CloudRuntimeException("Unsupported hypervisor type");
}
} catch (Exception ex) {
errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromManagedSnapshot': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
if (useCloning) {
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
}
if (copyCmdAnswer == null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotDataFactoryImpl method getSnapshot.
@Override
public SnapshotInfo getSnapshot(long snapshotId, DataStore store) {
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
return so;
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class DataMigrationUtility method getAllReadySnapshotsAndChains.
/**
* Returns parent snapshots and snapshots that do not have any children; snapshotChains comprises of the snapshot chain info
* for each parent snapshot and the cumulative size of the chain - this is done to ensure that all the snapshots in a chain
* are migrated to the same datastore
*/
protected List<DataObject> getAllReadySnapshotsAndChains(DataStore srcDataStore, Map<DataObject, Pair<List<SnapshotInfo>, Long>> snapshotChains) {
List<SnapshotInfo> files = new LinkedList<>();
List<SnapshotDataStoreVO> snapshots = snapshotDataStoreDao.listByStoreId(srcDataStore.getId(), DataStoreRole.Image);
for (SnapshotDataStoreVO snapshot : snapshots) {
SnapshotVO snapshotVO = snapshotDao.findById(snapshot.getSnapshotId());
if (snapshot.getState() == ObjectInDataStoreStateMachine.State.Ready && snapshotVO != null && snapshotVO.getHypervisorType() != Hypervisor.HypervisorType.Simulator && snapshot.getParentSnapshotId() == 0) {
SnapshotInfo snap = snapshotFactory.getSnapshot(snapshotVO.getSnapshotId(), DataStoreRole.Image);
if (snap != null) {
files.add(snap);
}
}
}
for (SnapshotInfo parent : files) {
List<SnapshotInfo> chain = new ArrayList<>();
chain.add(parent);
for (int i = 0; i < chain.size(); i++) {
SnapshotInfo child = chain.get(i);
List<SnapshotInfo> children = child.getChildren();
if (children != null) {
chain.addAll(children);
}
}
snapshotChains.put(parent, new Pair<List<SnapshotInfo>, Long>(chain, getTotalChainSize(chain)));
}
return (List<DataObject>) (List<?>) files;
}
Aggregations