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