Search in sources :

Example 6 with VolumeDataStoreVO

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

the class VolumeDataFactoryImpl method listVolumeOnCache.

@Override
public List<VolumeInfo> listVolumeOnCache(long volumeId) {
    List<VolumeInfo> cacheVols = new ArrayList<VolumeInfo>();
    // find all image cache stores for this zone scope
    List<DataStore> cacheStores = storeMgr.listImageCacheStores();
    if (cacheStores == null || cacheStores.size() == 0) {
        return cacheVols;
    }
    for (DataStore store : cacheStores) {
        // check if the volume is stored there
        VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(store.getId(), volumeId);
        if (volStore != null) {
            VolumeInfo vol = getVolume(volumeId, store);
            cacheVols.add(vol);
        }
    }
    return cacheVols;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 7 with VolumeDataStoreVO

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

the class VolumeObject method processEventOnly.

@Override
public void processEventOnly(ObjectInDataStoreStateMachine.Event event, Answer answer) {
    try {
        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                VolumeVO vol = volumeDao.findById(getId());
                VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            } else if (answer instanceof CreateObjectAnswer) {
                CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
                VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
                VolumeVO vol = volumeDao.findById(getId());
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            }
        } else {
            // image store or imageCache store
            if (answer instanceof DownloadAnswer) {
                DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
                volStore.setInstallPath(dwdAnswer.getInstallPath());
                volStore.setChecksum(dwdAnswer.getCheckSum());
                volumeStoreDao.update(volStore.getId(), volStore);
            } else if (answer instanceof CopyCmdAnswer) {
                CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
                VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                volStore.setInstallPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    volStore.setSize(newVol.getSize());
                }
                volumeStoreDao.update(volStore.getId(), volStore);
            }
        }
    } catch (RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEventOnly(event);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 8 with VolumeDataStoreVO

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

the class VolumeObject method decRefCount.

@Override
public void decRefCount() {
    if (dataStore == null) {
        return;
    }
    if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
        VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
        store.decrRefCnt();
        store.setLastUpdated(new Date());
        volumeStoreDao.update(store.getId(), store);
    }
}
Also used : VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) Date(java.util.Date)

Example 9 with VolumeDataStoreVO

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

the class VolumeDataStoreDaoImpl method duplicateCacheRecordsOnRegionStore.

@Override
public void duplicateCacheRecordsOnRegionStore(long storeId) {
    // find all records on image cache
    List<DataStore> cacheStores = storeMgr.listImageCacheStores();
    if (cacheStores == null || cacheStores.size() == 0) {
        return;
    }
    List<VolumeDataStoreVO> vols = new ArrayList<VolumeDataStoreVO>();
    for (DataStore store : cacheStores) {
        // check if the volume is stored there
        vols.addAll(listByStoreId(store.getId()));
    }
    // create an entry for each record, but with empty install path since the content is not yet on region-wide store yet
    if (vols != null) {
        s_logger.info("Duplicate " + vols.size() + " volume cache store records to region store");
        for (VolumeDataStoreVO vol : vols) {
            VolumeDataStoreVO volStore = findByStoreVolume(storeId, vol.getVolumeId());
            if (volStore != null) {
                s_logger.info("There is already entry for volume " + vol.getVolumeId() + " on region store " + storeId);
                continue;
            }
            s_logger.info("Persisting an entry for volume " + vol.getVolumeId() + " on region store " + storeId);
            VolumeDataStoreVO vs = new VolumeDataStoreVO();
            vs.setVolumeId(vol.getVolumeId());
            vs.setDataStoreId(storeId);
            vs.setState(vol.getState());
            vs.setDownloadPercent(vol.getDownloadPercent());
            vs.setDownloadState(vol.getDownloadState());
            vs.setSize(vol.getSize());
            vs.setPhysicalSize(vol.getPhysicalSize());
            vs.setErrorString(vol.getErrorString());
            vs.setRefCnt(vol.getRefCnt());
            persist(vs);
            // increase ref_cnt so that this will not be recycled before the content is pushed to region-wide store
            vol.incrRefCnt();
            this.update(vol.getId(), vol);
        }
    }
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 10 with VolumeDataStoreVO

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

the class VolumeDataStoreDaoImpl method deletePrimaryRecordsForStore.

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

Aggregations

VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)33 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 VolumeVO (com.cloud.storage.VolumeVO)9 Date (java.util.Date)8 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)8 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)7 ExecutionException (java.util.concurrent.ExecutionException)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)5 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 ActionEvent (com.cloud.event.ActionEvent)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 DB (com.cloud.utils.db.DB)3 ArrayList (java.util.ArrayList)3 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)3 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)3