Search in sources :

Example 6 with SnapshotDetailsVO

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

the class DateraPrimaryDataStoreDriver method deleteSnapshot.

/**
 * Deletes snapshot on Datera
 * @param snapshotInfo  snapshot information
 * @param storagePoolId primary storage
 * @throws UnsupportedEncodingException
 * @throws                              DateraObject.DateraError
 */
private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) throws UnsupportedEncodingException, DateraObject.DateraError {
    long csSnapshotId = snapshotInfo.getId();
    try {
        DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePoolId, _storagePoolDetailsDao);
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            // Native snapshot being used, delete that
            String snapshotName = snapshotDetails.getValue();
            DateraUtil.deleteVolumeSnapshot(conn, snapshotName);
            // check if the underlying volume needs to be deleted
            SnapshotVO snapshot = _snapshotDao.findById(csSnapshotId);
            VolumeVO volume = _volumeDao.findById(snapshot.getVolumeId());
            if (volume == null) {
                // deleted from Cloudstack. Check if other snapshots are using this volume
                volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
                if (shouldDeleteVolume(snapshot.getVolumeId(), snapshot.getId())) {
                    DateraUtil.deleteAppInstance(conn, volume.getFolder());
                }
            }
        } else {
            // An App Instance is being used to support the CloudStack volume snapshot.
            snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
            String appInstanceName = snapshotDetails.getValue();
            DateraUtil.deleteAppInstance(conn, appInstanceName);
        }
        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) {
        s_logger.debug("Error in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, ex);
        throw ex;
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DateraObject(org.apache.cloudstack.storage.datastore.util.DateraObject) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with SnapshotDetailsVO

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

the class DateraPrimaryDataStoreDriver method addTempVolumeToDb.

/**
 * Adding temp volume to the snapshot_details table. This is used if we are
 * using a native snapshot and we want to create a template out of the snapshot
 *
 * @param csSnapshotId   Source snasphot
 * @param tempVolumeName temp volume app instance on Datera
 */
private void addTempVolumeToDb(long csSnapshotId, String tempVolumeName) {
    SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
    if (snapshotDetails == null || snapshotDetails.getValue() == null) {
        throw new CloudRuntimeException("'addTempVolumeId' should not be invoked unless " + DateraUtil.VOLUME_ID + " exists.");
    }
    String originalVolumeId = snapshotDetails.getValue();
    handleSnapshotDetails(csSnapshotId, DateraUtil.TEMP_VOLUME_ID, originalVolumeId);
    handleSnapshotDetails(csSnapshotId, DateraUtil.VOLUME_ID, tempVolumeName);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 8 with SnapshotDetailsVO

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

the class DateraPrimaryDataStoreDriver method removeTempVolumeFromDb.

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

Example 9 with SnapshotDetailsVO

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

the class LinstorPrimaryDataStoreDriverImpl method removeTempVolumeFromDb.

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

Example 10 with SnapshotDetailsVO

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

the class LinstorPrimaryDataStoreDriverImpl method createVolumeFromSnapshot.

private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo, StoragePoolVO storagePoolVO) {
    long csSnapshotId = snapshotInfo.getId();
    SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(csSnapshotId, "tempVolume");
    if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("create")) {
        final String csName = "Temp-" + snapshotInfo.getUuid();
        final String tempRscName = LinstorUtil.RSC_PREFIX + csName;
        createResourceFromSnapshot(csSnapshotId, tempRscName, storagePoolVO);
        s_logger.debug("Temp resource created: " + tempRscName);
        addTempVolumeToDb(csSnapshotId, csName);
    } else if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("delete")) {
        snapshotDetails = _snapshotDetailsDao.findDetail(csSnapshotId, LinstorUtil.TEMP_VOLUME_ID);
        deleteResourceDefinition(storagePoolVO, snapshotDetails.getValue());
        s_logger.debug("Temp resource deleted: " + snapshotDetails.getValue());
        removeTempVolumeFromDb(csSnapshotId);
    } else {
        throw new CloudRuntimeException("Invalid state in 'createVolumeFromSnapshot(SnapshotInfo, StoragePoolVO)'");
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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