Search in sources :

Example 1 with VolumeObject

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);
}
Also used : StoragePool(com.cloud.storage.StoragePool) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 2 with VolumeObject

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);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject)

Example 3 with VolumeObject

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());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) URISyntaxException(java.net.URISyntaxException) ExecutionException(java.util.concurrent.ExecutionException) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 4 with VolumeObject

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;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject)

Aggregations

VolumeObject (org.apache.cloudstack.storage.volume.VolumeObject)4 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)2 StoragePool (com.cloud.storage.StoragePool)2 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)1 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)1 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 CreateSnapshotPayload (com.cloud.storage.CreateSnapshotPayload)1 SnapshotVO (com.cloud.storage.SnapshotVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 Account (com.cloud.user.Account)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)1 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)1