Search in sources :

Example 1 with ResizeVolumePayload

use of com.cloud.storage.ResizeVolumePayload 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 ResizeVolumePayload

use of com.cloud.storage.ResizeVolumePayload 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 ResizeVolumePayload

use of com.cloud.storage.ResizeVolumePayload in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method resize.

@Override
public void resize(DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errMsg = null;
    if (dataObject.getType() == DataObjectType.VOLUME) {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        iqn = volumeInfo.get_iScsiName();
        long storagePoolId = volumeInfo.getPoolId();
        long sfVolumeId = Long.parseLong(volumeInfo.getFolder());
        ResizeVolumePayload payload = (ResizeVolumePayload) volumeInfo.getpayload();
        SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
        SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId);
        verifySufficientIopsForStoragePool(storagePoolId, volumeInfo.getId(), payload.newMinIops);
        verifySufficientBytesForStoragePool(storagePoolId, volumeInfo.getId(), payload.newSize, payload.newHypervisorSnapshotReserve);
        long sfNewVolumeSize = sfVolume.getTotalSize();
        Integer hsr = volumeInfo.getHypervisorSnapshotReserve();
        if (payload.newSize != null || payload.newHypervisorSnapshotReserve != null) {
            if (payload.newHypervisorSnapshotReserve != null) {
                if (hsr != null) {
                    if (payload.newHypervisorSnapshotReserve > hsr) {
                        hsr = payload.newHypervisorSnapshotReserve;
                    }
                } else {
                    hsr = payload.newHypervisorSnapshotReserve;
                }
            }
            sfNewVolumeSize = getVolumeSizeIncludingHypervisorSnapshotReserve(payload.newSize, hsr);
        }
        Map<String, String> mapAttributes = new HashMap<>();
        mapAttributes.put(SolidFireUtil.CloudStackVolumeId, String.valueOf(volumeInfo.getId()));
        mapAttributes.put(SolidFireUtil.CloudStackVolumeSize, NumberFormat.getInstance().format(payload.newSize));
        SolidFireUtil.modifyVolume(sfConnection, sfVolumeId, sfNewVolumeSize, mapAttributes, payload.newMinIops, payload.newMaxIops, getDefaultBurstIops(storagePoolId, payload.newMaxIops));
        VolumeVO volume = volumeDao.findById(volumeInfo.getId());
        volume.setMinIops(payload.newMinIops);
        volume.setMaxIops(payload.newMaxIops);
        volume.setHypervisorSnapshotReserve(hsr);
        volumeDao.update(volume.getId(), volume);
        // SolidFireUtil.VOLUME_SIZE was introduced in 4.5.
        updateVolumeDetails(volume.getId(), sfNewVolumeSize);
    } else {
        errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to resize";
    }
    CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : HashMap(java.util.HashMap) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil)

Aggregations

ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)3 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)3 StoragePool (com.cloud.storage.StoragePool)2 VolumeObject (org.apache.cloudstack.storage.volume.VolumeObject)2 Answer (com.cloud.agent.api.Answer)1 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 VolumeVO (com.cloud.storage.VolumeVO)1 HashMap (java.util.HashMap)1 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)1 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)1