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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations