Search in sources :

Example 31 with SnapshotVO

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

the class XenServerStorageMotionStrategy method getNonDestroyedSnapshots.

private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) {
    List<SnapshotVO> lstSnapshots = snapshotDao.listByVolumeId(csVolumeId);
    if (lstSnapshots == null) {
        lstSnapshots = new ArrayList<>();
    }
    List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
    for (SnapshotVO snapshot : lstSnapshots) {
        if (!Snapshot.State.Destroyed.equals(snapshot.getState())) {
            lstSnapshots2.add(snapshot);
        }
    }
    return lstSnapshots2;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) ArrayList(java.util.ArrayList)

Example 32 with SnapshotVO

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

the class XenServerStorageMotionStrategy method verifyNoSnapshotsOnManagedStorageVolumes.

private void verifyNoSnapshotsOnManagedStorageVolumes(Map<VolumeInfo, DataStore> volumeToPool) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
        if (storagePool.isManaged()) {
            List<SnapshotVO> snapshots = getNonDestroyedSnapshots(volumeInfo.getId());
            if (snapshots != null && snapshots.size() > 0) {
                throw new CloudRuntimeException("Cannot perform this action on a volume with one or more snapshots");
            }
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 33 with SnapshotVO

use of com.cloud.storage.SnapshotVO 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 34 with SnapshotVO

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

the class LinstorPrimaryDataStoreDriverImpl method createResourceFromSnapshot.

private String createResourceFromSnapshot(long csSnapshotId, String rscName, StoragePoolVO storagePoolVO) {
    final String rscGrp = storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ? storagePoolVO.getUserInfo() : "DfltRscGrp";
    final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
    SnapshotVO snapshotVO = _snapshotDao.findById(csSnapshotId);
    String snapName = LinstorUtil.RSC_PREFIX + snapshotVO.getUuid();
    VolumeVO volumeVO = _volumeDao.findById(snapshotVO.getVolumeId());
    String cloneRes = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
    try {
        s_logger.debug("Create new resource definition: " + rscName);
        ResourceDefinitionCreate rdCreate = new ResourceDefinitionCreate();
        ResourceDefinition rd = new ResourceDefinition();
        rd.setName(rscName);
        rd.setResourceGroupName(rscGrp);
        rdCreate.setResourceDefinition(rd);
        ApiCallRcList answers = linstorApi.resourceDefinitionCreate(rdCreate);
        checkLinstorAnswersThrow(answers);
        SnapshotRestore snapshotRestore = new SnapshotRestore();
        snapshotRestore.toResource(rscName);
        s_logger.debug("Create new volume definition for snapshot: " + cloneRes + ":" + snapName);
        answers = linstorApi.resourceSnapshotsRestoreVolumeDefinition(cloneRes, snapName, snapshotRestore);
        checkLinstorAnswersThrow(answers);
        // restore snapshot to new resource
        s_logger.debug("Restore resource from snapshot: " + cloneRes + ":" + snapName);
        answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore);
        checkLinstorAnswersThrow(answers);
        return getDeviceName(linstorApi, rscName);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceDefinitionCreate(com.linbit.linstor.api.model.ResourceDefinitionCreate) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) SnapshotRestore(com.linbit.linstor.api.model.SnapshotRestore) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException)

Example 35 with SnapshotVO

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

the class DateraPrimaryDataStoreDriver method getNonDestroyedSnapshots.

private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) {
    List<SnapshotVO> lstSnapshots = _snapshotDao.listByVolumeId(csVolumeId);
    if (lstSnapshots == null) {
        lstSnapshots = new ArrayList<>();
    }
    List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
    for (SnapshotVO snapshot : lstSnapshots) {
        if (!Snapshot.State.Destroyed.equals(snapshot.getState())) {
            lstSnapshots2.add(snapshot);
        }
    }
    return lstSnapshots2;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) ArrayList(java.util.ArrayList)

Aggregations

SnapshotVO (com.cloud.storage.SnapshotVO)105 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)29 VolumeVO (com.cloud.storage.VolumeVO)28 Account (com.cloud.user.Account)22 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 ArrayList (java.util.ArrayList)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)16 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)16 HostVO (com.cloud.host.HostVO)15 VMTemplateVO (com.cloud.storage.VMTemplateVO)15 DB (com.cloud.utils.db.DB)14 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)12 ConfigurationException (javax.naming.ConfigurationException)12 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 UserVmVO (com.cloud.vm.UserVmVO)10 VMInstanceVO (com.cloud.vm.VMInstanceVO)10 ActionEvent (com.cloud.event.ActionEvent)9