Search in sources :

Example 1 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method createTemplateCallback.

protected Void createTemplateCallback(final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateObject template = context.getTemplate();
    final AsyncCompletionCallback<TemplateApiResult> parentCallback = context.getParentCallback();
    final TemplateApiResult result = new TemplateApiResult(template);
    final CreateCmdResult callbackResult = callback.getResult();
    if (callbackResult.isFailed()) {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        result.setResult(callbackResult.getResult());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    try {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (final Exception e) {
        result.setResult(e.toString());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    if (parentCallback != null) {
        parentCallback.complete(result);
    }
    return null;
}
Also used : 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) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 2 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<TemplateApiResult> syncToRegionStoreAsync(final TemplateInfo template, final DataStore store) {
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    // no need to create entry on template_store_ref here, since entries are already created when prepareSecondaryStorageForMigration is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    final TemplateInfo templateOnStore = _templateFactory.getTemplate(template, store);
    final String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + template.getAccountId() + "/" + template.getId() + "/" + template.getUniqueName();
    ((TemplateObject) templateOnStore).setInstallPath(installPath);
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(template, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 3 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject in project cosmic by MissionCriticalCloud.

the class TemplateDataFactoryImpl method getTemplate.

@Override
public TemplateInfo getTemplate(final DataObject obj, final DataStore store) {
    final TemplateObject tmpObj = (TemplateObject) this.getTemplate(obj.getId(), store);
    // carry over url set in passed in data object, for copyTemplate case
    // where url is generated on demand and not persisted in DB.
    // need to think of a more generic way to pass these runtime information
    // carried through DataObject post 4.2
    final TemplateObject origTmpl = (TemplateObject) obj;
    tmpObj.setUrl(origTmpl.getUrl());
    return tmpObj;
}
Also used : TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 4 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method deleteTemplateAsync.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateAsync(final TemplateInfo template) {
    final TemplateObject to = (TemplateObject) template;
    // update template_store_ref status
    to.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, to, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    to.getDataStore().getDriver().deleteAsync(to.getDataStore(), to, caller);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateObject(com.cloud.storage.image.store.TemplateObject) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 5 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method copyTemplate.

@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(final TemplateInfo srcTemplate, final DataStore destStore) {
    // generate a URL from source template ssvm to download to destination data store
    final String url = generateCopyUrl(srcTemplate);
    if (url == null) {
        s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
        throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
    }
    final TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting source template url to " + url);
    }
    tmplForCopy.setUrl(url);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Mark template_store_ref entry as Creating");
    }
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final DataObject templateOnStore = destStore.create(tmplForCopy);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
    }
    try {
        final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
        final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
        destStore.getDriver().createAsync(destStore, 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(destStore.getId(), srcTemplate.getId());
        if (templateStoreVO != null) {
            final TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

TemplateObject (com.cloud.storage.image.store.TemplateObject)8 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)3 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)3 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)3 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)3 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 CommandResult (com.cloud.storage.command.CommandResult)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1