use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class XenserverSnapshotStrategy method takeSnapshot.
@Override
@DB
public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) {
Object payload = snapshot.getPayload();
if (payload != null) {
CreateSnapshotPayload createSnapshotPayload = (CreateSnapshotPayload) payload;
if (createSnapshotPayload.getQuiescevm()) {
throw new InvalidParameterValueException("can't handle quiescevm equal true for volume snapshot");
}
}
SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshot.getId());
if (snapshotVO == null) {
throw new CloudRuntimeException("Failed to get lock on snapshot:" + snapshot.getId());
}
try {
VolumeInfo volumeInfo = snapshot.getBaseVolume();
volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
SnapshotResult result = null;
try {
result = snapshotSvr.takeSnapshot(snapshot);
if (result.isFailed()) {
s_logger.debug("Failed to take snapshot: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
} finally {
if (result != null && result.isSuccess()) {
volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
} else {
volumeInfo.stateTransit(Volume.Event.OperationFailed);
}
}
snapshot = result.getSnapshot();
DataStore primaryStore = snapshot.getDataStore();
boolean backupFlag = Boolean.parseBoolean(configDao.getValue(Config.BackupSnapshotAfterTakingSnapshot.toString()));
SnapshotInfo backupedSnapshot;
if (backupFlag) {
backupedSnapshot = backupSnapshot(snapshot);
} else {
// Fake it to get the transitions to fire in the proper order
s_logger.debug("skipping backup of snapshot due to configuration " + Config.BackupSnapshotAfterTakingSnapshot.toString());
SnapshotObject snapObj = (SnapshotObject) snapshot;
try {
snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
} catch (NoTransitionException e) {
s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
throw new CloudRuntimeException(e.toString());
}
backupedSnapshot = snapshot;
}
try {
SnapshotInfo parent = snapshot.getParent();
if (backupedSnapshot != null && parent != null && primaryStore instanceof PrimaryDataStoreImpl) {
if (((PrimaryDataStoreImpl) primaryStore).getPoolType() != StoragePoolType.RBD) {
Long parentSnapshotId = parent.getId();
while (parentSnapshotId != null && parentSnapshotId != 0L) {
SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(), primaryStore.getId(), parentSnapshotId);
if (snapshotDataStoreVO != null) {
parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId();
snapshotStoreDao.remove(snapshotDataStoreVO.getId());
} else {
parentSnapshotId = null;
}
}
}
SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(), primaryStore.getId(), snapshot.getId());
if (snapshotDataStoreVO != null) {
snapshotDataStoreVO.setParentSnapshotId(0L);
snapshotStoreDao.update(snapshotDataStoreVO.getId(), snapshotDataStoreVO);
}
}
} catch (Exception e) {
s_logger.debug("Failed to clean up snapshots on primary storage", e);
}
return backupedSnapshot;
} finally {
if (snapshotVO != null) {
snapshotDao.releaseFromLockTable(snapshot.getId());
}
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class SnapshotTestWithFakeData method testConcurrentSnapshot.
@Test
public void testConcurrentSnapshot() throws URISyntaxException, InterruptedException, ExecutionException {
DataStore store = createDataStore();
final FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver) store.getDriver();
dataStoreDriver.makeTakeSnapshotSucceed(true);
final VolumeInfo volumeInfo = createVolume(1L, store);
Assert.assertTrue(volumeInfo.getState() == Volume.State.Ready);
vol = volumeInfo;
// final SnapshotPolicyVO policyVO = createSnapshotPolicy(vol.getId());
ExecutorService pool = Executors.newFixedThreadPool(2);
boolean result = false;
List<Future<Boolean>> future = new ArrayList<Future<Boolean>>();
for (int i = 0; i < 12; i++) {
final int cnt = i;
Future<Boolean> task = pool.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
boolean r = true;
try {
SnapshotVO snapshotVO = createSnapshotInDb(vol.getId());
VolumeObject volumeObject = (VolumeObject) vol;
Account account = mock(Account.class);
when(account.getId()).thenReturn(1L);
CreateSnapshotPayload createSnapshotPayload = mock(CreateSnapshotPayload.class);
when(createSnapshotPayload.getAccount()).thenReturn(account);
when(createSnapshotPayload.getSnapshotId()).thenReturn(snapshotVO.getId());
when(createSnapshotPayload.getSnapshotPolicyId()).thenReturn(0L);
volumeObject.addPayload(createSnapshotPayload);
if (cnt > 8) {
mockStorageMotionStrategy.makeBackupSnapshotSucceed(false);
}
SnapshotInfo newSnapshot = volumeService.takeSnapshot(vol);
if (newSnapshot == null) {
r = false;
}
} catch (Exception e) {
r = false;
}
return r;
}
});
Assert.assertTrue(task.get());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VolumeServiceTest method createVolumeFromTemplate.
@Test(priority = 2)
public void createVolumeFromTemplate() {
DataStore primaryStore = this.primaryStore;
TemplateInfo te = createTemplate();
VolumeVO volume = createVolume(te.getId(), primaryStore.getId());
VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
// ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeFromTemplateAsync(vol, primaryStore.getId(), te);
try {
future.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VolumeTest method testCopyBaseImage.
@Test
public void testCopyBaseImage() {
DataStore primaryStore = createPrimaryDataStore();
primaryStoreId = primaryStore.getId();
primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
VolumeVO volume = createVolume(image.getId(), primaryStore.getId());
VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeFromTemplateAsync(volInfo, this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image));
try {
VolumeApiResult result = future.get();
AssertJUnit.assertTrue(result.isSuccess());
VolumeInfo newVol = result.getVolume();
boolean res = this.volumeService.destroyVolume(newVol.getId());
Assert.assertTrue(res);
VolumeInfo vol = this.volFactory.getVolume(volume.getId());
future = this.volumeService.expungeVolumeAsync(vol);
result = future.get();
Assert.assertTrue(result.isSuccess());
} catch (InterruptedException e) {
Assert.fail(e.toString());
} catch (ExecutionException e) {
Assert.fail(e.toString());
} catch (ConcurrentOperationException e) {
Assert.fail(e.toString());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.
the class VolumeTestVmware method testDeleteDisk.
@Test
public void testDeleteDisk() {
DataStore primaryStore = createPrimaryDataStore();
primaryStoreId = primaryStore.getId();
primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
VolumeVO volume = createVolume(null, primaryStore.getId());
VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeAsync(volInfo, primaryStore);
try {
VolumeApiResult result = future.get();
VolumeInfo vol = result.getVolume();
this.volumeService.destroyVolume(volInfo.getId());
volInfo = this.volFactory.getVolume(vol.getId());
this.volumeService.expungeVolumeAsync(volInfo);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations