Search in sources :

Example 6 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 long templateId, final DataStore store) {
    final VMTemplateVO templ = imageDataDao.findById(templateId);
    if (store == null) {
        final TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
        return tmpl;
    }
    // verify if the given input parameters are consistent with our db data.
    boolean found = false;
    if (store.getRole() == DataStoreRole.Primary) {
        final VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId);
        if (templatePoolVO != null) {
            found = true;
        }
    } else {
        final TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(store.getId(), templateId);
        if (templateStoreVO != null) {
            found = true;
        }
    }
    if (s_logger.isDebugEnabled()) {
        if (!found) {
            s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
        } else {
            s_logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole());
        }
    }
    final TemplateObject tmpl = TemplateObject.getTemplate(templ, store);
    return tmpl;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 7 with TemplateObject

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

the class TemplateServiceImpl method deleteTemplateCallback.

public Void deleteTemplateCallback(final AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final CommandResult result = callback.getResult();
    final TemplateObject vo = context.getTemplate();
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed);
    } else {
        vo.processEvent(Event.OperationFailed);
    }
    final TemplateApiResult apiResult = new TemplateApiResult(vo);
    apiResult.setResult(result.getResult());
    apiResult.setSuccess(result.isSuccess());
    context.future.complete(apiResult);
    return null;
}
Also used : CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 8 with TemplateObject

use of com.cloud.storage.image.store.TemplateObject 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

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