-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Begin to break templates away from scripts #23744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
118de21
4867848
085749b
b5f16fd
5b82a73
ea63c2d
58a5ad9
e2e7f3d
c5c9fbf
88be3a5
7df0a16
6b36b43
1471ebd
b8f0f08
31d733f
706ca6d
e06738e
42fb904
207e417
4d0b2f2
4051fe2
0714889
8d1165e
f0d70bc
eccf17d
6f00573
ac1b823
9360cfa
558b26b
8a58c24
d7ff55b
f74d9d6
cdecc35
83aacce
1d16334
2f1c935
b6f9cd5
8318393
7ab675d
c9bb0b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,12 @@ public class IngestService { | |
| private final PipelineStore pipelineStore; | ||
| private final PipelineExecutionService pipelineExecutionService; | ||
|
|
||
| public IngestService(Settings settings, ThreadPool threadPool, | ||
| Environment env, ScriptService scriptService, AnalysisRegistry analysisRegistry, | ||
| public IngestService(Settings settings, ThreadPool threadPool, Environment env, | ||
| org.elasticsearch.script.TemplateService esTemplateService, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unfortunate that we have an overlap here in class names :( I'm tempted to suggest renaming it to |
||
| ScriptService scriptService, AnalysisRegistry analysisRegistry, | ||
| List<IngestPlugin> ingestPlugins) { | ||
|
|
||
| final TemplateService templateService = new InternalTemplateService(scriptService); | ||
| final TemplateService templateService = new InternalTemplateService(esTemplateService); | ||
| Processor.Parameters parameters = new Processor.Parameters(env, scriptService, templateService, | ||
| analysisRegistry, threadPool.getThreadContext()); | ||
| Map<String, Processor.Factory> processorFactories = new HashMap<>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,40 +20,31 @@ | |
| package org.elasticsearch.ingest; | ||
|
|
||
| import org.elasticsearch.common.bytes.BytesReference; | ||
| import org.elasticsearch.script.CompiledScript; | ||
| import org.elasticsearch.script.ExecutableScript; | ||
| import org.elasticsearch.script.Script; | ||
| import org.elasticsearch.script.ScriptContext; | ||
| import org.elasticsearch.script.ScriptService; | ||
| import org.elasticsearch.script.ScriptType; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
|
|
||
| public class InternalTemplateService implements TemplateService { | ||
|
|
||
| private final ScriptService scriptService; | ||
| private final org.elasticsearch.script.TemplateService templateService; | ||
|
|
||
| InternalTemplateService(ScriptService scriptService) { | ||
| this.scriptService = scriptService; | ||
| InternalTemplateService(org.elasticsearch.script.TemplateService templateService) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is really ugly and prone to mistakes, I'm in favor of renaming the ingest version to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea, yeah. |
||
| this.templateService = templateService; | ||
| } | ||
|
|
||
| @Override | ||
| public Template compile(String template) { | ||
| int mustacheStart = template.indexOf("{{"); | ||
| int mustacheEnd = template.indexOf("}}"); | ||
| if (mustacheStart != -1 && mustacheEnd != -1 && mustacheStart < mustacheEnd) { | ||
| Script script = new Script(ScriptType.INLINE, "mustache", template, Collections.emptyMap()); | ||
| CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.INGEST); | ||
| Function<Map<String, Object>, BytesReference> compiled = templateService.template( | ||
| template, ScriptType.INLINE, ScriptContext.Standard.INGEST, null); | ||
| return new Template() { | ||
| @Override | ||
| public String execute(Map<String, Object> model) { | ||
| ExecutableScript executableScript = scriptService.executable(compiledScript, model); | ||
| Object result = executableScript.run(); | ||
| if (result instanceof BytesReference) { | ||
| return ((BytesReference) result).utf8ToString(); | ||
| } | ||
| return String.valueOf(result); | ||
| return compiled.apply(model).utf8ToString(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't actually need ClusterService....