Search in sources :

Example 1 with TemplateObject

use of org.apache.cloudstack.storage.image.store.TemplateObject in project cloudstack by apache.

the class VolumeServiceImpl method createManagedTemplateImageCallback.

protected Void createManagedTemplateImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<CreateCmdResult> context) {
    CreateCmdResult result = callback.getResult();
    VolumeApiResult res = new VolumeApiResult(null);
    res.setResult(result.getResult());
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    DataObject templateOnPrimaryStoreObj = context.getVolume();
    if (result.isSuccess()) {
        ((TemplateObject) templateOnPrimaryStoreObj).setInstallPath(result.getPath());
        templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
    }
    future.complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 2 with TemplateObject

use of org.apache.cloudstack.storage.image.store.TemplateObject in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateCallback.

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

Example 3 with TemplateObject

use of org.apache.cloudstack.storage.image.store.TemplateObject in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateOnPrimary.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateOnPrimary(TemplateInfo template, StoragePool pool) {
    TemplateObject templateObject = (TemplateObject) _templateFactory.getTemplate(template.getId(), (DataStore) pool);
    templateObject.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    DataStore dataStore = _storeMgr.getPrimaryDataStore(pool.getId());
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, templateObject, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    dataStore.getDriver().deleteAsync(dataStore, templateObject, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 4 with TemplateObject

use of org.apache.cloudstack.storage.image.store.TemplateObject in project cloudstack by apache.

the class TemplateServiceImpl method createTemplateCallback.

protected Void createTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
    TemplateObject template = context.getTemplate();
    AsyncCompletionCallback<TemplateApiResult> parentCallback = context.getParentCallback();
    TemplateApiResult result = new TemplateApiResult(template);
    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 (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(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 5 with TemplateObject

use of org.apache.cloudstack.storage.image.store.TemplateObject in project cloudstack by apache.

the class TemplateDataFactoryImpl method getTemplate.

@Override
public TemplateInfo getTemplate(DataObject obj, DataStore store) {
    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
    TemplateObject origTmpl = (TemplateObject) obj;
    tmpObj.setUrl(origTmpl.getUrl());
    return tmpObj;
}
Also used : TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Aggregations

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