Merge remote-tracking branch 'dakrone/prop-script-settings'

This commit is contained in:
Lee Hinman 2016-08-26 13:53:48 -06:00
commit abdd1b6f86
2 changed files with 35 additions and 1 deletions

View File

@ -97,9 +97,25 @@ public class ScriptSettings {
}
final boolean defaultIfNothingSet = defaultLangAndType;
Function<Settings, String> defaultLangAndTypeFn = settings -> {
final Setting<Boolean> globalTypeSetting = scriptTypeSettingMap.get(scriptType);
final Setting<Boolean> langAndTypeSetting = Setting.boolSetting(ScriptModes.getGlobalKey(language, scriptType),
defaultIfNothingSet, Property.NodeScope);
if (langAndTypeSetting.exists(settings)) {
// fine-grained e.g. script.engine.groovy.inline
return langAndTypeSetting.get(settings).toString();
} else if (globalTypeSetting.exists(settings)) {
// global type - script.inline
return globalTypeSetting.get(settings).toString();
} else {
return Boolean.toString(defaultIfNothingSet);
}
};
// Setting for something like "script.engine.groovy.inline"
final Setting<Boolean> langAndTypeSetting = Setting.boolSetting(ScriptModes.getGlobalKey(language, scriptType),
defaultLangAndType, Property.NodeScope);
defaultLangAndTypeFn, Property.NodeScope);
scriptModeSettings.add(langAndTypeSetting);
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {

View File

@ -20,11 +20,13 @@
package org.elasticsearch.script;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.test.ESTestCase;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import static org.hamcrest.Matchers.containsString;
@ -64,6 +66,22 @@ public class ScriptSettingsTests extends ESTestCase {
}
}
public void testSettingsAreProperlyPropogated() {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new CustomScriptEngineService()));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
boolean enabled = randomBoolean();
Settings s = Settings.builder().put("script.inline", enabled).build();
for (Iterator<Setting<Boolean>> iter = scriptSettings.getScriptLanguageSettings().iterator(); iter.hasNext();) {
Setting<Boolean> setting = iter.next();
if (setting.getKey().endsWith(".inline")) {
assertThat("inline settings should have propagated", setting.get(s), equalTo(enabled));
assertThat(setting.getDefaultRaw(s), equalTo(Boolean.toString(enabled)));
}
}
}
private static class CustomScriptEngineService implements ScriptEngineService {
public static final String NAME = "custom";