Search in sources :

Example 46 with SnapshotDataStoreVO

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

the class SolidFirePrimaryDataStoreDriver method getUsedBytes.

private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) {
    long usedSpace = 0;
    List<VolumeVO> lstVolumes = volumeDao.findByPoolIdAndState(storagePool.getId(), Volume.State.Ready);
    if (lstVolumes != null) {
        for (VolumeVO volume : lstVolumes) {
            if (volume.getId() == volumeIdToIgnore) {
                continue;
            }
            usedSpace += getVolumeSizeIncludingHypervisorSnapshotReserve(volume.getSize(), volume.getHypervisorSnapshotReserve());
        }
    }
    List<SnapshotDataStoreVO> snapshotDataStoreVOList = snapshotDataStoreDao.listByStoreIdAndState(storagePool.getId(), ObjectInDataStoreStateMachine.State.Ready);
    if (snapshotDataStoreVOList != null) {
        for (SnapshotDataStoreVO snapshot : snapshotDataStoreVOList) {
            usedSpace += snapshot.getPhysicalSize();
        }
    }
    List<VMTemplateStoragePoolVO> vmTemplateStoragePoolVOList = vmTemplatePoolDao.listByPoolIdAndState(storagePool.getId(), ObjectInDataStoreStateMachine.State.Ready);
    if (vmTemplateStoragePoolVOList != null) {
        for (VMTemplateStoragePoolVO template : vmTemplateStoragePoolVOList) {
            usedSpace += template.getTemplateSize();
        }
    }
    return usedSpace;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VolumeVO(com.cloud.storage.VolumeVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 47 with SnapshotDataStoreVO

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

the class StorageCacheReplacementAlgorithmLRU method chooseOneToBeReplaced.

@Override
public DataObject chooseOneToBeReplaced(DataStore store) {
    if (unusedTimeInterval == null) {
        unusedTimeInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementLRUTimeInterval.key()), 30);
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(DateUtil.now());
    cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue());
    Date bef = cal.getTime();
    QueryBuilder<TemplateDataStoreVO> sc = QueryBuilder.create(TemplateDataStoreVO.class);
    sc.and(sc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    sc.and(sc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    sc.and(sc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    sc.and(sc.entity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole());
    sc.and(sc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    TemplateDataStoreVO template = sc.find();
    if (template != null) {
        return templateFactory.getTemplate(template.getTemplateId(), store);
    }
    QueryBuilder<VolumeDataStoreVO> volSc = QueryBuilder.create(VolumeDataStoreVO.class);
    volSc.and(volSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    volSc.and(volSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    volSc.and(volSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    volSc.and(volSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    VolumeDataStoreVO volume = volSc.find();
    if (volume != null) {
        return volumeFactory.getVolume(volume.getVolumeId(), store);
    }
    QueryBuilder<SnapshotDataStoreVO> snapshotSc = QueryBuilder.create(SnapshotDataStoreVO.class);
    snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ, store.getRole());
    snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    SnapshotDataStoreVO snapshot = snapshotSc.find();
    if (snapshot != null) {
        return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
    }
    return null;
}
Also used : Calendar(java.util.Calendar) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Example 48 with SnapshotDataStoreVO

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

the class SnapshotServiceImpl method cleanupVolumeDuringSnapshotFailure.

@Override
public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) {
    SnapshotVO snaphsot = _snapshotDao.findById(snapshotId);
    if (snaphsot != null) {
        if (snaphsot.getState() != Snapshot.State.BackedUp) {
            List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
            for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) {
                s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId());
                _snapshotStoreDao.remove(snapshotDataStoreVO.getId());
            }
            s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table");
            _snapshotDao.remove(snapshotId);
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 49 with SnapshotDataStoreVO

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

the class CephSnapshotStrategy method isSnapshotStoredOnRbdStoragePool.

protected boolean isSnapshotStoredOnRbdStoragePool(Snapshot snapshot) {
    SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotStore == null) {
        return false;
    }
    StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(snapshotStore.getDataStoreId());
    return storagePoolVO != null && storagePoolVO.getPoolType() == StoragePoolType.RBD;
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 50 with SnapshotDataStoreVO

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

the class ScaleIOSnapshotStrategy method isSnapshotStoredOnScaleIOStoragePool.

protected boolean isSnapshotStoredOnScaleIOStoragePool(Snapshot snapshot) {
    SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotStore == null) {
        return false;
    }
    StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(snapshotStore.getDataStoreId());
    return storagePoolVO != null && storagePoolVO.getPoolType() == Storage.StoragePoolType.PowerFlex;
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Aggregations

SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)60 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)22 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)19 SnapshotVO (com.cloud.storage.SnapshotVO)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 VolumeVO (com.cloud.storage.VolumeVO)11 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)10 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)9 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)7 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6 DB (com.cloud.utils.db.DB)6 ArrayList (java.util.ArrayList)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Date (java.util.Date)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 Account (com.cloud.user.Account)4 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)4