Search in sources :

Example 16 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method listImageStoresByScope.

@Override
public List<DataStore> listImageStoresByScope(final ZoneScope scope) {
    final List<ImageStoreVO> stores = dataStoreDao.findByScope(scope);
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 17 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class SnapshotDataFactoryImpl method getSnapshot.

@Override
public SnapshotInfo getSnapshot(final long snapshotId, final DataStoreRole role) {
    final 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;
        }
    }
    final DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
    final SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
    return so;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 18 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method handleCreateTemplateFromSnapshot.

private Void handleCreateTemplateFromSnapshot(final SnapshotInfo snapshotInfo, final TemplateInfo templateInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        snapshotInfo.processEvent(Event.CopyingRequested);
    } catch (final Exception ex) {
        throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
    }
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final DataStore srcDataStore = snapshotInfo.getDataStore();
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
                errMsg = copyCmdAnswer.getDetails();
            } else {
                errMsg = "Unable to perform host-side operation";
            }
        }
        try {
            if (errMsg == null) {
                snapshotInfo.processEvent(Event.OperationSuccessed);
            } else {
                snapshotInfo.processEvent(Event.OperationFailed);
            }
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 19 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class TemplateDataStoreDaoImpl method findByTemplateZoneReady.

@Override
public TemplateDataStoreVO findByTemplateZoneReady(final long templateId, final Long zoneId) {
    List<DataStore> imgStores = null;
    imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
    if (imgStores != null) {
        Collections.shuffle(imgStores);
        for (final DataStore store : imgStores) {
            final List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
            if (sRes != null && sRes.size() > 0) {
                return sRes.get(0);
            }
        }
    }
    return null;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 20 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class VolumeDataStoreDaoImpl method duplicateCacheRecordsOnRegionStore.

@Override
public void duplicateCacheRecordsOnRegionStore(final long storeId) {
    // find all records on image cache
    final List<DataStore> cacheStores = storeMgr.listImageCacheStores();
    if (cacheStores == null || cacheStores.size() == 0) {
        return;
    }
    final List<VolumeDataStoreVO> vols = new ArrayList<>();
    for (final 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 (final VolumeDataStoreVO vol : vols) {
            final 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);
            final 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(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ArrayList(java.util.ArrayList)

Aggregations

DataStore (com.cloud.engine.subsystem.api.storage.DataStore)96 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)43 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 ExecutionException (java.util.concurrent.ExecutionException)23 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)19 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)17 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)17 ArrayList (java.util.ArrayList)17 VolumeVO (com.cloud.storage.VolumeVO)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)14 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)14 DB (com.cloud.utils.db.DB)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)12 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)12 ConfigurationException (javax.naming.ConfigurationException)12 Answer (com.cloud.agent.api.Answer)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)10