Script mode settings as booleans

This commit modifies the accept values for script mode settings from
"on", "off", and "sandbox" to "true", "false", and "sandbox".
This commit is contained in:
Jason Tedor 2016-01-26 17:13:06 -05:00
parent 9944573449
commit 284cc3a048
21 changed files with 71 additions and 71 deletions

View File

@ -28,8 +28,8 @@ import java.util.Map;
* only be executed by a sandboxed scripting language.
*/
enum ScriptMode {
ON("on"),
OFF("off"),
ON("true"),
OFF("false"),
SANDBOX("sandbox");
private final String mode;

View File

@ -145,7 +145,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
this.parseFieldMatcher = new ParseFieldMatcher(settings);
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
throw new IllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml");
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: true` and `script.indexed: true` in elasticsearch.yml");
}
this.scriptEngines = scriptEngines;

View File

@ -117,13 +117,13 @@ public class ScriptSettings {
return languageSettings.keySet().iterator().next();
}
// the next fallback is global operation-based settings (e.g., "script.aggs: off")
// the next fallback is global operation-based settings (e.g., "script.aggs: false")
Setting<ScriptMode> setting = scriptContextSettingMap.get(scriptContext);
if (setting.exists(settings)) {
return setting.get(settings).getMode();
}
// the next fallback is global source-based settings (e.g., "script.inline: off")
// the next fallback is global source-based settings (e.g., "script.inline: false")
Setting<ScriptMode> scriptTypeSetting = scriptTypeSettingMap.get(scriptType);
if (scriptTypeSetting.exists(settings)) {
return scriptTypeSetting.get(settings).getMode();

View File

@ -54,7 +54,7 @@ public class FileScriptTests extends ESTestCase {
public void testFileScriptFound() throws Exception {
ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
Settings settings = Settings.builder()
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "off").build();
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false").build();
ScriptService scriptService = makeScriptService(settings);
Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null);
assertNotNull(scriptService.compile(script, ScriptContext.Standard.SEARCH, contextAndHeaders, Collections.emptyMap()));
@ -67,7 +67,7 @@ public class FileScriptTests extends ESTestCase {
.put("script.engine." + MockScriptEngine.NAME + ".file.search", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.mapping", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.update", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.ingest", false).build();
.put("script.engine." + MockScriptEngine.NAME + ".file.ingest", "false").build();
ScriptService scriptService = makeScriptService(settings);
Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null);
for (ScriptContext context : ScriptContext.Standard.values()) {

View File

@ -41,8 +41,8 @@ public class ScriptContextTests extends ESTestCase {
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
// no file watching, so we don't need a ResourceWatcherService
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "off")
.put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "off")
.put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "off")
.put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "false")
.put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "false")
.build();
Set<ScriptEngineService> engines = new HashSet<>(Collections.singletonList(new MockScriptEngine()));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES)));

View File

@ -47,8 +47,8 @@ public class ScriptModesTests extends ESTestCase {
private static final Set<String> ALL_LANGS = unmodifiableSet(
newHashSet("custom", "test"));
static final String[] ENABLE_VALUES = new String[]{"on"};
static final String[] DISABLE_VALUES = new String[]{"off"};
static final String[] ENABLE_VALUES = new String[]{"true"};
static final String[] DISABLE_VALUES = new String[]{"false"};
ScriptSettings scriptSettings;
ScriptContextRegistry scriptContextRegistry;
@ -185,7 +185,7 @@ public class ScriptModesTests extends ESTestCase {
public void testConflictingScriptTypeAndOpGenericSettings() {
ScriptContext scriptContext = randomFrom(scriptContexts);
Settings.Builder builder = Settings.builder().put("script" + "." + scriptContext.getKey(), randomFrom(DISABLE_VALUES))
.put("script.indexed", randomFrom(ENABLE_VALUES)).put("script.inline", ScriptMode.SANDBOX);
.put("script.indexed", randomFrom(ENABLE_VALUES)).put("script.inline", "sandbox");
//operations generic settings have precedence over script type generic settings
this.scriptModes = new ScriptModes(scriptSettings, builder.build());
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, scriptContext);

View File

@ -193,10 +193,10 @@ public class ScriptServiceTests extends ESTestCase {
builder.put("script.file", randomFrom(ScriptModesTests.ENABLE_VALUES));
}
if (rarely()) {
builder.put("script.indexed", ScriptMode.SANDBOX);
builder.put("script.indexed", "sandbox");
}
if (rarely()) {
builder.put("script.inline", ScriptMode.SANDBOX);
builder.put("script.inline", "sandbox");
}
buildScriptService(builder.build());
createFileScripts("groovy", "mustache", "test");
@ -246,10 +246,10 @@ public class ScriptServiceTests extends ESTestCase {
for (Map.Entry<ScriptType, ScriptMode> entry : scriptSourceSettings.entrySet()) {
switch (entry.getValue()) {
case ON:
builder.put("script" + "." + entry.getKey().getScriptType(), "on");
builder.put("script" + "." + entry.getKey().getScriptType(), "true");
break;
case OFF:
builder.put("script" + "." + entry.getKey().getScriptType(), "off");
builder.put("script" + "." + entry.getKey().getScriptType(), "false");
break;
case SANDBOX:
builder.put("script" + "." + entry.getKey().getScriptType(), "sandbox");
@ -259,11 +259,11 @@ public class ScriptServiceTests extends ESTestCase {
for (Map.Entry<ScriptContext, ScriptMode> entry : scriptContextSettings.entrySet()) {
switch (entry.getValue()) {
case ON:
builder.put("script" + "." + entry.getKey().getKey(), "on");
builder.put("script" + "." + entry.getKey().getKey(), "true");
break;
case OFF:
builder.put("script" + "." + entry.getKey().getKey(), "off");
builder.put("script" + "." + entry.getKey().getKey(), "false");
break;
case SANDBOX:
builder.put("script" + "." + entry.getKey().getKey(), "sandbox");
@ -278,10 +278,10 @@ public class ScriptServiceTests extends ESTestCase {
String lang = randomFrom(scriptEnginesByLangMap.get(part1).getTypes());
switch (entry.getValue()) {
case ON:
builder.put("script.engine" + "." + lang + "." + part2, "on");
builder.put("script.engine" + "." + lang + "." + part2, "true");
break;
case OFF:
builder.put("script.engine" + "." + lang + "." + part2, "off");
builder.put("script.engine" + "." + lang + "." + part2, "false");
break;
case SANDBOX:
builder.put("script.engine" + "." + lang + "." + part2, "sandbox");

View File

@ -104,7 +104,7 @@ public class FunctionScoreBackwardCompatibilityIT extends ESBackcompatTestCase {
@Override
protected Settings commonNodeSettings(int nodeOrdinal) {
return Settings.builder().put(super.commonNodeSettings(nodeOrdinal))
.put("script.inline", "on").build();
.put("script.inline", "true").build();
}
private void checkFunctionScoreStillWorks(String... ids) throws ExecutionException, InterruptedException, IOException {

View File

@ -194,7 +194,7 @@ def smoke_test_release(release, files, expected_hash, plugins):
headers = {}
print(' Starting elasticsearch deamon from [%s]' % os.path.join(tmp_dir, 'elasticsearch-%s' % release))
try:
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.script.inline=on -Des.script.indexed=on -Des.repositories.url.allowed_urls=http://snapshot.test* %s -Des.pidfile=%s'
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.script.inline=true -Des.script.indexed=true -Des.repositories.url.allowed_urls=http://snapshot.test* %s -Des.pidfile=%s'
% (java_exe(), es_run_path, '-d', os.path.join(tmp_dir, 'elasticsearch-%s' % (release), 'es-smoke.pid')))
conn = HTTPConnection(host='127.0.0.1', port=9200, timeout=20)
if not wait_for_node_startup(header=headers):

View File

@ -691,9 +691,9 @@ settings can be modified by editing the elasticsearch.service file.
==== Script mode settings
Previously script mode settings (e.g., "script.inline: on",
"script.engine.groovy.inline.aggs: off", etc.) accepted the values
Previously script mode settings (e.g., "script.inline: true",
"script.engine.groovy.inline.aggs: false", etc.) accepted the values
`on`, `true`, `1`, and `yes` for enabling a scripting mode, and the
values `off`, `false`, `0`, and `no` for disabling a scripting mode.
The variants `true`, `1`, and `yes ` for enabling and `false`, `0`,
The variants `on`, `1`, and `yes ` for enabling and `off`, `0`,
and `no` for disabling are no longer supported.

View File

@ -244,8 +244,8 @@ every script engine, through the following settings that need to be added to the
[source,yaml]
-----------------------------------
script.inline: on
script.indexed: on
script.inline: true
script.indexed: true
-----------------------------------
@ -261,8 +261,8 @@ script settings:
[cols="<,<",options="header",]
|=======================================================================
|Value |Description
| `off` |scripting is turned off completely, in the context of the setting being set.
| `on` |scripting is turned on, in the context of the setting being set.
| `false` |scripting is turned off completely, in the context of the setting being set.
| `true` |scripting is turned on, in the context of the setting being set.
| `sandbox` |scripts may be executed only for languages that are sandboxed
|=======================================================================
@ -272,7 +272,7 @@ The default values are the following:
-----------------------------------
script.inline: sandbox
script.indexed: sandbox
script.file: on
script.file: true
-----------------------------------
@ -305,8 +305,8 @@ and plugins execution though, as the above defaults still get applied.
[source,yaml]
-----------------------------------
script.update: off
script.mapping: off
script.update: false
script.mapping: false
-----------------------------------
@ -317,21 +317,21 @@ precedence over any other generic settings.
[source,yaml]
-----------------------------------
script.engine.groovy.file.aggs: on
script.engine.groovy.file.mapping: on
script.engine.groovy.file.search: on
script.engine.groovy.file.update: on
script.engine.groovy.file.plugin: on
script.engine.groovy.indexed.aggs: on
script.engine.groovy.indexed.mapping: off
script.engine.groovy.indexed.search: on
script.engine.groovy.indexed.update: off
script.engine.groovy.indexed.plugin: off
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.mapping: off
script.engine.groovy.inline.search: off
script.engine.groovy.inline.update: off
script.engine.groovy.inline.plugin: off
script.engine.groovy.file.aggs: true
script.engine.groovy.file.mapping: true
script.engine.groovy.file.search: true
script.engine.groovy.file.update: true
script.engine.groovy.file.plugin: true
script.engine.groovy.indexed.aggs: true
script.engine.groovy.indexed.mapping: false
script.engine.groovy.indexed.search: true
script.engine.groovy.indexed.update: false
script.engine.groovy.indexed.plugin: false
script.engine.groovy.inline.aggs: true
script.engine.groovy.inline.mapping: false
script.engine.groovy.inline.search: false
script.engine.groovy.inline.update: false
script.engine.groovy.inline.plugin: false
-----------------------------------

View File

@ -39,9 +39,9 @@ public class IndexedExpressionTests extends ESIntegTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
builder.put("script.engine.expression.indexed.update", "off");
builder.put("script.engine.expression.indexed.search", "off");
builder.put("script.engine.expression.indexed.mapping", "off");
builder.put("script.engine.expression.indexed.update", "false");
builder.put("script.engine.expression.indexed.search", "false");
builder.put("script.engine.expression.indexed.mapping", "false");
return builder.build();
}

View File

@ -28,8 +28,8 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -91,7 +91,7 @@ public class ContextAndHeaderTransportTests extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("script.indexed", "on")
.put("script.indexed", "true")
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -60,13 +60,13 @@ public class IndexedScriptTests extends ESIntegTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
builder.put("script.engine.groovy.indexed.update", "off");
builder.put("script.engine.groovy.indexed.search", "on");
builder.put("script.engine.groovy.indexed.aggs", "on");
builder.put("script.engine.groovy.inline.aggs", "off");
builder.put("script.engine.expression.indexed.update", "off");
builder.put("script.engine.expression.indexed.search", "off");
builder.put("script.engine.expression.indexed.mapping", "off");
builder.put("script.engine.groovy.indexed.update", "false");
builder.put("script.engine.groovy.indexed.search", "true");
builder.put("script.engine.groovy.indexed.aggs", "true");
builder.put("script.engine.groovy.inline.aggs", "false");
builder.put("script.engine.expression.indexed.update", "false");
builder.put("script.engine.expression.indexed.search", "false");
builder.put("script.engine.expression.indexed.mapping", "false");
return builder.build();
}

View File

@ -28,7 +28,7 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -86,7 +86,7 @@ public class ContextAndHeaderTransportTests extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("script.indexed", "on")
.put("script.indexed", "true")
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -28,7 +28,7 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -28,8 +28,8 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -1682,8 +1682,8 @@ public abstract class ESIntegTestCase extends ESTestCase {
// from failing on nodes without enough disk space
.put(DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b")
.put(DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b")
.put("script.indexed", "on")
.put("script.inline", "on")
.put("script.indexed", "true")
.put("script.inline", "true")
// wait short time for other active shards before actually deleting, default 30s not needed in tests
.put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT.getKey(), new TimeValue(1, TimeUnit.SECONDS));
return builder.build();

View File

@ -166,8 +166,8 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
.put("node.name", nodeName())
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("script.inline", "on")
.put("script.indexed", "on")
.put("script.inline", "true")
.put("script.indexed", "true")
.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created
.put("http.enabled", false)
.put(Node.NODE_LOCAL_SETTING.getKey(), true)