mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
Scripting: Remove "inline script enabled" on script engines (#24815)
ScriptEngine implementations have an overridable method to indicate they are safe to use as inline scripts. Since groovy was removed fro 6.0, there are no longer any implementations which used the default false value. Furthermore, the value was not actually read anywhere. This commit removes the method. The ScriptEngineRegistry was also no longer necessary as it only was used to build a map from language to engine.
This commit is contained in:
parent
a5358f34b3
commit
2de748859f
@ -48,11 +48,4 @@ public interface ScriptEngine extends Closeable {
|
||||
ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars);
|
||||
|
||||
SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars);
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this scripting engine can safely accept inline scripts by default. The default is <code>false</code>
|
||||
*/
|
||||
default boolean isInlineScriptEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptEngineRegistry {
|
||||
|
||||
private final Map<Class<? extends ScriptEngine>, String> registeredScriptEngineServices;
|
||||
private final Map<String, ScriptEngine> registeredLanguages;
|
||||
private final Map<String, Boolean> defaultInlineScriptEnableds;
|
||||
|
||||
public ScriptEngineRegistry(Iterable<ScriptEngine> registrations) {
|
||||
Objects.requireNonNull(registrations);
|
||||
Map<Class<? extends ScriptEngine>, String> registeredScriptEngineServices = new HashMap<>();
|
||||
Map<String, ScriptEngine> registeredLanguages = new HashMap<>();
|
||||
Map<String, Boolean> inlineScriptEnableds = new HashMap<>();
|
||||
for (ScriptEngine service : registrations) {
|
||||
String oldLanguage = registeredScriptEngineServices.putIfAbsent(service.getClass(),
|
||||
service.getType());
|
||||
if (oldLanguage != null) {
|
||||
throw new IllegalArgumentException("script engine service [" + service.getClass() +
|
||||
"] already registered for language [" + oldLanguage + "]");
|
||||
}
|
||||
String language = service.getType();
|
||||
ScriptEngine scriptEngine =
|
||||
registeredLanguages.putIfAbsent(language, service);
|
||||
if (scriptEngine != null) {
|
||||
throw new IllegalArgumentException("scripting language [" + language + "] already registered for script engine service [" +
|
||||
scriptEngine.getClass().getCanonicalName() + "]");
|
||||
}
|
||||
inlineScriptEnableds.put(language, service.isInlineScriptEnabled());
|
||||
}
|
||||
|
||||
this.registeredScriptEngineServices = Collections.unmodifiableMap(registeredScriptEngineServices);
|
||||
this.registeredLanguages = Collections.unmodifiableMap(registeredLanguages);
|
||||
this.defaultInlineScriptEnableds = Collections.unmodifiableMap(inlineScriptEnableds);
|
||||
}
|
||||
|
||||
Iterable<Class<? extends ScriptEngine>> getRegisteredScriptEngineServices() {
|
||||
return registeredScriptEngineServices.keySet();
|
||||
}
|
||||
|
||||
String getLanguage(Class<? extends ScriptEngine> scriptEngineService) {
|
||||
Objects.requireNonNull(scriptEngineService);
|
||||
return registeredScriptEngineServices.get(scriptEngineService);
|
||||
}
|
||||
|
||||
public Map<String, ScriptEngine> getRegisteredLanguages() {
|
||||
return registeredLanguages;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getDefaultInlineScriptEnableds() {
|
||||
return this.defaultInlineScriptEnableds;
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,10 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.ScriptPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -52,14 +55,26 @@ public class ScriptModule {
|
||||
public ScriptModule(Settings settings, List<ScriptEngine> scriptEngines,
|
||||
List<ScriptContext.Plugin> customScriptContexts) {
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts);
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngines);
|
||||
Map<String, ScriptEngine> enginesByName = getEnginesByName(scriptEngines);
|
||||
try {
|
||||
scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
|
||||
scriptService = new ScriptService(settings, enginesByName, scriptContextRegistry);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Couldn't setup ScriptService", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ScriptEngine> getEnginesByName(List<ScriptEngine> engines) {
|
||||
Map<String, ScriptEngine> enginesByName = new HashMap<>();
|
||||
for (ScriptEngine engine : engines) {
|
||||
ScriptEngine existing = enginesByName.put(engine.getType(), engine);
|
||||
if (existing != null) {
|
||||
throw new IllegalArgumentException("scripting language [" + engine.getType() + "] defined for engine [" +
|
||||
existing.getClass().getName() + "] and [" + engine.getClass().getName());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(enginesByName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service responsible for managing scripts.
|
||||
*/
|
||||
|
@ -96,11 +96,11 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
||||
private double scriptsPerMinCounter;
|
||||
private double compilesAllowedPerNano;
|
||||
|
||||
public ScriptService(Settings settings, ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) throws IOException {
|
||||
public ScriptService(Settings settings, Map<String, ScriptEngine> engines, ScriptContextRegistry scriptContextRegistry) throws IOException {
|
||||
super(settings);
|
||||
|
||||
Objects.requireNonNull(settings);
|
||||
Objects.requireNonNull(scriptEngineRegistry);
|
||||
this.engines = Objects.requireNonNull(engines);
|
||||
Objects.requireNonNull(scriptContextRegistry);
|
||||
|
||||
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
|
||||
@ -192,8 +192,6 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
|
||||
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);
|
||||
this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();
|
||||
|
||||
this.engines = scriptEngineRegistry.getRegisteredLanguages();
|
||||
|
||||
this.lastInlineCompileTime = System.nanoTime();
|
||||
this.setMaxCompilationsPerMinute(SCRIPT_MAX_COMPILATIONS_PER_MINUTE.get(settings));
|
||||
}
|
||||
|
@ -43,12 +43,10 @@ import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.RandomObjects;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -60,7 +58,6 @@ import java.util.function.Function;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
|
||||
import static org.elasticsearch.script.MockScriptEngine.mockInlineScript;
|
||||
@ -140,14 +137,10 @@ public class UpdateRequestTests extends ESTestCase {
|
||||
scripts.put("return", vars -> null);
|
||||
final ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(emptyList());
|
||||
final MockScriptEngine engine = new MockScriptEngine("mock", scripts);
|
||||
final ScriptEngineRegistry scriptEngineRegistry =
|
||||
new ScriptEngineRegistry(singletonList(engine));
|
||||
|
||||
final ResourceWatcherService watcherService =
|
||||
new ResourceWatcherService(baseSettings, null);
|
||||
ScriptService scriptService = new ScriptService(
|
||||
baseSettings,
|
||||
scriptEngineRegistry,
|
||||
Collections.singletonMap(engine.getType(), engine),
|
||||
scriptContextRegistry);
|
||||
final Settings settings = settings(Version.CURRENT).build();
|
||||
|
||||
|
@ -68,7 +68,6 @@ import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedInd
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
import org.elasticsearch.indices.mapper.MapperRegistry;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.ClusterServiceUtils;
|
||||
@ -78,14 +77,12 @@ import org.elasticsearch.test.TestSearchContext;
|
||||
import org.elasticsearch.test.engine.MockEngineFactory;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
||||
public class IndexModuleTests extends ESTestCase {
|
||||
@ -128,9 +125,8 @@ public class IndexModuleTests extends ESTestCase {
|
||||
threadPool = new TestThreadPool("test");
|
||||
circuitBreakerService = new NoneCircuitBreakerService();
|
||||
bigArrays = new BigArrays(settings, circuitBreakerService);
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList());
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
|
||||
scriptService = new ScriptService(settings, Collections.emptyMap(), scriptContextRegistry);
|
||||
clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
nodeEnvironment = new NodeEnvironment(settings, environment);
|
||||
mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
|
||||
|
@ -30,6 +30,7 @@ import org.elasticsearch.test.ESTestCase;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScriptContextTests extends ESTestCase {
|
||||
|
||||
@ -42,13 +43,13 @@ public class ScriptContextTests extends ESTestCase {
|
||||
.build();
|
||||
|
||||
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"));
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
|
||||
Map<String, ScriptEngine> engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine);
|
||||
List<ScriptContext.Plugin> customContexts = Arrays.asList(
|
||||
new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"),
|
||||
new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"),
|
||||
new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
|
||||
ScriptService scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
|
||||
ScriptService scriptService = new ScriptService(settings, engines, scriptContextRegistry);
|
||||
|
||||
ClusterState empty = ClusterState.builder(new ClusterName("_name")).build();
|
||||
ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE);
|
||||
|
@ -54,8 +54,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
private ScriptEngine scriptEngine;
|
||||
private ScriptEngine dangerousScriptEngine;
|
||||
private Map<String, ScriptEngine> scriptEnginesByLangMap;
|
||||
private ScriptEngineRegistry scriptEngineRegistry;
|
||||
private Map<String, ScriptEngine> engines;
|
||||
private ScriptContextRegistry scriptContextRegistry;
|
||||
private ScriptContext[] scriptContexts;
|
||||
private ScriptService scriptService;
|
||||
@ -77,7 +76,6 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
.put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 10000)
|
||||
.build();
|
||||
scriptEngine = new TestEngine();
|
||||
dangerousScriptEngine = new TestDangerousEngine();
|
||||
TestEngine defaultScriptServiceEngine = new TestEngine(Script.DEFAULT_SCRIPT_LANG) {};
|
||||
//randomly register custom script contexts
|
||||
int randomInt = randomIntBetween(0, 3);
|
||||
@ -95,8 +93,9 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
String context = plugin + "_" + operation;
|
||||
contexts.put(context, new ScriptContext.Plugin(plugin, operation));
|
||||
}
|
||||
scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(scriptEngine, dangerousScriptEngine,
|
||||
defaultScriptServiceEngine));
|
||||
engines = new HashMap<>();
|
||||
engines.put(scriptEngine.getType(), scriptEngine);
|
||||
engines.put(defaultScriptServiceEngine.getType(), defaultScriptServiceEngine);
|
||||
scriptContextRegistry = new ScriptContextRegistry(contexts.values());
|
||||
scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
|
||||
logger.info("--> setup script service");
|
||||
@ -104,7 +103,7 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
|
||||
private void buildScriptService(Settings additionalSettings) throws IOException {
|
||||
Settings finalSettings = Settings.builder().put(baseSettings).put(additionalSettings).build();
|
||||
scriptService = new ScriptService(finalSettings, scriptEngineRegistry, scriptContextRegistry) {
|
||||
scriptService = new ScriptService(finalSettings, engines, scriptContextRegistry) {
|
||||
@Override
|
||||
StoredScriptSource getScriptFromClusterState(String id, String lang) {
|
||||
//mock the script that gets retrieved from an index
|
||||
@ -388,39 +387,5 @@ public class ScriptServiceTests extends ESTestCase {
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestDangerousEngine implements ScriptEngine {
|
||||
|
||||
public static final String NAME = "dtest";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
|
||||
return "compiled_" + scriptSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutableScript executable(final CompiledScript compiledScript, @Nullable Map<String, Object> vars) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -588,10 +588,5 @@ public class AvgIT extends AbstractNumericTestCase {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -491,11 +491,6 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -597,10 +592,5 @@ public class SumIT extends AbstractNumericTestCase {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,10 +344,5 @@ public class ValueCountIT extends ESIntegTestCase {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,9 @@ package org.elasticsearch.search.aggregations.metrics.scripted;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||
@ -72,10 +70,9 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
|
||||
Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> {
|
||||
return ((List<Object>) script.get("_aggs")).size();
|
||||
}));
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
try {
|
||||
return new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry);
|
||||
return new ScriptService(Settings.EMPTY, Collections.singletonMap(scriptEngine.getType(), scriptEngine), scriptContextRegistry);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException(e);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
@ -36,7 +35,7 @@ import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.ScoreAccessor;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptEngine;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.aggregations.AggregatorTestCase;
|
||||
@ -198,11 +197,11 @@ public class ScriptedMetricAggregatorTests extends AggregatorTestCase {
|
||||
protected QueryShardContext queryShardContextMock(MapperService mapperService, final MappedFieldType[] fieldTypes,
|
||||
CircuitBreakerService circuitBreakerService) {
|
||||
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS);
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
|
||||
Map<String, ScriptEngine> engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine);
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
ScriptService scriptService;
|
||||
try {
|
||||
scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry);
|
||||
scriptService = new ScriptService(Settings.EMPTY, engines, scriptContextRegistry);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException(e);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptEngine;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptServiceTests.TestEngine;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
@ -62,7 +62,6 @@ import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.IndexSettingsModule;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
@ -89,8 +88,8 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
|
||||
.put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder)
|
||||
.build();
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngine()));
|
||||
scriptService = new ScriptService(baseSettings, scriptEngineRegistry, scriptContextRegistry) {
|
||||
ScriptEngine engine = new TestEngine();
|
||||
scriptService = new ScriptService(baseSettings, Collections.singletonMap(engine.getType(), engine), scriptContextRegistry) {
|
||||
@Override
|
||||
public CompiledScript compile(Script script, ScriptContext scriptContext) {
|
||||
return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);
|
||||
|
@ -1059,11 +1059,6 @@ public class SuggestSearchIT extends ESIntegTestCase {
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
throw new UnsupportedOperationException("search script not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void testPhraseSuggesterCollate() throws InterruptedException, ExecutionException, IOException {
|
||||
|
@ -132,11 +132,6 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FieldIncrementScriptPlugin extends Plugin implements ScriptPlugin {
|
||||
@ -193,11 +188,6 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScriptedUpsertScriptPlugin extends Plugin implements ScriptPlugin {
|
||||
@ -254,12 +244,6 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ExtractContextInSourceScriptPlugin extends Plugin implements ScriptPlugin {
|
||||
@ -317,11 +301,6 @@ public class UpdateIT extends ESIntegTestCase {
|
||||
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -255,9 +255,4 @@ public class ExpressionScriptEngine extends AbstractComponent implements ScriptE
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +142,4 @@ public final class MustacheScriptEngine implements ScriptEngine {
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -264,9 +264,4 @@ public final class PainlessScriptEngine extends AbstractComponent implements Scr
|
||||
private int getNextStatement(String scriptSource, int offset) {
|
||||
return Math.min(scriptSource.length(), offset + 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -133,11 +133,6 @@ public class ExpertScriptPlugin extends Plugin implements ScriptPlugin {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
@ -21,13 +21,14 @@ package org.elasticsearch.ingest;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ScriptContextRegistry;
|
||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
||||
import org.elasticsearch.script.ScriptEngine;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.mustache.MustacheScriptEngine;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractScriptTestCase extends ESTestCase {
|
||||
|
||||
@ -35,9 +36,10 @@ public abstract class AbstractScriptTestCase extends ESTestCase {
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new MustacheScriptEngine()));
|
||||
MustacheScriptEngine engine = new MustacheScriptEngine();
|
||||
Map<String, ScriptEngine> engines = Collections.singletonMap(engine.getType(), engine);
|
||||
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
|
||||
ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry);
|
||||
ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, scriptContextRegistry);
|
||||
templateService = new InternalTemplateService(scriptService);
|
||||
}
|
||||
|
||||
|
@ -94,12 +94,6 @@ public class MockScriptEngine implements ScriptEngine {
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineScriptEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public class MockCompiledScript {
|
||||
|
||||
private final String name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user