Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
118de21
uhg
nik9000 Mar 2, 2017
4867848
I feel dirty
nik9000 Mar 3, 2017
085749b
Closer
nik9000 Mar 5, 2017
b5f16fd
Something I forgot:wq
nik9000 Mar 12, 2017
5b82a73
Merge branch 'master' into de_script_templates_1
nik9000 Mar 17, 2017
ea63c2d
Merge branch 'master' into de_script_templates_1
nik9000 Mar 17, 2017
58a5ad9
Line length
nik9000 Mar 20, 2017
e2e7f3d
Line length
nik9000 Mar 20, 2017
c5c9fbf
Merge branch 'master' into de_script_templates_1
nik9000 Mar 23, 2017
88be3a5
Fix file templates
nik9000 Mar 23, 2017
7df0a16
More tests
nik9000 Mar 23, 2017
6b36b43
Docs
nik9000 Mar 24, 2017
1471ebd
No more NOCOMMITs!
nik9000 Mar 24, 2017
b8f0f08
Last nocommit for real this time
nik9000 Mar 24, 2017
31d733f
TemplateService in createComponents
nik9000 Mar 24, 2017
706ca6d
Many renames
nik9000 Mar 24, 2017
e06738e
Migration notes for template/script split
nik9000 Mar 24, 2017
42fb904
Drop duplicate log message
nik9000 Mar 24, 2017
207e417
Remove leftover
nik9000 Mar 24, 2017
4d0b2f2
Implement contentType in TemplateService
nik9000 Mar 25, 2017
4051fe2
Notes
nik9000 Mar 25, 2017
0714889
Line length
nik9000 Mar 25, 2017
8d1165e
Remove logging guards
nik9000 Mar 27, 2017
f0d70bc
Remove leftover.
nik9000 Mar 27, 2017
eccf17d
Rename method
nik9000 Mar 27, 2017
6f00573
requireNonNull with messages
nik9000 Mar 27, 2017
ac1b823
Better comments in `checkCompileBeforeStore`
nik9000 Mar 27, 2017
9360cfa
No extension
nik9000 Mar 27, 2017
558b26b
Change exception type
nik9000 Mar 27, 2017
8a58c24
Some javadoc
nik9000 Mar 27, 2017
d7ff55b
More javadocs
nik9000 Mar 27, 2017
f74d9d6
Drop funny parsing for scripts that should only be there for templates
nik9000 Mar 27, 2017
cdecc35
Move null checks for stored templates or scripts
nik9000 Mar 27, 2017
83aacce
Code reuse
nik9000 Mar 27, 2017
1d16334
Javadocs
nik9000 Mar 27, 2017
2f1c935
StringBuilder
nik9000 Mar 27, 2017
b6f9cd5
Messages
nik9000 Mar 27, 2017
8318393
Fix comment
nik9000 Mar 27, 2017
7ab675d
Fix warning message
nik9000 Mar 27, 2017
c9bb0b0
Fix broken tests
nik9000 Mar 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]IngestDocumentTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]IngestMetadataTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]IngestProcessorNotInstalledOnAllNodesIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]IngestServiceTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]IngestStatsTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]PipelineConfigurationTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ingest[/\\]PipelineExecutionServiceTests.java" checks="LineLength" />
Expand Down Expand Up @@ -3048,7 +3047,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptMetaDataTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptModesTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptServiceTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptSettingsTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]StoredScriptTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]StoredScriptsIT.java" checks="LineLength" />
Expand Down
31 changes: 15 additions & 16 deletions core/src/main/java/org/elasticsearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.apache.lucene.util.SetOnce;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.TriFunction;
import org.elasticsearch.common.settings.Setting;
Expand Down Expand Up @@ -50,6 +49,7 @@
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.TemplateService;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.IOException;
Expand Down Expand Up @@ -320,20 +320,19 @@ public interface IndexSearcherWrapperFactory {
}

public IndexService newIndexService(
NodeEnvironment environment,
NamedXContentRegistry xContentRegistry,
IndexService.ShardStoreDeleter shardStoreDeleter,
CircuitBreakerService circuitBreakerService,
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
ClusterService clusterService,
Client client,
IndicesQueryCache indicesQueryCache,
MapperRegistry mapperRegistry,
Consumer<ShardId> globalCheckpointSyncer,
IndicesFieldDataCache indicesFieldDataCache)
throws IOException {
NodeEnvironment environment,
NamedXContentRegistry xContentRegistry,
IndexService.ShardStoreDeleter shardStoreDeleter,
CircuitBreakerService circuitBreakerService,
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
TemplateService templateService,
Client client,
IndicesQueryCache indicesQueryCache,
MapperRegistry mapperRegistry,
Consumer<ShardId> globalCheckpointSyncer,
IndicesFieldDataCache indicesFieldDataCache) throws IOException {
final IndexEventListener eventListener = freeze();
IndexSearcherWrapperFactory searcherWrapperFactory = indexSearcherWrapper.get() == null
? (shard) -> null : indexSearcherWrapper.get();
Expand Down Expand Up @@ -365,7 +364,7 @@ public IndexService newIndexService(
}
return new IndexService(indexSettings, environment, xContentRegistry, new SimilarityService(indexSettings, similarities),
shardStoreDeleter, analysisRegistry, engineFactory.get(), circuitBreakerService, bigArrays, threadPool, scriptService,
clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
templateService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry,
indicesFieldDataCache, globalCheckpointSyncer, searchOperationListeners, indexOperationListeners);
}

Expand Down
17 changes: 12 additions & 5 deletions core/src/main/java/org/elasticsearch/index/IndexService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -68,6 +67,7 @@
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.TemplateService;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.Closeable;
Expand Down Expand Up @@ -118,7 +118,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
private final BigArrays bigArrays;
private final AsyncGlobalCheckpointTask globalCheckpointTask;
private final ScriptService scriptService;
private final ClusterService clusterService;
private final TemplateService templateService;
private final Client client;

public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
Expand All @@ -131,7 +131,7 @@ public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
BigArrays bigArrays,
ThreadPool threadPool,
ScriptService scriptService,
ClusterService clusterService,
TemplateService templateService,
Client client,
QueryCache queryCache,
IndexStore indexStore,
Expand All @@ -158,7 +158,7 @@ public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
this.bigArrays = bigArrays;
this.threadPool = threadPool;
this.scriptService = scriptService;
this.clusterService = clusterService;
this.templateService = templateService;
this.client = client;
this.eventListener = eventListener;
this.nodeEnv = nodeEnv;
Expand Down Expand Up @@ -473,7 +473,7 @@ public IndexSettings getIndexSettings() {
public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis) {
return new QueryShardContext(
shardId, indexSettings, indexCache.bitsetFilterCache(), indexFieldData, mapperService(),
similarityService(), scriptService, xContentRegistry,
similarityService(), scriptService, templateService, xContentRegistry,
client, indexReader,
nowInMillis);
}
Expand All @@ -499,6 +499,13 @@ public ScriptService getScriptService() {
return scriptService;
}

/**
* The {@link TemplateService} to use for this index.
*/
public TemplateService getTemplateService() {
return templateService;
}

List<IndexingOperationListener> getIndexOperationListeners() { // pkg private for testing
return indexingOperationListeners;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.TemplateService;

import java.util.function.LongSupplier;

Expand All @@ -38,17 +38,19 @@
public class QueryRewriteContext {
protected final MapperService mapperService;
protected final ScriptService scriptService;
private final TemplateService templateService;
protected final IndexSettings indexSettings;
private final NamedXContentRegistry xContentRegistry;
protected final Client client;
protected final IndexReader reader;
protected final LongSupplier nowInMillis;

public QueryRewriteContext(IndexSettings indexSettings, MapperService mapperService, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, Client client, IndexReader reader,
TemplateService templateService, NamedXContentRegistry xContentRegistry, Client client, IndexReader reader,
LongSupplier nowInMillis) {
this.mapperService = mapperService;
this.scriptService = scriptService;
this.templateService = templateService;
this.indexSettings = indexSettings;
this.xContentRegistry = xContentRegistry;
this.client = client;
Expand Down Expand Up @@ -104,7 +106,17 @@ public long nowInMillis() {
}

public BytesReference getTemplateBytes(Script template) {
ExecutableScript executable = scriptService.executable(template, ScriptContext.Standard.SEARCH);
return (BytesReference) executable.run();
return templateService
.template(template.getIdOrCode(), template.getType(),
ScriptContext.Standard.SEARCH, null)
.apply(template.getParams());
}

public ScriptService getScriptService() {
return scriptService;
}

public TemplateService getTemplateService() {
return templateService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.SearchScript;
import org.elasticsearch.script.TemplateService;
import org.elasticsearch.search.lookup.SearchLookup;

import java.io.IOException;
Expand Down Expand Up @@ -100,9 +101,9 @@ public String[] getTypes() {

public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
IndexFieldDataService indexFieldDataService, MapperService mapperService, SimilarityService similarityService,
ScriptService scriptService, NamedXContentRegistry xContentRegistry,
ScriptService scriptService, TemplateService templateService, NamedXContentRegistry xContentRegistry,
Client client, IndexReader reader, LongSupplier nowInMillis) {
super(indexSettings, mapperService, scriptService, xContentRegistry, client, reader, nowInMillis);
super(indexSettings, mapperService, scriptService, templateService, xContentRegistry, client, reader, nowInMillis);
this.shardId = shardId;
this.indexSettings = indexSettings;
this.similarityService = similarityService;
Expand All @@ -116,7 +117,7 @@ public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterC

public QueryShardContext(QueryShardContext source) {
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService,
source.similarityService, source.scriptService, source.getXContentRegistry(), source.client,
source.similarityService, source.scriptService, source.getTemplateService(), source.getXContentRegistry(), source.client,
source.reader, source.nowInMillis);
this.types = source.getTypes();
}
Expand Down Expand Up @@ -355,13 +356,14 @@ public final ExecutableScript getExecutableScript(Script script, ScriptContext c
}

/**
* Returns a lazily created {@link ExecutableScript} that is compiled immediately but can be pulled later once all
* parameters are available.
* Returns {@link Function} representing a script that is compiled immediately but can be pulled
* later once all parameters are available.
*/
public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(Script script, ScriptContext context) {
public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(
Script script, ScriptContext context) {
failIfFrozen();
CompiledScript executable = scriptService.compile(script, context);
return (p) -> scriptService.executable(executable, p);
return (p) -> scriptService.executable(executable, p);
}

/**
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/java/org/elasticsearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.routing.RecoverySource;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.breaker.CircuitBreaker;
Expand Down Expand Up @@ -110,6 +109,7 @@
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.TemplateService;
import org.elasticsearch.search.internal.AliasFilter;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.internal.ShardSearchRequest;
Expand All @@ -121,7 +121,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -162,7 +161,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final CircuitBreakerService circuitBreakerService;
private final BigArrays bigArrays;
private final ScriptService scriptService;
private final ClusterService clusterService;
private final TemplateService templateService;
private final Client client;
private volatile Map<String, IndexService> indices = emptyMap();
private final Map<Index, List<PendingDelete>> pendingDeletes = new HashMap<>();
Expand All @@ -187,7 +186,7 @@ public IndicesService(Settings settings, PluginsService pluginsService, NodeEnvi
IndexNameExpressionResolver indexNameExpressionResolver,
MapperRegistry mapperRegistry, NamedWriteableRegistry namedWriteableRegistry,
ThreadPool threadPool, IndexScopedSettings indexScopedSettings, CircuitBreakerService circuitBreakerService,
BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService, Client client,
BigArrays bigArrays, ScriptService scriptService, TemplateService templateService, Client client,
Copy link
Member Author

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....

MetaStateService metaStateService) {
super(settings);
this.threadPool = threadPool;
Expand All @@ -208,7 +207,7 @@ public IndicesService(Settings settings, PluginsService pluginsService, NodeEnvi
this.circuitBreakerService = circuitBreakerService;
this.bigArrays = bigArrays;
this.scriptService = scriptService;
this.clusterService = clusterService;
this.templateService = templateService;
this.client = client;
this.indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {
@Override
Expand Down Expand Up @@ -447,7 +446,7 @@ private synchronized IndexService createIndexService(final String reason,
bigArrays,
threadPool,
scriptService,
clusterService,
templateService,
client,
indicesQueryCache,
mapperRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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 ScriptTemplateService or the ingest one to IngestTemplateService, not sure how large a change that would be though.

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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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 IngestTemplateService if you don't think that'd be too disruptive?

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand Down
Loading