diff --git a/core/src/main/java/org/elasticsearch/common/settings/Setting.java b/core/src/main/java/org/elasticsearch/common/settings/Setting.java index 1efb65c18b1..1be1fa8f3f4 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -537,6 +537,10 @@ public class Setting extends ToXContentToBytes { return new Setting<>(key, fallbackSetting, Booleans::parseBooleanExact, properties); } + public static Setting boolSetting(String key, Function defaultValueFn, Property... properties) { + return new Setting<>(key, defaultValueFn, Booleans::parseBooleanExact, properties); + } + public static Setting byteSizeSetting(String key, String percentage, Property... properties) { return new Setting<>(key, (s) -> percentage, (s) -> MemorySizeValue.parseBytesSizeValueOrHeapRatio(s, key), properties); } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java b/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java index 226fd7b6c34..31ff9ac0b61 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java @@ -30,13 +30,13 @@ public class ScriptEngineRegistry { private final Map, String> registeredScriptEngineServices; private final Map> registeredLanguages; - private final Map defaultInlineScriptModes; + private final Map defaultInlineScriptEnableds; public ScriptEngineRegistry(Iterable registrations) { Objects.requireNonNull(registrations); Map, String> registeredScriptEngineServices = new HashMap<>(); Map> registeredLanguages = new HashMap<>(); - Map inlineScriptModes = new HashMap<>(); + Map inlineScriptEnableds = new HashMap<>(); for (ScriptEngineRegistration registration : registrations) { String oldLanguage = registeredScriptEngineServices.putIfAbsent(registration.getScriptEngineService(), registration.getScriptEngineLanguage()); @@ -51,12 +51,12 @@ public class ScriptEngineRegistry { throw new IllegalArgumentException("scripting language [" + language + "] already registered for script engine service [" + scriptEngineServiceClazz.getCanonicalName() + "]"); } - inlineScriptModes.put(language, registration.getDefaultInlineScriptMode()); + inlineScriptEnableds.put(language, registration.getDefaultInlineScriptEnabled()); } this.registeredScriptEngineServices = Collections.unmodifiableMap(registeredScriptEngineServices); this.registeredLanguages = Collections.unmodifiableMap(registeredLanguages); - this.defaultInlineScriptModes = Collections.unmodifiableMap(inlineScriptModes); + this.defaultInlineScriptEnableds = Collections.unmodifiableMap(inlineScriptEnableds); } Iterable> getRegisteredScriptEngineServices() { @@ -72,27 +72,27 @@ public class ScriptEngineRegistry { return registeredLanguages; } - Map getDefaultInlineScriptModes() { - return this.defaultInlineScriptModes; + Map getDefaultInlineScriptEnableds() { + return this.defaultInlineScriptEnableds; } public static class ScriptEngineRegistration { private final Class scriptEngineService; private final String scriptEngineLanguage; - private final ScriptMode defaultInlineScriptMode; + private final boolean defaultInlineScriptEnabled; /** * Register a script engine service with the default of inline scripts disabled */ public ScriptEngineRegistration(Class scriptEngineService, String scriptEngineLanguage) { - this(scriptEngineService, scriptEngineLanguage, ScriptMode.OFF); + this(scriptEngineService, scriptEngineLanguage, false); } /** * Register a script engine service with the given default mode for inline scripts */ public ScriptEngineRegistration(Class scriptEngineService, String scriptEngineLanguage, - ScriptMode defaultInlineScriptMode) { + boolean defaultInlineScriptEnabled) { Objects.requireNonNull(scriptEngineService); if (Strings.hasText(scriptEngineLanguage) == false) { throw new IllegalArgumentException("languages for script engine service [" + @@ -100,7 +100,7 @@ public class ScriptEngineRegistry { } this.scriptEngineService = scriptEngineService; this.scriptEngineLanguage = scriptEngineLanguage; - this.defaultInlineScriptMode = defaultInlineScriptMode; + this.defaultInlineScriptEnabled = defaultInlineScriptEnabled; } Class getScriptEngineService() { @@ -111,8 +111,8 @@ public class ScriptEngineRegistry { return scriptEngineLanguage; } - ScriptMode getDefaultInlineScriptMode() { - return defaultInlineScriptMode; + boolean getDefaultInlineScriptEnabled() { + return defaultInlineScriptEnabled; } } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptMode.java b/core/src/main/java/org/elasticsearch/script/ScriptMode.java deleted file mode 100644 index 6508d2f1015..00000000000 --- a/core/src/main/java/org/elasticsearch/script/ScriptMode.java +++ /dev/null @@ -1,64 +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.HashMap; -import java.util.Map; - -/** - * Mode for a specific script, used for script settings. - * Defines whether a certain script or category of scripts can be executed or not. - */ -public enum ScriptMode { - ON("true"), - OFF("false"); - - private final String mode; - - ScriptMode(String mode) { - this.mode = mode; - } - - private static final Map SCRIPT_MODES; - - static { - SCRIPT_MODES = new HashMap<>(); - for (ScriptMode scriptMode : ScriptMode.values()) { - SCRIPT_MODES.put(scriptMode.mode, scriptMode); - } - } - - static ScriptMode parse(String input) { - ScriptMode scriptMode = SCRIPT_MODES.get(input); - if (scriptMode == null) { - throw new IllegalArgumentException("script mode [" + input + "] not supported"); - } - return scriptMode; - } - - public String getMode() { - return mode; - } - - @Override - public String toString() { - return mode; - } -} diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModes.java b/core/src/main/java/org/elasticsearch/script/ScriptModes.java index d07a4073ba8..46ab2a44d21 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModes.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModes.java @@ -29,22 +29,22 @@ import java.util.Map; import java.util.TreeMap; /** - * Holds the {@link org.elasticsearch.script.ScriptMode}s for each of the different scripting languages available, - * each script source and each scripted operation. + * Holds the boolean indicating the enabled mode for each of the different scripting languages available, each script source and each + * scripted operation. */ public class ScriptModes { private static final String SCRIPT_SETTINGS_PREFIX = "script"; private static final String ENGINE_SETTINGS_PREFIX = "script.engine"; - final Map scriptModes; + final Map scriptEnabled; ScriptModes(ScriptSettings scriptSettings, Settings settings) { - HashMap scriptModes = new HashMap<>(); - for (Setting scriptModeSetting : scriptSettings.getScriptLanguageSettings()) { + HashMap scriptModes = new HashMap<>(); + for (Setting scriptModeSetting : scriptSettings.getScriptLanguageSettings()) { scriptModes.put(scriptModeSetting.getKey(), scriptModeSetting.get(settings)); } - this.scriptModes = Collections.unmodifiableMap(scriptModes); + this.scriptEnabled = Collections.unmodifiableMap(scriptModes); } /** @@ -54,14 +54,14 @@ public class ScriptModes { * @param lang the language that the script is written in * @param scriptType the type of the script * @param scriptContext the operation that requires the execution of the script - * @return whether scripts are on or off + * @return whether scripts are enabled (true) or disabled (false) */ - public ScriptMode getScriptMode(String lang, ScriptType scriptType, ScriptContext scriptContext) { - //native scripts are always on as they are static by definition + public boolean getScriptEnabled(String lang, ScriptType scriptType, ScriptContext scriptContext) { + //native scripts are always enabled as they are static by definition if (NativeScriptEngineService.NAME.equals(lang)) { - return ScriptMode.ON; + return true; } - ScriptMode scriptMode = scriptModes.get(getKey(lang, scriptType, scriptContext)); + Boolean scriptMode = scriptEnabled.get(getKey(lang, scriptType, scriptContext)); if (scriptMode == null) { throw new IllegalArgumentException("script mode not found for lang [" + lang + "], script_type [" + scriptType + "], operation [" + scriptContext.getKey() + "]"); } @@ -87,10 +87,10 @@ public class ScriptModes { @Override public String toString() { //order settings by key before printing them out, for readability - TreeMap scriptModesTreeMap = new TreeMap<>(); - scriptModesTreeMap.putAll(scriptModes); + TreeMap scriptModesTreeMap = new TreeMap<>(); + scriptModesTreeMap.putAll(scriptEnabled); StringBuilder stringBuilder = new StringBuilder(); - for (Map.Entry stringScriptModeEntry : scriptModesTreeMap.entrySet()) { + for (Map.Entry stringScriptModeEntry : scriptModesTreeMap.entrySet()) { stringBuilder.append(stringScriptModeEntry.getKey()).append(": ").append(stringScriptModeEntry.getValue()).append("\n"); } return stringBuilder.toString(); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java index 0fa4d9ea731..c08c31c9bf2 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.inject.multibindings.MapBinder; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.SettingsModule; -import org.elasticsearch.script.ScriptMode; import java.util.ArrayList; import java.util.HashMap; @@ -42,7 +41,7 @@ public class ScriptModule extends AbstractModule { { scriptEngineRegistrations.add(new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, - NativeScriptEngineService.NAME, ScriptMode.ON)); + NativeScriptEngineService.NAME, true)); } private final Map> scripts = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index f77a0aae330..cf0ba1ca941 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -473,15 +473,7 @@ public class ScriptService extends AbstractComponent implements Closeable { if (scriptContextRegistry.isSupportedContext(scriptContext) == false) { throw new IllegalArgumentException("script context [" + scriptContext.getKey() + "] not supported"); } - ScriptMode mode = scriptModes.getScriptMode(lang, scriptType, scriptContext); - switch (mode) { - case ON: - return true; - case OFF: - return false; - default: - throw new IllegalArgumentException("script mode [" + mode + "] not supported"); - } + return scriptModes.getScriptEnabled(lang, scriptType, scriptContext); } public ScriptStats stats() { @@ -610,14 +602,14 @@ public class ScriptService extends AbstractComponent implements Closeable { */ public enum ScriptType { - INLINE(0, "inline", "inline", ScriptMode.OFF), - STORED(1, "id", "stored", ScriptMode.OFF), - FILE(2, "file", "file", ScriptMode.ON); + INLINE(0, "inline", "inline", false), + STORED(1, "id", "stored", false), + FILE(2, "file", "file", true); private final int val; private final ParseField parseField; private final String scriptType; - private final ScriptMode defaultScriptMode; + private final boolean defaultScriptEnabled; public static ScriptType readFrom(StreamInput in) throws IOException { int scriptTypeVal = in.readVInt(); @@ -638,19 +630,19 @@ public class ScriptService extends AbstractComponent implements Closeable { } } - ScriptType(int val, String name, String scriptType, ScriptMode defaultScriptMode) { + ScriptType(int val, String name, String scriptType, boolean defaultScriptEnabled) { this.val = val; this.parseField = new ParseField(name); this.scriptType = scriptType; - this.defaultScriptMode = defaultScriptMode; + this.defaultScriptEnabled = defaultScriptEnabled; } public ParseField getParseField() { return parseField; } - public ScriptMode getDefaultScriptMode() { - return defaultScriptMode; + public boolean getDefaultScriptEnabled() { + return defaultScriptEnabled; } public String getScriptType() { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java index 433912e47e5..71013f28a06 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java @@ -37,29 +37,28 @@ public class ScriptSettings { public final static String DEFAULT_LANG = "groovy"; - private final static Map> SCRIPT_TYPE_SETTING_MAP; + private final static Map> SCRIPT_TYPE_SETTING_MAP; static { - Map> scriptTypeSettingMap = new HashMap<>(); + Map> scriptTypeSettingMap = new HashMap<>(); for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { - scriptTypeSettingMap.put(scriptType, new Setting<>( + scriptTypeSettingMap.put(scriptType, Setting.boolSetting( ScriptModes.sourceKey(scriptType), - scriptType.getDefaultScriptMode().getMode(), - ScriptMode::parse, + scriptType.getDefaultScriptEnabled(), Property.NodeScope)); } SCRIPT_TYPE_SETTING_MAP = Collections.unmodifiableMap(scriptTypeSettingMap); } - private final Map> scriptContextSettingMap; - private final List> scriptLanguageSettings; + private final Map> scriptContextSettingMap; + private final List> scriptLanguageSettings; private final Setting defaultScriptLanguageSetting; public ScriptSettings(ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) { - Map> scriptContextSettingMap = contextSettings(scriptContextRegistry); + Map> scriptContextSettingMap = contextSettings(scriptContextRegistry); this.scriptContextSettingMap = Collections.unmodifiableMap(scriptContextSettingMap); - List> scriptLanguageSettings = languageSettings(SCRIPT_TYPE_SETTING_MAP, scriptContextSettingMap, scriptEngineRegistry, scriptContextRegistry); + List> scriptLanguageSettings = languageSettings(SCRIPT_TYPE_SETTING_MAP, scriptContextSettingMap, scriptEngineRegistry, scriptContextRegistry); this.scriptLanguageSettings = Collections.unmodifiableList(scriptLanguageSettings); this.defaultScriptLanguageSetting = new Setting<>("script.default_lang", DEFAULT_LANG, setting -> { @@ -70,24 +69,20 @@ public class ScriptSettings { }, Property.NodeScope); } - private static Map> contextSettings(ScriptContextRegistry scriptContextRegistry) { - Map> scriptContextSettingMap = new HashMap<>(); + private static Map> contextSettings(ScriptContextRegistry scriptContextRegistry) { + Map> scriptContextSettingMap = new HashMap<>(); for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) { - scriptContextSettingMap.put(scriptContext, new Setting<>( - ScriptModes.operationKey(scriptContext), - ScriptMode.OFF.getMode(), - ScriptMode::parse, - Property.NodeScope - )); + scriptContextSettingMap.put(scriptContext, + Setting.boolSetting(ScriptModes.operationKey(scriptContext), false, Property.NodeScope)); } return scriptContextSettingMap; } - private static List> languageSettings(Map> scriptTypeSettingMap, - Map> scriptContextSettingMap, + private static List> languageSettings(Map> scriptTypeSettingMap, + Map> scriptContextSettingMap, ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) { - final List> scriptModeSettings = new ArrayList<>(); + final List> scriptModeSettings = new ArrayList<>(); for (final Class scriptEngineService : scriptEngineRegistry.getRegisteredScriptEngineServices()) { if (scriptEngineService == NativeScriptEngineService.class) { @@ -97,17 +92,17 @@ public class ScriptSettings { final String language = scriptEngineRegistry.getLanguage(scriptEngineService); for (final ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { // Top level, like "script.engine.groovy.inline" - final ScriptMode defaultNonFileScriptMode = scriptEngineRegistry.getDefaultInlineScriptModes().get(language); - ScriptMode defaultLangAndType = defaultNonFileScriptMode; + final boolean defaultNonFileScriptMode = scriptEngineRegistry.getDefaultInlineScriptEnableds().get(language); + boolean defaultLangAndType = defaultNonFileScriptMode; // Files are treated differently because they are never default-deny if (ScriptService.ScriptType.FILE == scriptType) { - defaultLangAndType = ScriptService.ScriptType.FILE.getDefaultScriptMode(); + defaultLangAndType = ScriptService.ScriptType.FILE.getDefaultScriptEnabled(); } - final ScriptMode defaultIfNothingSet = defaultLangAndType; + final boolean defaultIfNothingSet = defaultLangAndType; // Setting for something like "script.engine.groovy.inline" - final Setting langAndTypeSetting = new Setting<>(ScriptModes.getGlobalKey(language, scriptType), - defaultLangAndType.toString(), ScriptMode::parse, Property.NodeScope); + final Setting langAndTypeSetting = Setting.boolSetting(ScriptModes.getGlobalKey(language, scriptType), + defaultLangAndType, Property.NodeScope); scriptModeSettings.add(langAndTypeSetting); for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) { @@ -115,32 +110,31 @@ public class ScriptSettings { // A function that, given a setting, will return what the default should be. Since the fine-grained script settings // read from a bunch of different places this is implemented in this way. Function defaultSettingFn = settings -> { - final Setting globalOpSetting = scriptContextSettingMap.get(scriptContext); - final Setting globalTypeSetting = scriptTypeSettingMap.get(scriptType); - final Setting langAndTypeAndContextSetting = new Setting<>(langAndTypeAndContextName, - defaultIfNothingSet.toString(), ScriptMode::parse, Property.NodeScope); + final Setting globalOpSetting = scriptContextSettingMap.get(scriptContext); + final Setting globalTypeSetting = scriptTypeSettingMap.get(scriptType); + final Setting langAndTypeAndContextSetting = Setting.boolSetting(langAndTypeAndContextName, + defaultIfNothingSet, Property.NodeScope); // fallback logic for script mode settings if (langAndTypeAndContextSetting.exists(settings)) { // like: "script.engine.groovy.inline.aggs: true" - return langAndTypeAndContextSetting.get(settings).getMode(); + return langAndTypeAndContextSetting.get(settings).toString(); } else if (langAndTypeSetting.exists(settings)) { // like: "script.engine.groovy.inline: true" - return langAndTypeSetting.get(settings).getMode(); + return langAndTypeSetting.get(settings).toString(); } else if (globalOpSetting.exists(settings)) { // like: "script.aggs: true" - return globalOpSetting.get(settings).getMode(); + return globalOpSetting.get(settings).toString(); } else if (globalTypeSetting.exists(settings)) { // like: "script.inline: true" - return globalTypeSetting.get(settings).getMode(); + return globalTypeSetting.get(settings).toString(); } else { // Nothing is set! - return defaultIfNothingSet.getMode(); + return Boolean.toString(defaultIfNothingSet); } }; // The actual setting for finest grained script settings - Setting setting = new Setting<>(langAndTypeAndContextName, defaultSettingFn, - ScriptMode::parse, Property.NodeScope); + Setting setting = Setting.boolSetting(langAndTypeAndContextName, defaultSettingFn, Property.NodeScope); scriptModeSettings.add(setting); } } @@ -148,15 +142,15 @@ public class ScriptSettings { return scriptModeSettings; } - public Iterable> getScriptTypeSettings() { + public Iterable> getScriptTypeSettings() { return Collections.unmodifiableCollection(SCRIPT_TYPE_SETTING_MAP.values()); } - public Iterable> getScriptContextSettings() { + public Iterable> getScriptContextSettings() { return Collections.unmodifiableCollection(scriptContextSettingMap.values()); } - public Iterable> getScriptLanguageSettings() { + public Iterable> getScriptLanguageSettings() { return scriptLanguageSettings; } diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index b150000daf1..b49488bd7c2 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.query; import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.io.JsonStringEncoder; -import org.elasticsearch.script.ScriptMode; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.Query; @@ -239,7 +238,7 @@ public abstract class AbstractQueryTestCase> ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections .singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, - MockScriptEngine.NAME, ScriptMode.ON))); + MockScriptEngine.NAME, true))); bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); diff --git a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java b/core/src/test/java/org/elasticsearch/script/FileScriptTests.java index e5f78d7474e..fefe55b9ec3 100644 --- a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/FileScriptTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.script; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.script.MockScriptEngine.MockCompiledScript; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.test.ESTestCase; import java.nio.file.Files; @@ -46,7 +45,7 @@ public class FileScriptTests extends ESTestCase { .put(settings) .build(); Set engines = new HashSet<>(Collections.singletonList(new MockScriptEngine())); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, ScriptMode.ON))); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, true))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); return new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 045f62ff8fe..5e1dc740f9e 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -75,10 +74,10 @@ public class NativeScriptTests extends ESTestCase { Settings.Builder builder = Settings.builder(); if (randomBoolean()) { ScriptType scriptType = randomFrom(ScriptType.values()); - builder.put("script" + "." + scriptType.getScriptType(), randomFrom(ScriptMode.values())); + builder.put("script" + "." + scriptType.getScriptType(), randomBoolean()); } else { ScriptContext scriptContext = randomFrom(ScriptContext.Standard.values()); - builder.put("script" + "." + scriptContext.getKey(), randomFrom(ScriptMode.values())); + builder.put("script" + "." + scriptContext.getKey(), randomBoolean()); } Settings settings = builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build(); Environment environment = new Environment(settings); @@ -86,7 +85,7 @@ public class NativeScriptTests extends ESTestCase { Map nativeScriptFactoryMap = new HashMap<>(); nativeScriptFactoryMap.put("my", new MyNativeScriptFactory()); Set scriptEngineServices = singleton(new NativeScriptEngineService(settings, nativeScriptFactoryMap)); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, NativeScriptEngineService.NAME, ScriptMode.ON))); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, NativeScriptEngineService.NAME, true))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList<>()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); ScriptService scriptService = new ScriptService(settings, environment, scriptEngineServices, resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, scriptSettings); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java index 8405366f34d..715694fe890 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.script; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -46,7 +45,7 @@ public class ScriptContextTests extends ESTestCase { .build(); Set engines = new HashSet<>(Collections.singletonList(new MockScriptEngine())); ScriptEngineRegistry.ScriptEngineRegistration registration = - new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, ScriptMode.ON); + new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, true); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(registration)); List customContexts = Arrays.asList( new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"), diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index 800c079b889..8f02bee234d 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -83,7 +83,7 @@ public class ScriptModesTests extends ESTestCase { @After public void assertNativeScriptsAreAlwaysAllowed() { if (assertScriptModesNonNull) { - assertThat(scriptModes.getScriptMode(NativeScriptEngineService.NAME, randomFrom(ScriptType.values()), randomFrom(scriptContexts)), equalTo(ScriptMode.ON)); + assertThat(scriptModes.getScriptEnabled(NativeScriptEngineService.NAME, randomFrom(ScriptType.values()), randomFrom(scriptContexts)), equalTo(true)); } } @@ -93,7 +93,7 @@ public class ScriptModesTests extends ESTestCase { assertThat(scriptModes, notNullValue()); int numberOfSettings = ScriptType.values().length * scriptContextRegistry.scriptContexts().size(); numberOfSettings += 3; // for top-level inline/store/file settings - assertThat(scriptModes.scriptModes.size(), equalTo(numberOfSettings)); + assertThat(scriptModes.scriptEnabled.size(), equalTo(numberOfSettings)); if (assertAllSettingsWereChecked) { assertThat(checkedSettings.size(), equalTo(numberOfSettings)); } @@ -102,15 +102,15 @@ public class ScriptModesTests extends ESTestCase { public void testDefaultSettings() { this.scriptModes = new ScriptModes(scriptSettings, Settings.EMPTY); - assertScriptModesAllOps(ScriptMode.ON, ScriptType.FILE); - assertScriptModesAllOps(ScriptMode.OFF, ScriptType.STORED, ScriptType.INLINE); + assertScriptModesAllOps(true, ScriptType.FILE); + assertScriptModesAllOps(false, ScriptType.STORED, ScriptType.INLINE); } public void testMissingSetting() { assertAllSettingsWereChecked = false; this.scriptModes = new ScriptModes(scriptSettings, Settings.EMPTY); try { - scriptModes.getScriptMode("non_existing", randomFrom(ScriptType.values()), randomFrom(scriptContexts)); + scriptModes.getScriptEnabled("non_existing", randomFrom(ScriptType.values()), randomFrom(scriptContexts)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("not found for lang [non_existing]")); @@ -120,13 +120,13 @@ public class ScriptModesTests extends ESTestCase { public void testScriptTypeGenericSettings() { int randomInt = randomIntBetween(1, ScriptType.values().length - 1); Set randomScriptTypesSet = new HashSet<>(); - ScriptMode[] randomScriptModes = new ScriptMode[randomInt]; + boolean[] randomScriptModes = new boolean[randomInt]; for (int i = 0; i < randomInt; i++) { boolean added = false; while (added == false) { added = randomScriptTypesSet.add(randomFrom(ScriptType.values())); } - randomScriptModes[i] = randomFrom(ScriptMode.values()); + randomScriptModes[i] = randomBoolean(); } ScriptType[] randomScriptTypes = randomScriptTypesSet.toArray(new ScriptType[randomScriptTypesSet.size()]); Settings.Builder builder = Settings.builder(); @@ -139,26 +139,26 @@ public class ScriptModesTests extends ESTestCase { assertScriptModesAllOps(randomScriptModes[i], randomScriptTypes[i]); } if (randomScriptTypesSet.contains(ScriptType.FILE) == false) { - assertScriptModesAllOps(ScriptMode.ON, ScriptType.FILE); + assertScriptModesAllOps(true, ScriptType.FILE); } if (randomScriptTypesSet.contains(ScriptType.STORED) == false) { - assertScriptModesAllOps(ScriptMode.OFF, ScriptType.STORED); + assertScriptModesAllOps(false, ScriptType.STORED); } if (randomScriptTypesSet.contains(ScriptType.INLINE) == false) { - assertScriptModesAllOps(ScriptMode.OFF, ScriptType.INLINE); + assertScriptModesAllOps(false, ScriptType.INLINE); } } public void testScriptContextGenericSettings() { int randomInt = randomIntBetween(1, scriptContexts.length - 1); Set randomScriptContextsSet = new HashSet<>(); - ScriptMode[] randomScriptModes = new ScriptMode[randomInt]; + boolean[] randomScriptModes = new boolean[randomInt]; for (int i = 0; i < randomInt; i++) { boolean added = false; while (added == false) { added = randomScriptContextsSet.add(randomFrom(scriptContexts)); } - randomScriptModes[i] = randomFrom(ScriptMode.values()); + randomScriptModes[i] = randomBoolean(); } ScriptContext[] randomScriptContexts = randomScriptContextsSet.toArray(new ScriptContext[randomScriptContextsSet.size()]); Settings.Builder builder = Settings.builder(); @@ -172,8 +172,8 @@ public class ScriptModesTests extends ESTestCase { } ScriptContext[] complementOf = complementOf(randomScriptContexts); - assertScriptModes(ScriptMode.ON, new ScriptType[]{ScriptType.FILE}, complementOf); - assertScriptModes(ScriptMode.OFF, new ScriptType[]{ScriptType.STORED, ScriptType.INLINE}, complementOf); + assertScriptModes(true, new ScriptType[]{ScriptType.FILE}, complementOf); + assertScriptModes(false, new ScriptType[]{ScriptType.STORED, ScriptType.INLINE}, complementOf); } public void testConflictingScriptTypeAndOpGenericSettings() { @@ -184,28 +184,28 @@ public class ScriptModesTests extends ESTestCase { .put("script.inline", "true"); //operations generic settings have precedence over script type generic settings this.scriptModes = new ScriptModes(scriptSettings, builder.build()); - assertScriptModesAllTypes(ScriptMode.OFF, scriptContext); + assertScriptModesAllTypes(false, scriptContext); ScriptContext[] complementOf = complementOf(scriptContext); - assertScriptModes(ScriptMode.ON, new ScriptType[]{ScriptType.FILE, ScriptType.STORED}, complementOf); - assertScriptModes(ScriptMode.ON, new ScriptType[]{ScriptType.INLINE}, complementOf); + assertScriptModes(true, new ScriptType[]{ScriptType.FILE, ScriptType.STORED}, complementOf); + assertScriptModes(true, new ScriptType[]{ScriptType.INLINE}, complementOf); } - private void assertScriptModesAllOps(ScriptMode expectedScriptMode, ScriptType... scriptTypes) { - assertScriptModes(expectedScriptMode, scriptTypes, scriptContexts); + private void assertScriptModesAllOps(boolean expectedScriptEnabled, ScriptType... scriptTypes) { + assertScriptModes(expectedScriptEnabled, scriptTypes, scriptContexts); } - private void assertScriptModesAllTypes(ScriptMode expectedScriptMode, ScriptContext... scriptContexts) { - assertScriptModes(expectedScriptMode, ScriptType.values(), scriptContexts); + private void assertScriptModesAllTypes(boolean expectedScriptEnabled, ScriptContext... scriptContexts) { + assertScriptModes(expectedScriptEnabled, ScriptType.values(), scriptContexts); } - private void assertScriptModes(ScriptMode expectedScriptMode, ScriptType[] scriptTypes, ScriptContext... scriptContexts) { + private void assertScriptModes(boolean expectedScriptEnabled, ScriptType[] scriptTypes, ScriptContext... scriptContexts) { assert scriptTypes.length > 0; assert scriptContexts.length > 0; for (ScriptType scriptType : scriptTypes) { checkedSettings.add("script.engine.custom." + scriptType); for (ScriptContext scriptContext : scriptContexts) { assertThat("custom." + scriptType + "." + scriptContext.getKey() + " doesn't have the expected value", - scriptModes.getScriptMode("custom", scriptType, scriptContext), equalTo(expectedScriptMode)); + scriptModes.getScriptEnabled("custom", scriptType, scriptContext), equalTo(expectedScriptEnabled)); checkedSettings.add("custom." + scriptType + "." + scriptContext); } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 8fd8f674c3a..890ffccc514 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -71,12 +71,12 @@ public class ScriptServiceTests extends ESTestCase { private Path scriptsFilePath; private Settings baseSettings; - private static final Map DEFAULT_SCRIPT_MODES = new HashMap<>(); + private static final Map DEFAULT_SCRIPT_ENABLED = new HashMap<>(); static { - DEFAULT_SCRIPT_MODES.put(ScriptType.FILE, ScriptMode.ON); - DEFAULT_SCRIPT_MODES.put(ScriptType.STORED, ScriptMode.OFF); - DEFAULT_SCRIPT_MODES.put(ScriptType.INLINE, ScriptMode.OFF); + DEFAULT_SCRIPT_ENABLED.put(ScriptType.FILE, true); + DEFAULT_SCRIPT_ENABLED.put(ScriptType.STORED, false); + DEFAULT_SCRIPT_ENABLED.put(ScriptType.INLINE, false); } @Before @@ -110,7 +110,7 @@ public class ScriptServiceTests extends ESTestCase { contexts.put(context, new ScriptContext.Plugin(plugin, operation)); } List registries = new ArrayList<>(2); - registries.add(new ScriptEngineRegistry.ScriptEngineRegistration(TestEngineService.class, TestEngineService.NAME, ScriptMode.ON)); + registries.add(new ScriptEngineRegistry.ScriptEngineRegistration(TestEngineService.class, TestEngineService.NAME, true)); registries.add(new ScriptEngineRegistry.ScriptEngineRegistration(TestDangerousEngineService.class, TestDangerousEngineService.NAME)); scriptEngineRegistry = new ScriptEngineRegistry(registries); scriptContextRegistry = new ScriptContextRegistry(contexts.values()); @@ -215,25 +215,25 @@ public class ScriptServiceTests extends ESTestCase { public void testFineGrainedSettings() throws IOException { //collect the fine-grained settings to set for this run int numScriptSettings = randomIntBetween(0, ScriptType.values().length); - Map scriptSourceSettings = new HashMap<>(); + Map scriptSourceSettings = new HashMap<>(); for (int i = 0; i < numScriptSettings; i++) { ScriptType scriptType; do { scriptType = randomFrom(ScriptType.values()); } while (scriptSourceSettings.containsKey(scriptType)); - scriptSourceSettings.put(scriptType, randomFrom(ScriptMode.values())); + scriptSourceSettings.put(scriptType, randomBoolean()); } int numScriptContextSettings = randomIntBetween(0, this.scriptContextRegistry.scriptContexts().size()); - Map scriptContextSettings = new HashMap<>(); + Map scriptContextSettings = new HashMap<>(); for (int i = 0; i < numScriptContextSettings; i++) { ScriptContext scriptContext; do { scriptContext = randomFrom(this.scriptContexts); } while (scriptContextSettings.containsKey(scriptContext)); - scriptContextSettings.put(scriptContext, randomFrom(ScriptMode.values())); + scriptContextSettings.put(scriptContext, randomBoolean()); } int numEngineSettings = randomIntBetween(0, ScriptType.values().length * scriptContexts.length); - Map engineSettings = new HashMap<>(); + Map engineSettings = new HashMap<>(); for (int i = 0; i < numEngineSettings; i++) { String settingKey; do { @@ -241,43 +241,34 @@ public class ScriptServiceTests extends ESTestCase { ScriptContext scriptContext = randomFrom(this.scriptContexts); settingKey = scriptEngineService.getType() + "." + scriptType + "." + scriptContext.getKey(); } while (engineSettings.containsKey(settingKey)); - engineSettings.put(settingKey, randomFrom(ScriptMode.values())); + engineSettings.put(settingKey, randomBoolean()); } //set the selected fine-grained settings Settings.Builder builder = Settings.builder(); - for (Map.Entry entry : scriptSourceSettings.entrySet()) { - switch (entry.getValue()) { - case ON: - builder.put("script" + "." + entry.getKey().getScriptType(), "true"); - break; - case OFF: - builder.put("script" + "." + entry.getKey().getScriptType(), "false"); - break; + for (Map.Entry entry : scriptSourceSettings.entrySet()) { + if (entry.getValue()) { + builder.put("script" + "." + entry.getKey().getScriptType(), "true"); + } else { + builder.put("script" + "." + entry.getKey().getScriptType(), "false"); } } - for (Map.Entry entry : scriptContextSettings.entrySet()) { - switch (entry.getValue()) { - case ON: - builder.put("script" + "." + entry.getKey().getKey(), "true"); - break; - case OFF: - builder.put("script" + "." + entry.getKey().getKey(), "false"); - break; + for (Map.Entry entry : scriptContextSettings.entrySet()) { + if (entry.getValue()) { + builder.put("script" + "." + entry.getKey().getKey(), "true"); + } else { + builder.put("script" + "." + entry.getKey().getKey(), "false"); } } - for (Map.Entry entry : engineSettings.entrySet()) { + for (Map.Entry entry : engineSettings.entrySet()) { int delimiter = entry.getKey().indexOf('.'); String part1 = entry.getKey().substring(0, delimiter); String part2 = entry.getKey().substring(delimiter + 1); String lang = randomFrom(scriptEnginesByLangMap.get(part1).getType()); - switch (entry.getValue()) { - case ON: - builder.put("script.engine" + "." + lang + "." + part2, "true"); - break; - case OFF: - builder.put("script.engine" + "." + lang + "." + part2, "false"); - break; + if (entry.getValue()) { + builder.put("script.engine" + "." + lang + "." + part2, "true"); + } else { + builder.put("script.engine" + "." + lang + "." + part2, "false"); } } @@ -290,25 +281,22 @@ public class ScriptServiceTests extends ESTestCase { String script = scriptType == ScriptType.FILE ? "file_script" : "script"; for (ScriptContext scriptContext : this.scriptContexts) { //fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings - ScriptMode scriptMode = engineSettings.get(dangerousScriptEngineService.getType() + "." + scriptType + "." + scriptContext.getKey()); - if (scriptMode == null) { - scriptMode = scriptContextSettings.get(scriptContext); + Boolean scriptEnabled = engineSettings.get(dangerousScriptEngineService.getType() + "." + scriptType + "." + scriptContext.getKey()); + if (scriptEnabled == null) { + scriptEnabled = scriptContextSettings.get(scriptContext); } - if (scriptMode == null) { - scriptMode = scriptSourceSettings.get(scriptType); + if (scriptEnabled == null) { + scriptEnabled = scriptSourceSettings.get(scriptType); } - if (scriptMode == null) { - scriptMode = DEFAULT_SCRIPT_MODES.get(scriptType); + if (scriptEnabled == null) { + scriptEnabled = DEFAULT_SCRIPT_ENABLED.get(scriptType); } String lang = dangerousScriptEngineService.getType(); - switch (scriptMode) { - case ON: - assertCompileAccepted(lang, script, scriptType, scriptContext); - break; - case OFF: - assertCompileRejected(lang, script, scriptType, scriptContext); - break; + if (scriptEnabled) { + assertCompileAccepted(lang, script, scriptType, scriptContext); + } else { + assertCompileRejected(lang, script, scriptType, scriptContext); } } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java index 3d82e2f1468..92598ec8dd2 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java @@ -22,7 +22,6 @@ package org.elasticsearch.script; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESTestCase; @@ -39,7 +38,7 @@ public class ScriptSettingsTests extends ESTestCase { public void testDefaultLanguageIsGroovy() { ScriptEngineRegistry scriptEngineRegistry = - new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, ScriptMode.ON))); + new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, true))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); assertThat(scriptSettings.getDefaultScriptLanguageSetting().get(Settings.EMPTY), equalTo("groovy")); @@ -47,7 +46,7 @@ public class ScriptSettingsTests extends ESTestCase { public void testCustomDefaultLanguage() { ScriptEngineRegistry scriptEngineRegistry = - new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, ScriptMode.ON))); + new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, true))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); String defaultLanguage = CustomScriptEngineService.NAME; @@ -57,7 +56,7 @@ public class ScriptSettingsTests extends ESTestCase { public void testInvalidDefaultLanguage() { ScriptEngineRegistry scriptEngineRegistry = - new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, ScriptMode.ON))); + new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.NAME, true))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); Settings settings = Settings.builder().put("script.default_lang", "C++").build(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 2949dadcc49..60185dbae28 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -51,7 +51,6 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptSettings; @@ -135,7 +134,7 @@ public class AggregatorParsingTests extends ESTestCase { new ScriptEngineRegistry(Collections .singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, - ScriptMode.ON))); + true))); bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index e986ab1288f..8df37e25f76 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -55,7 +55,6 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptSettings; @@ -149,7 +148,7 @@ public abstract class BaseAggregationTestCase> new ScriptEngineRegistry(Collections .singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.NAME, - ScriptMode.ON))); + true))); bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index 113b52cb0b6..c20344f35fc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -55,7 +55,6 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptMode; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptSettings; @@ -148,7 +147,7 @@ public abstract class BasePipelineAggregationTestCase