Search in sources :

Example 26 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class DateraPrimaryDataStoreDriver method getUsedBytes.

/**
 * Get the total space used by all the entities on the storage.
 * Total space = volume space + snapshot space + template space
 * @param storagePool      Primary storage
 * @param volumeIdToIgnore Ignore this volume (used when we delete a volume and
 *                         want to update the space)
 * @return size in bytes
 */
private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) {
    long usedSpaceBytes = 0;
    List<VolumeVO> lstVolumes = _volumeDao.findByPoolId(storagePool.getId(), null);
    if (lstVolumes != null) {
        for (VolumeVO volume : lstVolumes) {
            if (volume.getId() == volumeIdToIgnore) {
                continue;
            }
            VolumeDetailVO volumeDetail = volumeDetailsDao.findDetail(volume.getId(), DateraUtil.VOLUME_SIZE);
            if (volumeDetail != null && volumeDetail.getValue() != null) {
                long volumeSizeGib = Long.parseLong(volumeDetail.getValue());
                long volumeSizeBytes = DateraUtil.gibToBytes((int) (volumeSizeGib));
                usedSpaceBytes += volumeSizeBytes;
            } else {
                DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePool.getId(), _storagePoolDetailsDao);
                try {
                    String appInstanceName = getAppInstanceName(volumeDataFactory.getVolume(volume.getId()));
                    DateraObject.AppInstance appInstance = DateraUtil.getAppInstance(conn, appInstanceName);
                    if (appInstance != null) {
                        usedSpaceBytes += DateraUtil.gibToBytes(appInstance.getSize());
                    }
                } catch (DateraObject.DateraError dateraError) {
                    String errMesg = "Error getting used bytes for storage pool : " + storagePool.getId();
                    s_logger.warn(errMesg, dateraError);
                    throw new CloudRuntimeException(errMesg);
                }
            }
        }
    }
    List<SnapshotVO> lstSnapshots = _snapshotDao.listAll();
    if (lstSnapshots != null) {
        for (SnapshotVO snapshot : lstSnapshots) {
            SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), DateraUtil.STORAGE_POOL_ID);
            // if this snapshot belongs to the storagePool that was passed in
            if (snapshotDetails != null && snapshotDetails.getValue() != null && Long.parseLong(snapshotDetails.getValue()) == storagePool.getId()) {
                snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), DateraUtil.VOLUME_SIZE);
                if (snapshotDetails != null && snapshotDetails.getValue() != null) {
                    long snapshotSize = Long.parseLong(snapshotDetails.getValue());
                    usedSpaceBytes += snapshotSize;
                }
            }
        }
    }
    List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId());
    if (lstTemplatePoolRefs != null) {
        for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
            usedSpaceBytes += templatePoolRef.getTemplateSize();
        }
    }
    s_logger.debug("usedSpaceBytes: " + toHumanReadableSize(usedSpaceBytes));
    return usedSpaceBytes;
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DateraObject(org.apache.cloudstack.storage.datastore.util.DateraObject)

Example 27 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method deleteSnapshot.

private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) {
    long csSnapshotId = snapshotInfo.getId();
    try {
        SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            // A SolidFire snapshot is being used to support the CloudStack volume snapshot.
            long sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
            deleteSolidFireSnapshot(sfConnection, csSnapshotId, sfSnapshotId);
        } else {
            // A SolidFire volume is being used to support the CloudStack volume snapshot.
            snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID);
            long sfVolumeId = Long.parseLong(snapshotDetails.getValue());
            SolidFireUtil.deleteVolume(sfConnection, sfVolumeId);
        }
        snapshotDetailsDao.removeDetails(csSnapshotId);
        StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
        // getUsedBytes(StoragePool) will not include the snapshot to delete because it has already been deleted 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 + "Issue in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, 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) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 28 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method createClone.

private SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) {
    String sfNewVolumeName = volumeInfo.getName();
    long sfVolumeId = Long.MIN_VALUE;
    long sfSnapshotId = Long.MIN_VALUE;
    if (dataObjectType == DataObjectType.SNAPSHOT) {
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
        }
        snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID);
        sfVolumeId = Long.parseLong(snapshotDetails.getValue());
    } else if (dataObjectType == DataObjectType.TEMPLATE) {
        // get the cached template on this storage
        VMTemplateStoragePoolVO templatePoolRef = vmTemplatePoolDao.findByPoolTemplate(storagePoolId, dataObjectId, null);
        if (templatePoolRef != null) {
            sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
        }
    }
    if (sfVolumeId <= 0) {
        throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType);
    }
    final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), getVolumeAttributes(volumeInfo));
    final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId);
    SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops());
    return SolidFireUtil.getVolume(sfConnection, newSfVolumeId);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 29 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method removeTempVolumeId.

private void removeTempVolumeId(long csSnapshotId) {
    SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.TEMP_VOLUME_ID);
    if (snapshotDetails == null || snapshotDetails.getValue() == null) {
        throw new CloudRuntimeException("'removeTempVolumeId' should not be invoked unless " + SolidFireUtil.TEMP_VOLUME_ID + " exists.");
    }
    String originalVolumeId = snapshotDetails.getValue();
    handleSnapshotDetails(csSnapshotId, SolidFireUtil.VOLUME_ID, originalVolumeId);
    snapshotDetailsDao.remove(snapshotDetails.getId());
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 30 with SnapshotDetailsVO

use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method deleteSolidFireVolume.

private void deleteSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, long csVolumeId, long sfVolumeId) {
    List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(csVolumeId);
    boolean deleteVolume = true;
    for (SnapshotVO snapshot : lstSnapshots) {
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            deleteVolume = false;
            break;
        }
    }
    if (deleteVolume) {
        SolidFireUtil.deleteVolume(sfConnection, sfVolumeId);
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Aggregations

SnapshotDetailsVO (com.cloud.storage.dao.SnapshotDetailsVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 SnapshotVO (com.cloud.storage.SnapshotVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 DateraObject (org.apache.cloudstack.storage.datastore.util.DateraObject)5 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)5 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)4 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)4 HostVO (com.cloud.host.HostVO)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 ArrayList (java.util.ArrayList)2 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)2 CommandResult (org.apache.cloudstack.storage.command.CommandResult)2 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 VolumeDetailVO (com.cloud.storage.VolumeDetailVO)1 SnapshotAndCopyAnswer (com.cloud.storage.command.SnapshotAndCopyAnswer)1