Search in sources :

Example 66 with DataStore

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

the class ImageStoreProviderManagerImpl method listImageStores.

@Override
public List<DataStore> listImageStores() {
    final List<ImageStoreVO> stores = dataStoreDao.listImageStores();
    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 67 with DataStore

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

the class SnapshotDataFactoryImpl method listSnapshotOnCache.

@Override
public List<SnapshotInfo> listSnapshotOnCache(final long snapshotId) {
    final List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
    final List<SnapshotInfo> snapObjs = new ArrayList<>();
    for (final SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
        final long storeId = cacheSnap.getDataStoreId();
        final DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
        final SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
        snapObjs.add(tmplObj);
    }
    return snapObjs;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) ArrayList(java.util.ArrayList)

Example 68 with DataStore

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

the class SnapshotServiceImpl method deleteSnapshot.

@Override
public boolean deleteSnapshot(final SnapshotInfo snapInfo) {
    snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<>(null, snapInfo, future);
    final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
    final DataStore store = snapInfo.getDataStore();
    store.getDriver().deleteAsync(store, snapInfo, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (final InterruptedException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    } catch (final ExecutionException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 69 with DataStore

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

the class SnapshotServiceImpl method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(final SnapshotInfo snapshot) {
    final SnapshotObject snapObj = (SnapshotObject) snapshot;
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final SnapshotResult result = new SnapshotResult(snapshot, null);
    try {
        snapObj.processEvent(Snapshot.Event.BackupToSecondary);
        final DataStore imageStore = findSnapshotImageStore(snapshot);
        if (imageStore == null) {
            throw new CloudRuntimeException("can not find an image stores");
        }
        final SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
        snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
        final CopySnapshotContext<CommandResult> context = new CopySnapshotContext<>(null, snapshot, snapshotOnImageStore, future);
        final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to copy snapshot", e);
        result.setResult("Failed to copy snapshot:" + e.toString());
        try {
            snapObj.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change state: " + e1.toString());
        }
        future.complete(result);
    }
    try {
        final SnapshotResult res = future.get();
        if (res.isFailed()) {
            throw new CloudRuntimeException(res.getResult());
        }
        final SnapshotInfo destSnapshot = res.getSnashot();
        return destSnapshot;
    } catch (final InterruptedException e) {
        s_logger.debug("failed copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    } catch (final ExecutionException e) {
        s_logger.debug("Failed to copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    }
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 70 with DataStore

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

the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.

protected Void createTemplateAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing image store createTemplate async callback");
    }
    final DownloadAnswer answer = callback.getResult();
    final DataObject obj = context.data;
    final DataStore store = obj.getDataStore();
    final TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
    if (tmpltStoreVO != null) {
        if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        final TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
        updateBuilder.setDownloadPercent(answer.getDownloadPct());
        updateBuilder.setDownloadState(answer.getDownloadStatus());
        updateBuilder.setLastUpdated(new Date());
        updateBuilder.setErrorString(answer.getErrorString());
        updateBuilder.setJobId(answer.getJobId());
        updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
        updateBuilder.setInstallPath(answer.getInstallPath());
        updateBuilder.setSize(answer.getTemplateSize());
        updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
        _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
        // update size in vm_template table
        final VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
        tmlptUpdater.setSize(answer.getTemplateSize());
        _templateDao.update(obj.getId(), tmlptUpdater);
    }
    final AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
    if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
        final CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(answer.getErrorString());
        caller.complete(result);
        final String msg = "Failed to register template: " + obj.getUuid() + " with error: " + answer.getErrorString();
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        if (answer.getCheckSum() != null) {
            final VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate();
            templateDaoBuilder.setChecksum(answer.getCheckSum());
            _templateDao.update(obj.getId(), templateDaoBuilder);
        }
        final CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

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