clarified TemplateService comments
We will keep this abstractions as it's convenient, otherwise IngestDocument would depend on ScriptService directly, and would explicitly rely on mustache which is not even part of core. better to have the interface in core, and the impl as part of the ingest plugin, which relies on mustache, shipped with core by default.
This commit is contained in:
parent
fa4dbdaea1
commit
635b9b5a46
|
@ -21,10 +21,9 @@ package org.elasticsearch.ingest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstraction for the template engine.
|
* Abstraction for the ingest template engine: allows to compile a template into a {@link Template} object.
|
||||||
|
* A compiled template can be executed by calling its {@link Template#execute(Map)} method.
|
||||||
*/
|
*/
|
||||||
// NOTE: this abstraction is added because the 'org.elasticsearch.ingest' has the requirement to be ES agnostic
|
|
||||||
//TODO this abstraction could be removed once ingest-core is part of es core?
|
|
||||||
public interface TemplateService {
|
public interface TemplateService {
|
||||||
|
|
||||||
Template compile(String template);
|
Template compile(String template);
|
||||||
|
@ -34,7 +33,5 @@ public interface TemplateService {
|
||||||
String execute(Map<String, Object> model);
|
String execute(Map<String, Object> model);
|
||||||
|
|
||||||
String getKey();
|
String getKey();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,6 @@ public class IngestPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onModule(ScriptModule module) {
|
public void onModule(ScriptModule module) {
|
||||||
module.registerScriptContext(InternalTemplateService.INGEST_SCRIPT_CONTEXT);
|
module.registerScriptContext(MustacheTemplateService.INGEST_SCRIPT_CONTEXT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.elasticsearch.script.ScriptService;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class InternalTemplateService implements TemplateService {
|
class MustacheTemplateService implements TemplateService {
|
||||||
|
|
||||||
public static final ScriptContext.Plugin INGEST_SCRIPT_CONTEXT = new ScriptContext.Plugin("elasticsearch-ingest", "ingest");
|
public static final ScriptContext.Plugin INGEST_SCRIPT_CONTEXT = new ScriptContext.Plugin("elasticsearch-ingest", "ingest");
|
||||||
|
|
||||||
private final ScriptService scriptService;
|
private final ScriptService scriptService;
|
||||||
|
|
||||||
InternalTemplateService(ScriptService scriptService) {
|
MustacheTemplateService(ScriptService scriptService) {
|
||||||
this.scriptService = scriptService;
|
this.scriptService = scriptService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class PipelineStore extends AbstractComponent implements Closeable {
|
||||||
|
|
||||||
public void buildProcessorFactoryRegistry(Map<String, ProcessorFactoryProvider> processorFactoryProviders, Environment environment, ScriptService scriptService) {
|
public void buildProcessorFactoryRegistry(Map<String, ProcessorFactoryProvider> processorFactoryProviders, Environment environment, ScriptService scriptService) {
|
||||||
Map<String, Processor.Factory> processorFactories = new HashMap<>();
|
Map<String, Processor.Factory> processorFactories = new HashMap<>();
|
||||||
TemplateService templateService = new InternalTemplateService(scriptService);
|
TemplateService templateService = new MustacheTemplateService(scriptService);
|
||||||
for (Map.Entry<String, ProcessorFactoryProvider> entry : processorFactoryProviders.entrySet()) {
|
for (Map.Entry<String, ProcessorFactoryProvider> entry : processorFactoryProviders.entrySet()) {
|
||||||
Processor.Factory processorFactory = entry.getValue().get(environment, templateService);
|
Processor.Factory processorFactory = entry.getValue().get(environment, templateService);
|
||||||
processorFactories.put(entry.getKey(), processorFactory);
|
processorFactories.put(entry.getKey(), processorFactory);
|
||||||
|
|
|
@ -42,12 +42,12 @@ public abstract class AbstractMustacheTests extends ESTestCase {
|
||||||
.build();
|
.build();
|
||||||
MustacheScriptEngineService mustache = new MustacheScriptEngineService(settings);
|
MustacheScriptEngineService mustache = new MustacheScriptEngineService(settings);
|
||||||
ScriptContextRegistry registry = new ScriptContextRegistry(
|
ScriptContextRegistry registry = new ScriptContextRegistry(
|
||||||
Collections.singletonList(InternalTemplateService.INGEST_SCRIPT_CONTEXT)
|
Collections.singletonList(MustacheTemplateService.INGEST_SCRIPT_CONTEXT)
|
||||||
);
|
);
|
||||||
ScriptService scriptService = new ScriptService(
|
ScriptService scriptService = new ScriptService(
|
||||||
settings, new Environment(settings), Collections.singleton(mustache), null, registry
|
settings, new Environment(settings), Collections.singleton(mustache), null, registry
|
||||||
);
|
);
|
||||||
templateService = new InternalTemplateService(scriptService);
|
templateService = new MustacheTemplateService(scriptService);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue