Search in sources :

Example 16 with CreateCmdResult

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

the class CloudStackPrimaryDataStoreDriverImpl method createAsync.

@Override
public void createAsync(final DataStore dataStore, final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
    String errMsg = null;
    Answer answer = null;
    final CreateCmdResult result = new CreateCmdResult(null, null);
    if (data.getType() == DataObjectType.VOLUME) {
        try {
            answer = createVolume((VolumeInfo) data);
            if ((answer == null) || (!answer.getResult())) {
                result.setSuccess(false);
                if (answer != null) {
                    result.setResult(answer.getDetails());
                }
            } else {
                result.setAnswer(answer);
            }
        } catch (final StorageUnavailableException e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        } catch (final Exception e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        }
    }
    if (errMsg != null) {
        result.setResult(errMsg);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 17 with CreateCmdResult

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

the class TemplateServiceImpl method copyTemplateCrossZoneCallBack.

protected Void copyTemplateCrossZoneCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing copy template cross zone callback after completion");
    }
    final TemplateInfo destTemplate = context.getTemplate();
    final CreateCmdResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process copy template cross zones callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 18 with CreateCmdResult

use of com.cloud.engine.subsystem.api.storage.CreateCmdResult 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)

Example 19 with CreateCmdResult

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

the class BaseImageStoreDriverImpl method createVolumeAsyncCallback.

protected Void createVolumeAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
    final DownloadAnswer answer = callback.getResult();
    final DataObject obj = context.data;
    final DataStore store = obj.getDataStore();
    final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
    if (volStoreVO != null) {
        if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        final VolumeDataStoreVO updateBuilder = _volumeStoreDao.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());
        _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
        // update size in volume table
        final VolumeVO volUpdater = volumeDao.createForUpdate();
        volUpdater.setSize(answer.getTemplateSize());
        volumeDao.update(obj.getId(), volUpdater);
    }
    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 upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg);
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        final CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 20 with CreateCmdResult

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

the class TemplateServiceImpl method createTemplateAsync.

@Override
public void createTemplateAsync(final TemplateInfo template, final DataStore store, final AsyncCompletionCallback<TemplateApiResult> callback) {
    // persist template_store_ref entry
    final TemplateObject templateOnStore = (TemplateObject) store.create(template);
    // update template_store_ref and template state
    try {
        templateOnStore.processEvent(ObjectInDataStoreStateMachine.Event.CreateOnlyRequested);
    } catch (final Exception e) {
        final TemplateApiResult result = new TemplateApiResult(templateOnStore);
        result.setResult(e.toString());
        result.setSuccess(false);
        if (callback != null) {
            callback.complete(result);
        }
        return;
    }
    try {
        final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(callback, templateOnStore, null);
        final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createTemplateCallback(null, null)).setContext(context);
        store.getDriver().createAsync(store, templateOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
        final TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
        if (templateStoreVO != null) {
            final TemplateInfo tmplObj = _templateFactory.getTemplate(template, store);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final TemplateApiResult result = new TemplateApiResult(template);
        result.setResult(ex.getMessage());
        if (callback != null) {
            callback.complete(result);
        }
    }
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Aggregations

CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)4 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)3 TemplateObject (com.cloud.storage.image.store.TemplateObject)3 Answer (com.cloud.agent.api.Answer)2 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2