use of org.apache.cloudstack.storage.volume.VolumeObject in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method resize.
@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
VolumeObject vol = (VolumeObject) data;
StoragePool pool = (StoragePool) data.getDataStore();
ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
CreateCmdResult result = new CreateCmdResult(null, null);
try {
ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
if (answer != null && answer.getResult()) {
long finalSize = answer.getNewSize();
s_logger.debug("Resize: volume started at size " + vol.getSize() + " and ended at size " + finalSize);
vol.setSize(finalSize);
vol.update();
} else if (answer != null) {
result.setResult(answer.getDetails());
} else {
s_logger.debug("return a null answer, mark it as failed for unknown reason");
result.setResult("return a null answer, mark it as failed for unknown reason");
}
} catch (Exception e) {
s_logger.debug("sending resize command failed", e);
result.setResult(e.toString());
}
callback.complete(result);
}
use of org.apache.cloudstack.storage.volume.VolumeObject in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method resize.
@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
s_logger.debug("Resize elastistor volume started");
Boolean status = false;
VolumeObject vol = (VolumeObject) data;
StoragePool pool = (StoragePool) data.getDataStore();
ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
CreateCmdResult result = new CreateCmdResult(null, null);
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
if (!(poolVO.isManaged())) {
super.resize(data, callback);
return;
}
try {
status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize);
} catch (Throwable e) {
s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e);
result.setResult(e.toString());
callback.complete(result);
}
if (status) {
// now updating the cloudstack storagepool usedbytes and volume
Long usedBytes = poolVO.getUsedBytes();
Long currentVolumeSize = vol.getSize();
Long newUsedBytes;
if (currentVolumeSize < resizeParameter.newSize) {
newUsedBytes = usedBytes + (resizeParameter.newSize - currentVolumeSize);
poolVO.setUsedBytes(newUsedBytes);
} else {
newUsedBytes = usedBytes - (currentVolumeSize - resizeParameter.newSize);
poolVO.setUsedBytes(newUsedBytes);
}
_storagePoolDao.update(pool.getId(), poolVO);
vol.getVolume().setSize(resizeParameter.newSize);
vol.update();
callback.complete(result);
} else {
callback.complete(result);
}
}
use of org.apache.cloudstack.storage.volume.VolumeObject 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.storage.volume.VolumeObject in project cloudstack by apache.
the class PrimaryDataStoreImpl method getVolume.
@Override
public VolumeInfo getVolume(long id) {
VolumeVO volumeVO = volumeDao.findById(id);
VolumeObject vol = VolumeObject.getVolumeObject(this, volumeVO);
return vol;
}
Aggregations