Remove ScriptMode class in favor of boolean true/false

This removes the ScriptMode class entirely, which was an enum with two
options (ON and OFF) which essentially boiled down to true and false.
Now the boolean values are used instead.
This commit is contained in:
Lee Hinman 2016-05-20 15:01:30 -06:00
parent 4c7993ea71
commit fdfd2a2f18
28 changed files with 162 additions and 268 deletions

View File

@ -537,6 +537,10 @@ public class Setting<T> extends ToXContentToBytes {
return new Setting<>(key, fallbackSetting, Booleans::parseBooleanExact, properties);
}
public static Setting<Boolean> boolSetting(String key, Function<Settings, String> defaultValueFn, Property... properties) {
return new Setting<>(key, defaultValueFn, Booleans::parseBooleanExact, properties);
}
public static Setting<ByteSizeValue> byteSizeSetting(String key, String percentage, Property... properties) {
return new Setting<>(key, (s) -> percentage, (s) -> MemorySizeValue.parseBytesSizeValueOrHeapRatio(s, key), properties);
}

View File

@ -30,13 +30,13 @@ public class ScriptEngineRegistry {
private final Map<Class<? extends ScriptEngineService>, String> registeredScriptEngineServices;
private final Map<String, Class<? extends ScriptEngineService>> registeredLanguages;
private final Map<String, ScriptMode> defaultInlineScriptModes;
private final Map<String, Boolean> defaultInlineScriptEnableds;
public ScriptEngineRegistry(Iterable<ScriptEngineRegistration> registrations) {
Objects.requireNonNull(registrations);
Map<Class<? extends ScriptEngineService>, String> registeredScriptEngineServices = new HashMap<>();
Map<String, Class<? extends ScriptEngineService>> registeredLanguages = new HashMap<>();
Map<String, ScriptMode> inlineScriptModes = new HashMap<>();
Map<String, Boolean> 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<Class<? extends ScriptEngineService>> getRegisteredScriptEngineServices() {
@ -72,27 +72,27 @@ public class ScriptEngineRegistry {
return registeredLanguages;
}
Map<String, ScriptMode> getDefaultInlineScriptModes() {
return this.defaultInlineScriptModes;
Map<String, Boolean> getDefaultInlineScriptEnableds() {
return this.defaultInlineScriptEnableds;
}
public static class ScriptEngineRegistration {
private final Class<? extends ScriptEngineService> 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<? extends ScriptEngineService> 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<? extends ScriptEngineService> 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<? extends ScriptEngineService> getScriptEngineService() {
@ -111,8 +111,8 @@ public class ScriptEngineRegistry {
return scriptEngineLanguage;
}
ScriptMode getDefaultInlineScriptMode() {
return defaultInlineScriptMode;
boolean getDefaultInlineScriptEnabled() {
return defaultInlineScriptEnabled;
}
}

View File

@ -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<String, ScriptMode> 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;
}
}

View File

@ -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<String, ScriptMode> scriptModes;
final Map<String, Boolean> scriptEnabled;
ScriptModes(ScriptSettings scriptSettings, Settings settings) {
HashMap<String, ScriptMode> scriptModes = new HashMap<>();
for (Setting<ScriptMode> scriptModeSetting : scriptSettings.getScriptLanguageSettings()) {
HashMap<String, Boolean> scriptModes = new HashMap<>();
for (Setting<Boolean> 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<String, ScriptMode> scriptModesTreeMap = new TreeMap<>();
scriptModesTreeMap.putAll(scriptModes);
TreeMap<String, Boolean> scriptModesTreeMap = new TreeMap<>();
scriptModesTreeMap.putAll(scriptEnabled);
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, ScriptMode> stringScriptModeEntry : scriptModesTreeMap.entrySet()) {
for (Map.Entry<String, Boolean> stringScriptModeEntry : scriptModesTreeMap.entrySet()) {
stringBuilder.append(stringScriptModeEntry.getKey()).append(": ").append(stringScriptModeEntry.getValue()).append("\n");
}
return stringBuilder.toString();

View File

@ -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<String, Class<? extends NativeScriptFactory>> scripts = new HashMap<>();

View File

@ -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() {

View File

@ -37,29 +37,28 @@ public class ScriptSettings {
public final static String DEFAULT_LANG = "groovy";
private final static Map<ScriptService.ScriptType, Setting<ScriptMode>> SCRIPT_TYPE_SETTING_MAP;
private final static Map<ScriptService.ScriptType, Setting<Boolean>> SCRIPT_TYPE_SETTING_MAP;
static {
Map<ScriptService.ScriptType, Setting<ScriptMode>> scriptTypeSettingMap = new HashMap<>();
Map<ScriptService.ScriptType, Setting<Boolean>> 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<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap;
private final List<Setting<ScriptMode>> scriptLanguageSettings;
private final Map<ScriptContext, Setting<Boolean>> scriptContextSettingMap;
private final List<Setting<Boolean>> scriptLanguageSettings;
private final Setting<String> defaultScriptLanguageSetting;
public ScriptSettings(ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) {
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap = contextSettings(scriptContextRegistry);
Map<ScriptContext, Setting<Boolean>> scriptContextSettingMap = contextSettings(scriptContextRegistry);
this.scriptContextSettingMap = Collections.unmodifiableMap(scriptContextSettingMap);
List<Setting<ScriptMode>> scriptLanguageSettings = languageSettings(SCRIPT_TYPE_SETTING_MAP, scriptContextSettingMap, scriptEngineRegistry, scriptContextRegistry);
List<Setting<Boolean>> 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<ScriptContext, Setting<ScriptMode>> contextSettings(ScriptContextRegistry scriptContextRegistry) {
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap = new HashMap<>();
private static Map<ScriptContext, Setting<Boolean>> contextSettings(ScriptContextRegistry scriptContextRegistry) {
Map<ScriptContext, Setting<Boolean>> 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<Setting<ScriptMode>> languageSettings(Map<ScriptService.ScriptType, Setting<ScriptMode>> scriptTypeSettingMap,
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap,
private static List<Setting<Boolean>> languageSettings(Map<ScriptService.ScriptType, Setting<Boolean>> scriptTypeSettingMap,
Map<ScriptContext, Setting<Boolean>> scriptContextSettingMap,
ScriptEngineRegistry scriptEngineRegistry,
ScriptContextRegistry scriptContextRegistry) {
final List<Setting<ScriptMode>> scriptModeSettings = new ArrayList<>();
final List<Setting<Boolean>> scriptModeSettings = new ArrayList<>();
for (final Class<? extends ScriptEngineService> 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<ScriptMode> langAndTypeSetting = new Setting<>(ScriptModes.getGlobalKey(language, scriptType),
defaultLangAndType.toString(), ScriptMode::parse, Property.NodeScope);
final Setting<Boolean> 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<Settings, String> defaultSettingFn = settings -> {
final Setting<ScriptMode> globalOpSetting = scriptContextSettingMap.get(scriptContext);
final Setting<ScriptMode> globalTypeSetting = scriptTypeSettingMap.get(scriptType);
final Setting<ScriptMode> langAndTypeAndContextSetting = new Setting<>(langAndTypeAndContextName,
defaultIfNothingSet.toString(), ScriptMode::parse, Property.NodeScope);
final Setting<Boolean> globalOpSetting = scriptContextSettingMap.get(scriptContext);
final Setting<Boolean> globalTypeSetting = scriptTypeSettingMap.get(scriptType);
final Setting<Boolean> 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<ScriptMode> setting = new Setting<>(langAndTypeAndContextName, defaultSettingFn,
ScriptMode::parse, Property.NodeScope);
Setting<Boolean> setting = Setting.boolSetting(langAndTypeAndContextName, defaultSettingFn, Property.NodeScope);
scriptModeSettings.add(setting);
}
}
@ -148,15 +142,15 @@ public class ScriptSettings {
return scriptModeSettings;
}
public Iterable<Setting<ScriptMode>> getScriptTypeSettings() {
public Iterable<Setting<Boolean>> getScriptTypeSettings() {
return Collections.unmodifiableCollection(SCRIPT_TYPE_SETTING_MAP.values());
}
public Iterable<Setting<ScriptMode>> getScriptContextSettings() {
public Iterable<Setting<Boolean>> getScriptContextSettings() {
return Collections.unmodifiableCollection(scriptContextSettingMap.values());
}
public Iterable<Setting<ScriptMode>> getScriptLanguageSettings() {
public Iterable<Setting<Boolean>> getScriptLanguageSettings() {
return scriptLanguageSettings;
}

View File

@ -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<QB extends AbstractQueryBuilder<QB>>
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);

View File

@ -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<ScriptEngineService> 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);

View File

@ -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<String, NativeScriptFactory> nativeScriptFactoryMap = new HashMap<>();
nativeScriptFactoryMap.put("my", new MyNativeScriptFactory());
Set<ScriptEngineService> 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);

View File

@ -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<ScriptEngineService> 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<ScriptContext.Plugin> customContexts = Arrays.asList(
new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"),

View File

@ -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<ScriptType> 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<ScriptContext> 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);
}
}

View File

@ -71,12 +71,12 @@ public class ScriptServiceTests extends ESTestCase {
private Path scriptsFilePath;
private Settings baseSettings;
private static final Map<ScriptType, ScriptMode> DEFAULT_SCRIPT_MODES = new HashMap<>();
private static final Map<ScriptType, Boolean> 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<ScriptEngineRegistry.ScriptEngineRegistration> 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<ScriptType, ScriptMode> scriptSourceSettings = new HashMap<>();
Map<ScriptType, Boolean> 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<ScriptContext, ScriptMode> scriptContextSettings = new HashMap<>();
Map<ScriptContext, Boolean> 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<String, ScriptMode> engineSettings = new HashMap<>();
Map<String, Boolean> 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<ScriptType, ScriptMode> 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<ScriptType, Boolean> entry : scriptSourceSettings.entrySet()) {
if (entry.getValue()) {
builder.put("script" + "." + entry.getKey().getScriptType(), "true");
} else {
builder.put("script" + "." + entry.getKey().getScriptType(), "false");
}
}
for (Map.Entry<ScriptContext, ScriptMode> 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<ScriptContext, Boolean> entry : scriptContextSettings.entrySet()) {
if (entry.getValue()) {
builder.put("script" + "." + entry.getKey().getKey(), "true");
} else {
builder.put("script" + "." + entry.getKey().getKey(), "false");
}
}
for (Map.Entry<String, ScriptMode> entry : engineSettings.entrySet()) {
for (Map.Entry<String, Boolean> 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);
}
}
}

View File

@ -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();

View File

@ -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);

View File

@ -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<AB extends AggregationBuilder<AB>>
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);

View File

@ -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<AF extends PipelineAggrega
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);

View File

@ -28,7 +28,6 @@ import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
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.ScriptType;
import org.elasticsearch.script.SearchScript;
@ -370,7 +369,7 @@ public class AvgIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.NAME, true));
}
}
@ -490,7 +489,7 @@ public class AvgIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, true));
}
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
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.ScriptType;
import org.elasticsearch.script.SearchScript;
@ -365,7 +364,7 @@ public class SumIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.NAME, true));
}
}
@ -487,7 +486,7 @@ public class SumIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, true));
}
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
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.ScriptType;
import org.elasticsearch.script.SearchScript;
@ -224,7 +223,7 @@ public class ValueCountIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.NAME, true));
}
}

View File

@ -62,7 +62,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;
@ -155,7 +154,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
ScriptEngineRegistry scriptEngineRegistry = 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);

View File

@ -43,7 +43,6 @@ import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
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.SearchScript;
@ -94,7 +93,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PutFieldValuesScriptEngine.class, PutFieldValuesScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PutFieldValuesScriptEngine.class, PutFieldValuesScriptEngine.NAME, true));
}
}
@ -181,7 +180,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldIncrementScriptEngine.class, FieldIncrementScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldIncrementScriptEngine.class, FieldIncrementScriptEngine.NAME, true));
}
}
@ -261,7 +260,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ScriptedUpsertScriptEngine.class, ScriptedUpsertScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ScriptedUpsertScriptEngine.class, ScriptedUpsertScriptEngine.NAME, true));
}
}
@ -341,7 +340,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractContextInSourceScriptEngine.class, ExtractContextInSourceScriptEngine.NAME, ScriptMode.ON));
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractContextInSourceScriptEngine.class, ExtractContextInSourceScriptEngine.NAME, true));
}
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.script.expression;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.script.ScriptModule;
public class ExpressionPlugin extends Plugin {
@ -38,6 +37,6 @@ public class ExpressionPlugin extends Plugin {
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExpressionScriptEngineService.class,
ExpressionScriptEngineService.NAME, ScriptMode.ON));
ExpressionScriptEngineService.NAME, true));
}
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.script.mustache;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.script.ScriptModule;
public class MustachePlugin extends Plugin {
@ -38,6 +37,6 @@ public class MustachePlugin extends Plugin {
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class,
MustacheScriptEngineService.NAME, ScriptMode.ON));
MustacheScriptEngineService.NAME, true));
}
}

View File

@ -59,7 +59,6 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
@ -107,7 +106,7 @@ public class TemplateQueryParserTests extends ESTestCase {
ScriptModule scriptModule = new ScriptModule();
scriptModule.prepareSettings(settingsModule);
// TODO: make this use a mock engine instead of mustache and it will no longer be messy!
scriptModule.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.NAME, ScriptMode.ON));
scriptModule.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.NAME, true));
settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED);
injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)),

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.script.ScriptModule;
/**
@ -47,6 +46,6 @@ public final class PainlessPlugin extends Plugin {
public void onModule(final ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(
PainlessScriptEngineService.class, PainlessScriptEngineService.NAME, ScriptMode.ON));
PainlessScriptEngineService.class, PainlessScriptEngineService.NAME, true));
}
}

View File

@ -24,7 +24,6 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.ingest.core.TemplateService;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
@ -48,7 +47,7 @@ public abstract class AbstractMustacheTestCase extends ESTestCase {
new ScriptEngineRegistry(Collections.singletonList(
new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class,
MustacheScriptEngineService.NAME,
ScriptMode.ON)));
true)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService = new ScriptService(settings, new Environment(settings), Collections.singleton(mustache), null,

View File

@ -23,7 +23,6 @@ import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptMode;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
@ -70,7 +69,7 @@ public class MockScriptEngine implements ScriptEngineService {
public void onModule(ScriptModule module) {
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class,
MockScriptEngine.NAME, ScriptMode.ON));
MockScriptEngine.NAME, true));
}
}