use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTest method createSnapshotInDb.
private SnapshotVO createSnapshotInDb(VolumeInfo volume) {
Snapshot.Type snapshotType = Snapshot.Type.MANUAL;
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), 2, 1, volume.getId(), 1L, UUID.randomUUID().toString(), (short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), 1L, 100L, HypervisorType.XenServer, LocationType.PRIMARY);
return this.snapshotDao.persist(snapshotVO);
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTest method createVolumeFromSnapshot.
@Test
public void createVolumeFromSnapshot() throws InterruptedException, ExecutionException {
VolumeInfo vol = createCopyBaseImage();
SnapshotVO snapshotVO = createSnapshotInDb(vol);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
boolean result = false;
SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy != null) {
snapshot = snapshotStrategy.takeSnapshot(snapshot);
result = true;
}
AssertJUnit.assertTrue(result);
VolumeVO volVO = createVolume(vol.getTemplateId(), vol.getPoolId());
VolumeInfo newVol = this.volFactory.getVolume(volVO.getId());
AsyncCallFuture<VolumeApiResult> volFuture = this.volumeService.createVolumeFromSnapshot(newVol, newVol.getDataStore(), snapshot);
VolumeApiResult apiResult = volFuture.get();
Assert.assertTrue(apiResult.isSuccess());
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTest method deleteSnapshot.
@Test
public void deleteSnapshot() throws InterruptedException, ExecutionException {
VolumeInfo vol = createCopyBaseImage();
SnapshotVO snapshotVO = createSnapshotInDb(vol);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
SnapshotInfo newSnapshot = null;
SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy != null) {
newSnapshot = snapshotStrategy.takeSnapshot(snapshot);
}
AssertJUnit.assertNotNull(newSnapshot);
// create another snapshot
for (SnapshotStrategy strategy : this.snapshotStrategies) {
if (strategy.canHandle(snapshot, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) {
strategy.deleteSnapshot(newSnapshot.getId());
}
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTest method createTemplateFromSnapshot.
@Test
public void createTemplateFromSnapshot() throws InterruptedException, ExecutionException {
VolumeInfo vol = createCopyBaseImage();
SnapshotVO snapshotVO = createSnapshotInDb(vol);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
boolean result = false;
SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy != null) {
snapshot = snapshotStrategy.takeSnapshot(snapshot);
result = true;
}
AssertJUnit.assertTrue(result);
LocalHostEndpoint ep = new LocalHostEndpoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
try {
VMTemplateVO templateVO = createTemplateInDb();
TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image);
DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId);
AsyncCallFuture<TemplateApiResult> templateFuture = this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore);
TemplateApiResult apiResult = templateFuture.get();
Assert.assertTrue(apiResult.isSuccess());
} finally {
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp);
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotTestWithFakeData method createSnapshotInDb.
private SnapshotVO createSnapshotInDb() {
Snapshot.Type snapshotType = Snapshot.Type.RECURRING;
SnapshotVO snapshotVO = new SnapshotVO(dcId, 2, 1, 1L, 1L, UUID.randomUUID().toString(), (short) snapshotType.ordinal(), snapshotType.name(), 100, 1L, 100L, Hypervisor.HypervisorType.XenServer, LocationType.PRIMARY);
return snapshotDao.persist(snapshotVO);
}
Aggregations