Search in sources :

Example 51 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method verifySufficientBytesForStoragePool.

private void verifySufficientBytesForStoragePool(long requestedBytes, long storagePoolId) {
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    long capacityBytes = storagePool.getCapacityBytes();
    long usedBytes = getUsedBytes(storagePool);
    usedBytes += requestedBytes;
    if (usedBytes > capacityBytes) {
        throw new CloudRuntimeException("Insufficient amount of space remains in this primary storage");
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 52 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method verifySufficientBytesForStoragePool.

private void verifySufficientBytesForStoragePool(DataObject dataObject, long storagePoolId) {
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    long requestedBytes = getDataObjectSizeIncludingHypervisorSnapshotReserve(dataObject, storagePool);
    verifySufficientBytesForStoragePool(requestedBytes, storagePoolId);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 53 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method deleteTemplate.

private void deleteTemplate(TemplateInfo template, long storagePoolId) {
    try {
        SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
        long sfTemplateVolumeId = getVolumeIdFrom_iScsiPath(template.getInstallPath());
        SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
        StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
        // getUsedBytes(StoragePool) will not include the template to delete because the "template_spool_ref" table has already been updated by this point
        long usedBytes = getUsedBytes(storagePool);
        storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
        storagePoolDao.update(storagePoolId, storagePool);
    } catch (Exception ex) {
        LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to delete SolidFire template volume. CloudStack template ID: " + template.getId(), ex);
        throw ex;
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 54 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class ScaleIOPrimaryDataStoreDriver method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
    Preconditions.checkArgument(dataObject != null, "dataObject cannot be null");
    long storagePoolId = dataStore.getId();
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    Preconditions.checkArgument(storagePoolId > 0, "storagePoolId should be > 0");
    Preconditions.checkArgument(storagePool != null && storagePool.getHostAddress() != null, "storagePool and host address should not be null");
    String errMsg = null;
    String scaleIOVolumePath = null;
    try {
        boolean deleteResult = false;
        if (dataObject.getType() == DataObjectType.VOLUME) {
            LOGGER.debug("deleteAsync - deleting volume");
            scaleIOVolumePath = ((VolumeInfo) dataObject).getPath();
        } else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
            LOGGER.debug("deleteAsync - deleting snapshot");
            scaleIOVolumePath = ((SnapshotInfo) dataObject).getPath();
        } else if (dataObject.getType() == DataObjectType.TEMPLATE) {
            LOGGER.debug("deleteAsync - deleting template");
            scaleIOVolumePath = ((TemplateInfo) dataObject).getInstallPath();
        } else {
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
            LOGGER.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        try {
            String scaleIOVolumeId = ScaleIOUtil.getVolumePath(scaleIOVolumePath);
            final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
            deleteResult = client.deleteVolume(scaleIOVolumeId);
            if (!deleteResult) {
                errMsg = "Failed to delete PowerFlex volume with id: " + scaleIOVolumeId;
            }
            long usedBytes = storagePool.getUsedBytes();
            usedBytes -= dataObject.getSize();
            storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
            storagePoolDao.update(storagePoolId, storagePool);
        } catch (Exception e) {
            errMsg = "Unable to delete PowerFlex volume: " + scaleIOVolumePath + " due to " + e.getMessage();
            LOGGER.warn(errMsg);
            throw new CloudRuntimeException(errMsg, e);
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage();
        LOGGER.error(errMsg);
        if (callback == null) {
            throw ex;
        }
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ScaleIOGatewayClient(org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 55 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method getVolumesToDisconnect.

private List<Map<String, String>> getVolumesToDisconnect(VirtualMachine vm) {
    List<Map<String, String>> volumesToDisconnect = new ArrayList<>();
    List<VolumeVO> volumes = _volsDao.findByInstance(vm.getId());
    if (CollectionUtils.isEmpty(volumes)) {
        return volumesToDisconnect;
    }
    for (VolumeVO volume : volumes) {
        StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
        if (storagePool != null && storagePool.isManaged()) {
            Map<String, String> info = new HashMap<>();
            info.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress());
            info.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort()));
            info.put(DiskTO.IQN, volume.get_iScsiName());
            info.put(DiskTO.PROTOCOL_TYPE, (volume.getPoolType() != null) ? volume.getPoolType().toString() : null);
            volumesToDisconnect.add(info);
        }
    }
    return volumesToDisconnect;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)276 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)106 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)75 ArrayList (java.util.ArrayList)54 VolumeVO (com.cloud.storage.VolumeVO)53 HostVO (com.cloud.host.HostVO)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)45 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)45 HashMap (java.util.HashMap)44 Answer (com.cloud.agent.api.Answer)38 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)35 StoragePool (com.cloud.storage.StoragePool)33 Test (org.junit.Test)33 VMInstanceVO (com.cloud.vm.VMInstanceVO)25 Map (java.util.Map)25 Account (com.cloud.user.Account)24 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)20 ExecutionException (java.util.concurrent.ExecutionException)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ClusterVO (com.cloud.dc.ClusterVO)18