Search in sources :

Example 31 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 32 with SnapshotDataStoreVO

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

the class SnapshotDataFactoryImpl method getSnapshot.

@Override
public SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role) {
    SnapshotVO snapshot = snapshotDao.findById(snapshotId);
    SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotId, role);
    if (snapshotStore == null) {
        snapshotStore = snapshotStoreDao.findByVolume(snapshot.getVolumeId(), role);
        if (snapshotStore == null) {
            return null;
        }
    }
    DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
    SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
    return so;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 33 with SnapshotDataStoreVO

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

the class SnapshotObject method getParent.

@Override
public SnapshotInfo getParent() {
    SnapshotDataStoreVO snapStoreVO = snapshotStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshot.getId());
    Long parentId = null;
    if (snapStoreVO != null) {
        parentId = snapStoreVO.getParentSnapshotId();
        if (parentId != null && parentId != 0) {
            return snapshotFactory.getSnapshot(parentId, store);
        }
    }
    return null;
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 34 with SnapshotDataStoreVO

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

the class VolumeOrchestrator method getDataStoreRole.

public DataStoreRole getDataStoreRole(Snapshot snapshot) {
    SnapshotDataStoreVO snapshotStore = _snapshotDataStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotStore == null) {
        return DataStoreRole.Image;
    }
    long storagePoolId = snapshotStore.getDataStoreId();
    DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
    if (mapCapabilities != null) {
        String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
        Boolean supportsStorageSystemSnapshots = new Boolean(value);
        if (supportsStorageSystemSnapshots) {
            return DataStoreRole.Primary;
        }
    }
    return DataStoreRole.Image;
}
Also used : PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 35 with SnapshotDataStoreVO

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

the class SnapshotDataStoreDaoImpl method deletePrimaryRecordsForStore.

@Override
public void deletePrimaryRecordsForStore(long id, DataStoreRole role) {
    SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
    sc.setParameters("store_id", id);
    sc.setParameters("store_role", role);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Aggregations

SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)38 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 SnapshotVO (com.cloud.storage.SnapshotVO)10 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)6 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 VolumeVO (com.cloud.storage.VolumeVO)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 DB (com.cloud.utils.db.DB)4 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 Account (com.cloud.user.Account)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)3 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)3