diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy index 60e50a97ad0e3..75653d92b63fc 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy @@ -180,12 +180,14 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { } if (test.setup != null) { // Insert a setup defined outside of the docs - String setup = setups[test.setup] - if (setup == null) { - throw new InvalidUserDataException("Couldn't find setup " - + "for $test") + for (String setupName : test.setup.split(',')) { + String setup = setups[setupName] + if (setup == null) { + throw new InvalidUserDataException("Couldn't find setup " + + "for $test") + } + current.println(setup) } - current.println(setup) } body(test, false) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java index 269606c9cc201..01a5eb5dfc12d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java @@ -338,7 +338,7 @@ public void testScript() { Map parameters = new HashMap<>(); parameters.put("param1", 5); scriptQuery(new Script( - ScriptType.FILE, // <1> + ScriptType.STORED, // <1> "painless", // <2> "myscript", // <3> singletonMap("param1", 5))); // <4> diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Security.java b/core/src/main/java/org/elasticsearch/bootstrap/Security.java index 2af6ee33b374f..384d4dd3352be 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -256,7 +256,6 @@ static void addFilePermissions(Permissions policy, Environment environment) { addPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.modulesFile(), "read,readlink"); addPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.pluginsFile(), "read,readlink"); addPath(policy, Environment.PATH_CONF_SETTING.getKey(), environment.configFile(), "read,readlink"); - addPath(policy, Environment.PATH_SCRIPTS_SETTING.getKey(), environment.scriptsFile(), "read,readlink"); // read-write dirs addPath(policy, "java.io.tmpdir", environment.tmpFile(), "read,readlink,write,delete"); addPath(policy, Environment.PATH_LOGS_SETTING.getKey(), environment.logsFile(), "read,readlink,write,delete"); diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index e79d46bb55569..9b96f407f33e3 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -302,7 +302,6 @@ public void apply(Settings value, Settings current, Settings previous) { IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD, ScriptService.SCRIPT_CACHE_SIZE_SETTING, ScriptService.SCRIPT_CACHE_EXPIRE_SETTING, - ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, ScriptService.SCRIPT_MAX_SIZE_IN_BYTES, ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE, IndicesService.INDICES_CACHE_CLEAN_INTERVAL_SETTING, @@ -321,7 +320,6 @@ public void apply(Settings value, Settings current, Settings previous) { Environment.DEFAULT_PATH_LOGS_SETTING, Environment.PATH_LOGS_SETTING, Environment.PATH_REPO_SETTING, - Environment.PATH_SCRIPTS_SETTING, Environment.PATH_SHARED_DATA_SETTING, Environment.PIDFILE_SETTING, NodeEnvironment.NODE_ID_SEED_SETTING, diff --git a/core/src/main/java/org/elasticsearch/env/Environment.java b/core/src/main/java/org/elasticsearch/env/Environment.java index 7ac442d716549..bdf3d76fa9acd 100644 --- a/core/src/main/java/org/elasticsearch/env/Environment.java +++ b/core/src/main/java/org/elasticsearch/env/Environment.java @@ -55,8 +55,6 @@ public class Environment { public static final Setting DEFAULT_PATH_CONF_SETTING = Setting.simpleString("default.path.conf", Property.NodeScope); public static final Setting PATH_CONF_SETTING = new Setting<>("path.conf", DEFAULT_PATH_CONF_SETTING, Function.identity(), Property.NodeScope); - public static final Setting PATH_SCRIPTS_SETTING = - Setting.simpleString("path.scripts", Property.NodeScope, Property.Deprecated); public static final Setting> DEFAULT_PATH_DATA_SETTING = Setting.listSetting("default.path.data", Collections.emptyList(), Function.identity(), Property.NodeScope); public static final Setting> PATH_DATA_SETTING = @@ -79,8 +77,6 @@ public class Environment { private final Path configFile; - private final Path scriptsFile; - private final Path pluginsFile; private final Path modulesFile; @@ -116,12 +112,6 @@ public Environment(Settings settings) { configFile = homeFile.resolve("config"); } - if (PATH_SCRIPTS_SETTING.exists(settings)) { - scriptsFile = PathUtils.get(cleanPath(PATH_SCRIPTS_SETTING.get(settings))); - } else { - scriptsFile = configFile.resolve("scripts"); - } - pluginsFile = homeFile.resolve("plugins"); List dataPaths = PATH_DATA_SETTING.get(settings); @@ -281,13 +271,6 @@ public Path configFile() { return configFile; } - /** - * Location of on-disk scripts - */ - public Path scriptsFile() { - return scriptsFile; - } - public Path pluginsFile() { return pluginsFile; } @@ -332,7 +315,6 @@ public static void assertEquivalent(Environment actual, Environment expected) { assertEquals(actual.dataWithClusterFiles(), expected.dataWithClusterFiles(), "dataWithClusterFiles"); assertEquals(actual.repoFiles(), expected.repoFiles(), "repoFiles"); assertEquals(actual.configFile(), expected.configFile(), "configFile"); - assertEquals(actual.scriptsFile(), expected.scriptsFile(), "scriptsFile"); assertEquals(actual.pluginsFile(), expected.pluginsFile(), "pluginsFile"); assertEquals(actual.binFile(), expected.binFile(), "binFile"); assertEquals(actual.libFile(), expected.libFile(), "libFile"); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 08f9856c76647..bbda2869ff7f6 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -325,8 +325,7 @@ protected Node(final Environment environment, Collection } client = new NodeClient(settings, threadPool); final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool); - final ScriptModule scriptModule = ScriptModule.create(settings, this.environment, resourceWatcherService, - pluginsService.filterPlugins(ScriptPlugin.class)); + final ScriptModule scriptModule = ScriptModule.create(settings, pluginsService.filterPlugins(ScriptPlugin.class)); AnalysisModule analysisModule = new AnalysisModule(this.environment, pluginsService.filterPlugins(AnalysisPlugin.class)); additionalSettings.addAll(scriptModule.getSettings()); // this is as early as we can validate settings at this point. we already pass them to ScriptModule as well as ThreadPool diff --git a/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java b/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java index 1b3fb23a7f9a5..af1185f17420f 100644 --- a/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java +++ b/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java @@ -57,11 +57,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return ""; // Native scripts have no extensions - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { NativeScriptFactory scriptFactory = scripts.get(scriptSource); diff --git a/core/src/main/java/org/elasticsearch/script/Script.java b/core/src/main/java/org/elasticsearch/script/Script.java index 7397ecfd89056..f9b67e31b9954 100644 --- a/core/src/main/java/org/elasticsearch/script/Script.java +++ b/core/src/main/java/org/elasticsearch/script/Script.java @@ -74,15 +74,6 @@ *
  • {@link Script#params} - {@link Map} of user-defined parameters; must not be {@code null}, * use an empty {@link Map} to specify no params * - *
  • {@link ScriptType#FILE} - *
      - *
    • {@link Script#lang} - specifies the language for look up, defaults to {@link Script#DEFAULT_SCRIPT_LANG} - *
    • {@link Script#idOrCode} - specifies the id of the file script to be looked up, must not be {@code null} - *
    • {@link Script#options} - compiler options will be specified when a file script is loaded, - * so they have no meaning here and must be {@code null} - *
    • {@link Script#params} - {@link Map} of user-defined parameters; must not be {@code null}, - * use an empty {@link Map} to specify no params - *
    * */ public final class Script implements ToXContentObject, Writeable { @@ -193,26 +184,13 @@ private void setStored(String idOrCode) { this.idOrCode = idOrCode; } - /** - * Set both the id and the type of the file script. - */ - private void setFile(String idOrCode) { - if (type != null) { - throwOnlyOneOfType(); - } - - type = ScriptType.FILE; - this.idOrCode = idOrCode; - } - /** * Helper method to throw an exception if more than one type of {@link Script} is specified. */ private void throwOnlyOneOfType() { throw new IllegalArgumentException("must only use one of [" + - ScriptType.INLINE.getParseField().getPreferredName() + " + , " + - ScriptType.STORED.getParseField().getPreferredName() + " + , " + - ScriptType.FILE.getParseField().getPreferredName() + "]" + + ScriptType.INLINE.getParseField().getPreferredName() + ", " + + ScriptType.STORED.getParseField().getPreferredName() + "]" + " when specifying a script"); } @@ -242,8 +220,7 @@ private Script build(String defaultLang) { if (type == null) { throw new IllegalArgumentException( "must specify either code for an [" + ScriptType.INLINE.getParseField().getPreferredName() + "] script " + - "or an id for a [" + ScriptType.STORED.getParseField().getPreferredName() + "] script " + - "or [" + ScriptType.FILE.getParseField().getPreferredName() + "] script"); + "or an id for a [" + ScriptType.STORED.getParseField().getPreferredName() + "] script"); } if (type == ScriptType.INLINE) { @@ -283,22 +260,6 @@ private Script build(String defaultLang) { throw new IllegalArgumentException("field [" + OPTIONS_PARSE_FIELD.getPreferredName() + "] " + "cannot be specified using a [" + ScriptType.STORED.getParseField().getPreferredName() + "] script"); } - } else if (type == ScriptType.FILE) { - if (lang == null) { - lang = defaultLang; - } - - if (idOrCode == null) { - throw new IllegalArgumentException( - "must specify for an [" + ScriptType.FILE.getParseField().getPreferredName() + "] script"); - } - - if (options.isEmpty()) { - options = null; - } else { - throw new IllegalArgumentException("field [" + OPTIONS_PARSE_FIELD.getPreferredName() + "] " + - "cannot be specified using a [" + ScriptType.FILE.getParseField().getPreferredName() + "] script"); - } } return new Script(type, lang, idOrCode, options, params); @@ -311,7 +272,6 @@ private Script build(String defaultLang) { // Defines the fields necessary to parse a Script as XContent using an ObjectParser. PARSER.declareField(Builder::setInline, parser -> parser, ScriptType.INLINE.getParseField(), ValueType.OBJECT_OR_STRING); PARSER.declareString(Builder::setStored, ScriptType.STORED.getParseField()); - PARSER.declareString(Builder::setFile, ScriptType.FILE.getParseField()); PARSER.declareString(Builder::setLang, LANG_PARSE_FIELD); PARSER.declareField(Builder::setOptions, XContentParser::mapStrings, OPTIONS_PARSE_FIELD, ValueType.OBJECT); PARSER.declareField(Builder::setParams, XContentParser::map, PARAMS_PARSE_FIELD, ValueType.OBJECT); @@ -425,10 +385,10 @@ public Script(String idOrCode) { /** * Constructor for a script that does not need to use compiler options. * @param type The {@link ScriptType}. - * @param lang The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE} or - * {@link ScriptType#FILE}. For {@link ScriptType#STORED} scripts this should be null, but can + * @param lang The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. + * For {@link ScriptType#STORED} scripts this should be null, but can * be specified to access scripts stored as part of the stored scripts deprecated API. - * @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}. + * @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#STORED}. * The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. * @param params The user-defined params to be bound for script execution. */ @@ -439,10 +399,10 @@ public Script(ScriptType type, String lang, String idOrCode, Map /** * Constructor for a script that requires the use of compiler options. * @param type The {@link ScriptType}. - * @param lang The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE} or - * {@link ScriptType#FILE}. For {@link ScriptType#STORED} scripts this should be null, but can + * @param lang The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. + * For {@link ScriptType#STORED} scripts this should be null, but can * be specified to access scripts stored as part of the stored scripts deprecated API. - * @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}. + * @param idOrCode The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#STORED}. * The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. * @param options The map of compiler options for this {@link Script} if the {@link ScriptType} * is {@link ScriptType#INLINE}, {@code null} otherwise. @@ -464,15 +424,6 @@ public Script(ScriptType type, String lang, String idOrCode, Map "options must be null for [" + ScriptType.STORED.getParseField().getPreferredName() + "] scripts"); } - this.options = null; - } else if (type == ScriptType.FILE) { - this.lang = Objects.requireNonNull(lang); - - if (options != null) { - throw new IllegalStateException( - "options must be null for [" + ScriptType.FILE.getParseField().getPreferredName() + "] scripts"); - } - this.options = null; } else { throw new IllegalStateException("unknown script type [" + type.getName() + "]"); @@ -701,8 +652,8 @@ public ScriptType getType() { } /** - * @return The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE} or - * {@link ScriptType#FILE}. For {@link ScriptType#STORED} scripts this should be null, but can + * @return The language for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. + * For {@link ScriptType#STORED} scripts this should be null, but can * be specified to access scripts stored as part of the stored scripts deprecated API. */ public String getLang() { @@ -710,7 +661,7 @@ public String getLang() { } /** - * @return The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#FILE} or {@link ScriptType#STORED}. + * @return The id for this {@link Script} if the {@link ScriptType} is {@link ScriptType#STORED}. * The code for this {@link Script} if the {@link ScriptType} is {@link ScriptType#INLINE}. */ public String getIdOrCode() { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngine.java b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java index 78a1478a9c9c9..e9c92ddd4199a 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngine.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java @@ -35,13 +35,6 @@ public interface ScriptEngine extends Closeable { */ String getType(); - /** - * The extension for file scripts in this language. - */ - default String getExtension() { - return getType(); - } - /** * Compiles a script. * @param scriptName name of the script. {@code null} if it is anonymous (inline). diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java index ff03c2526563b..307a16d8b2caa 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -42,10 +42,9 @@ public class ScriptModule { /** * Build from {@linkplain ScriptPlugin}s. Convenient for normal use but not great for tests. See - * {@link ScriptModule#ScriptModule(Settings, Environment, ResourceWatcherService, List, List)} for easier use in tests. + * {@link ScriptModule#ScriptModule(Settings, List, List)} for easier use in tests. */ - public static ScriptModule create(Settings settings, Environment environment, - ResourceWatcherService resourceWatcherService, List scriptPlugins) { + public static ScriptModule create(Settings settings, List scriptPlugins) { Map factoryMap = scriptPlugins.stream().flatMap(x -> x.getNativeScripts().stream()) .collect(Collectors.toMap(NativeScriptFactory::getName, Function.identity())); NativeScriptEngine nativeScriptEngineService = new NativeScriptEngine(settings, factoryMap); @@ -54,21 +53,19 @@ public static ScriptModule create(Settings settings, Environment environment, scriptEngines.add(nativeScriptEngineService); List plugins = scriptPlugins.stream().map(x -> x.getCustomScriptContexts()).filter(Objects::nonNull) .collect(Collectors.toList()); - return new ScriptModule(settings, environment, resourceWatcherService, scriptEngines, plugins); + return new ScriptModule(settings, scriptEngines, plugins); } /** * Build {@linkplain ScriptEngine} and {@linkplain ScriptContext.Plugin}. */ - public ScriptModule(Settings settings, Environment environment, - ResourceWatcherService resourceWatcherService, List scriptEngines, + public ScriptModule(Settings settings, List scriptEngines, List customScriptContexts) { ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngines); scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); try { - scriptService = new ScriptService(settings, environment, resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, - scriptSettings); + scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings); } catch (IOException e) { throw new RuntimeException("Couldn't setup ScriptService", e); } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index 55b326062d5e1..860bb315606b4 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -19,10 +19,13 @@ package org.elasticsearch.script; -import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.logging.log4j.util.Supplier; +import java.io.Closeable; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; + import org.apache.lucene.util.IOUtils; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; @@ -43,39 +46,14 @@ import org.elasticsearch.common.cache.CacheBuilder; import org.elasticsearch.common.cache.RemovalListener; import org.elasticsearch.common.cache.RemovalNotification; -import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.env.Environment; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.template.CompiledTemplate; -import org.elasticsearch.watcher.FileChangesListener; -import org.elasticsearch.watcher.FileWatcher; -import org.elasticsearch.watcher.ResourceWatcherService; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentMap; - -import static java.util.Collections.unmodifiableMap; public class ScriptService extends AbstractComponent implements Closeable, ClusterStateListener { @@ -85,21 +63,14 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust Setting.intSetting("script.cache.max_size", 100, 0, Property.NodeScope); public static final Setting SCRIPT_CACHE_EXPIRE_SETTING = Setting.positiveTimeSetting("script.cache.expire", TimeValue.timeValueMillis(0), Property.NodeScope); - public static final Setting SCRIPT_AUTO_RELOAD_ENABLED_SETTING = - Setting.boolSetting("script.auto_reload_enabled", true, Property.NodeScope, Property.Deprecated); public static final Setting SCRIPT_MAX_SIZE_IN_BYTES = Setting.intSetting("script.max_size_in_bytes", 65535, Property.NodeScope); public static final Setting SCRIPT_MAX_COMPILATIONS_PER_MINUTE = Setting.intSetting("script.max_compilations_per_minute", 15, 0, Property.Dynamic, Property.NodeScope); - private final Collection scriptEngines; - private final Map scriptEnginesByLang; - private final Map scriptEnginesByExt; - - private final ConcurrentMap staticCache = ConcurrentCollections.newConcurrentMap(); + private final Map engines; private final Cache cache; - private final Path scriptsDirectory; private final ScriptModes scriptModes; private final ScriptContextRegistry scriptContextRegistry; @@ -113,8 +84,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust private double scriptsPerMinCounter; private double compilesAllowedPerNano; - public ScriptService(Settings settings, Environment env, - ResourceWatcherService resourceWatcherService, ScriptEngineRegistry scriptEngineRegistry, + public ScriptService(Settings settings, ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry, ScriptSettings scriptSettings) throws IOException { super(settings); Objects.requireNonNull(scriptEngineRegistry); @@ -125,7 +95,6 @@ public ScriptService(Settings settings, Environment env, "Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: true` and `script.stored: true` in elasticsearch.yml"); } - this.scriptEngines = scriptEngineRegistry.getRegisteredLanguages().values(); this.scriptContextRegistry = scriptContextRegistry; int cacheMaxSize = SCRIPT_CACHE_SIZE_SETTING.get(settings); @@ -141,35 +110,8 @@ public ScriptService(Settings settings, Environment env, logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire); this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build(); - - Map enginesByLangBuilder = new HashMap<>(); - Map enginesByExtBuilder = new HashMap<>(); - for (ScriptEngine scriptEngine : scriptEngines) { - String language = scriptEngineRegistry.getLanguage(scriptEngine.getClass()); - enginesByLangBuilder.put(language, scriptEngine); - enginesByExtBuilder.put(scriptEngine.getExtension(), scriptEngine); - } - this.scriptEnginesByLang = unmodifiableMap(enginesByLangBuilder); - this.scriptEnginesByExt = unmodifiableMap(enginesByExtBuilder); - + this.engines = scriptEngineRegistry.getRegisteredLanguages(); this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, settings); - - // add file watcher for static scripts - scriptsDirectory = env.scriptsFile(); - if (logger.isTraceEnabled()) { - logger.trace("Using scripts directory [{}] ", scriptsDirectory); - } - FileWatcher fileWatcher = new FileWatcher(scriptsDirectory); - fileWatcher.addListener(new ScriptChangesListener()); - - if (SCRIPT_AUTO_RELOAD_ENABLED_SETTING.get(settings) && resourceWatcherService != null) { - // automatic reload is enabled - register scripts - resourceWatcherService.add(fileWatcher); - } else { - // automatic reload is disable just load scripts once - fileWatcher.init(); - } - this.lastInlineCompileTime = System.nanoTime(); this.setMaxCompilationsPerMinute(SCRIPT_MAX_COMPILATIONS_PER_MINUTE.get(settings)); } @@ -180,25 +122,17 @@ void registerClusterSettingsListeners(ClusterSettings clusterSettings) { @Override public void close() throws IOException { - IOUtils.close(scriptEngines); + IOUtils.close(engines.values()); } - private ScriptEngine getScriptEngineServiceForLang(String lang) { - ScriptEngine scriptEngine = scriptEnginesByLang.get(lang); + private ScriptEngine getEngine(String lang) { + ScriptEngine scriptEngine = engines.get(lang); if (scriptEngine == null) { throw new IllegalArgumentException("script_lang not supported [" + lang + "]"); } return scriptEngine; } - private ScriptEngine getScriptEngineServiceForFileExt(String fileExtension) { - ScriptEngine scriptEngine = scriptEnginesByExt.get(fileExtension); - if (scriptEngine == null) { - throw new IllegalArgumentException("script file extension not supported [" + fileExtension + "]"); - } - return scriptEngine; - } - void setMaxCompilationsPerMinute(Integer newMaxPerMinute) { this.totalCompilesPerMinute = newMaxPerMinute; // Reset the counter to allow new compilations @@ -258,7 +192,7 @@ public CompiledScript compile(Script script, ScriptContext scriptContext) { " operation [" + scriptContext.getKey() + "] and lang [" + lang + "] are not supported"); } - ScriptEngine scriptEngine = getScriptEngineServiceForLang(lang); + ScriptEngine scriptEngine = getEngine(lang); if (canExecuteScript(lang, type, scriptContext) == false) { throw new IllegalStateException("scripts of type [" + script.getType() + "]," + @@ -269,17 +203,6 @@ public CompiledScript compile(Script script, ScriptContext scriptContext) { logger.trace("compiling lang: [{}] type: [{}] script: {}", lang, type, idOrCode); } - if (type == ScriptType.FILE) { - CacheKey cacheKey = new CacheKey(lang, idOrCode, options); - CompiledScript compiledScript = staticCache.get(cacheKey); - - if (compiledScript == null) { - throw new IllegalArgumentException("unable to find file script [" + idOrCode + "] using lang [" + lang + "]"); - } - - return compiledScript; - } - CacheKey cacheKey = new CacheKey(lang, idOrCode, options); CompiledScript compiledScript = cache.get(cacheKey); @@ -362,8 +285,7 @@ void checkCompilationLimit() { public boolean isLangSupported(String lang) { Objects.requireNonNull(lang); - - return scriptEnginesByLang.containsKey(lang); + return engines.containsKey(lang); } StoredScriptSource getScriptFromClusterState(String id, String lang) { @@ -404,7 +326,7 @@ public void putStoredScript(ClusterService clusterService, PutStoredScriptReques } try { - ScriptEngine scriptEngine = getScriptEngineServiceForLang(source.getLang()); + ScriptEngine scriptEngine = getEngine(source.getLang()); if (isAnyScriptContextEnabled(source.getLang(), ScriptType.STORED)) { Object compiled = scriptEngine.compile(request.id(), source.getCode(), Collections.emptyMap()); @@ -481,7 +403,7 @@ public StoredScriptSource getStoredScript(ClusterState state, GetStoredScriptReq * Executes a previously compiled script provided as an argument */ public ExecutableScript executable(CompiledScript compiledScript, Map params) { - return getScriptEngineServiceForLang(compiledScript.lang()).executable(compiledScript, params); + return getEngine(compiledScript.lang()).executable(compiledScript, params); } /** @@ -497,7 +419,7 @@ public SearchScript search(SearchLookup lookup, Script script, ScriptContext scr * {@link SearchScript} ready for execution */ public SearchScript search(SearchLookup lookup, CompiledScript compiledScript, Map params) { - return getScriptEngineServiceForLang(compiledScript.lang()).search(compiledScript, lookup, params); + return getEngine(compiledScript.lang()).search(compiledScript, lookup, params); } private boolean isAnyScriptContextEnabled(String lang, ScriptType scriptType) { @@ -541,108 +463,6 @@ public void onRemoval(RemovalNotification notification } } - private class ScriptChangesListener implements FileChangesListener { - private boolean deprecationEmitted = false; - - private Tuple getScriptNameExt(Path file) { - Path scriptPath = scriptsDirectory.relativize(file); - int extIndex = scriptPath.toString().lastIndexOf('.'); - if (extIndex <= 0) { - return null; - } - - String ext = scriptPath.toString().substring(extIndex + 1); - if (ext.isEmpty()) { - return null; - } - - String scriptName = scriptPath.toString().substring(0, extIndex).replace(scriptPath.getFileSystem().getSeparator(), "_"); - return new Tuple<>(scriptName, ext); - } - - @Override - public void onFileInit(Path file) { - Tuple scriptNameExt = getScriptNameExt(file); - if (scriptNameExt == null) { - logger.debug("Skipped script with invalid extension : [{}]", file); - return; - } - if (logger.isTraceEnabled()) { - logger.trace("Loading script file : [{}]", file); - } - - ScriptEngine engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); - if (engineService == null) { - logger.warn("No script engine found for [{}]", scriptNameExt.v2()); - } else { - if (deprecationEmitted == false) { - deprecationLogger.deprecated("File scripts are deprecated. Use stored or inline scripts instead."); - deprecationEmitted = true; - } - - try { - //we don't know yet what the script will be used for, but if all of the operations for this lang - // with file scripts are disabled, it makes no sense to even compile it and cache it. - if (isAnyScriptContextEnabled(engineService.getType(), ScriptType.FILE)) { - logger.info("compiling script file [{}]", file.toAbsolutePath()); - try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) { - String script = Streams.copyToString(reader); - String id = scriptNameExt.v1(); - CacheKey cacheKey = new CacheKey(engineService.getType(), id, null); - // pass the actual file name to the compiler (for script engines that care about this) - Object executable = engineService.compile(file.getFileName().toString(), script, Collections.emptyMap()); - CompiledScript compiledScript = new CompiledScript(ScriptType.FILE, id, engineService.getType(), executable); - staticCache.put(cacheKey, compiledScript); - scriptMetrics.onCompilation(); - } - } else { - logger.warn("skipping compile of script file [{}] as all scripted operations are disabled for file scripts", file.toAbsolutePath()); - } - } catch (ScriptException e) { - try (XContentBuilder builder = JsonXContent.contentBuilder()) { - builder.prettyPrint(); - builder.startObject(); - ElasticsearchException.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, e); - builder.endObject(); - logger.warn("failed to load/compile script [{}]: {}", scriptNameExt.v1(), builder.string()); - } catch (IOException ioe) { - ioe.addSuppressed(e); - logger.warn((Supplier) () -> new ParameterizedMessage( - "failed to log an appropriate warning after failing to load/compile script [{}]", scriptNameExt.v1()), ioe); - } - /* Log at the whole exception at the debug level as well just in case the stack trace is important. That way you can - * turn on the stack trace if you need it. */ - logger.debug((Supplier) () -> new ParameterizedMessage("failed to load/compile script [{}]. full exception:", - scriptNameExt.v1()), e); - } catch (Exception e) { - logger.warn((Supplier) () -> new ParameterizedMessage("failed to load/compile script [{}]", scriptNameExt.v1()), e); - } - } - } - - @Override - public void onFileCreated(Path file) { - onFileInit(file); - } - - @Override - public void onFileDeleted(Path file) { - Tuple scriptNameExt = getScriptNameExt(file); - if (scriptNameExt != null) { - ScriptEngine engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); - assert engineService != null; - logger.info("removing script file [{}]", file.toAbsolutePath()); - staticCache.remove(new CacheKey(engineService.getType(), scriptNameExt.v1(), null)); - } - } - - @Override - public void onFileChanged(Path file) { - onFileInit(file); - } - - } - private static final class CacheKey { final String lang; final String idOrCode; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java index 9d9b12558697d..dfc4706726f6a 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java @@ -84,9 +84,6 @@ private static List> languageSettings(Map defaultLangAndTypeFn = settings -> { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptType.java b/core/src/main/java/org/elasticsearch/script/ScriptType.java index e8265b644dae2..cb77e374047d9 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptType.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptType.java @@ -49,14 +49,7 @@ public enum ScriptType implements Writeable { * (Groovy and others), but can be overridden by the specific {@link ScriptEngine} * if the language is naturally secure (Painless, Mustache, and Expressions). */ - STORED ( 1 , new ParseField("stored", "id") , false ), - - /** - * FILE scripts are loaded from disk either on start-up or on-the-fly depending on - * user-defined settings. They will be compiled and cached as soon as they are loaded - * from disk. They are turned on by default as they should always be safe to execute. - */ - FILE ( 2 , new ParseField("file") , true ); + STORED ( 1 , new ParseField("stored", "id") , false ); /** * Reads an int from the input stream and converts it to a {@link ScriptType}. @@ -66,15 +59,12 @@ public enum ScriptType implements Writeable { public static ScriptType readFrom(StreamInput in) throws IOException { int id = in.readVInt(); - if (FILE.id == id) { - return FILE; - } else if (STORED.id == id) { + if (STORED.id == id) { return STORED; } else if (INLINE.id == id) { return INLINE; } else { throw new IllegalStateException("Error reading ScriptType id [" + id + "] from stream, expected one of [" + - FILE.id + " [" + FILE.parseField.getPreferredName() + "], " + STORED.id + " [" + STORED.parseField.getPreferredName() + "], " + INLINE.id + " [" + INLINE.parseField.getPreferredName() + "]]"); } diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index a89fe23edb3df..120cf3dbb3e9d 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -253,9 +253,6 @@ static Settings buildClientSettings(String tribeName, String parentNodeId, Setti if (Environment.PATH_LOGS_SETTING.exists(globalSettings)) { sb.put(Environment.PATH_LOGS_SETTING.getKey(), Environment.PATH_LOGS_SETTING.get(globalSettings)); } - if (Environment.PATH_SCRIPTS_SETTING.exists(globalSettings)) { - sb.put(Environment.PATH_SCRIPTS_SETTING.getKey(), Environment.PATH_SCRIPTS_SETTING.get(globalSettings)); - } for (Setting passthrough : PASS_THROUGH_SETTINGS) { if (passthrough.exists(tribeSettings) == false && passthrough.exists(globalSettings)) { sb.put(passthrough.getKey(), globalSettings.get(passthrough.getKey())); diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java index 6cdc5c6bdac00..e03f3ec45f11e 100644 --- a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java @@ -151,8 +151,6 @@ public void setUp() throws Exception { new ResourceWatcherService(baseSettings, null); ScriptService scriptService = new ScriptService( baseSettings, - environment, - watcherService, scriptEngineRegistry, scriptContextRegistry, scriptSettings); diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java index e3df8c423c886..7dd97f8554762 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -131,8 +131,7 @@ public void setUp() throws Exception { ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList()); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - scriptService = new ScriptService(settings, environment, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry, - scriptContextRegistry, scriptSettings); + scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings); clusterService = ClusterServiceUtils.createClusterService(threadPool); nodeEnvironment = new NodeEnvironment(settings, environment); mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry(); diff --git a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java b/core/src/test/java/org/elasticsearch/script/FileScriptTests.java deleted file mode 100644 index 0ad3bb08ab21a..0000000000000 --- a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java +++ /dev/null @@ -1,96 +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 org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.script.MockScriptEngine.MockCompiledScript; -import org.elasticsearch.test.ESTestCase; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - -// TODO: these really should just be part of ScriptService tests, there is nothing special about them -public class FileScriptTests extends ESTestCase { - - private ScriptSettings scriptSettings; - - ScriptService makeScriptService(Settings settings) throws Exception { - Path homeDir = createTempDir(); - Path scriptsDir = homeDir.resolve("config").resolve("scripts"); - Files.createDirectories(scriptsDir); - Path mockscript = scriptsDir.resolve("script1.mockscript"); - String scriptSource = "1"; - Files.write(mockscript, scriptSource.getBytes("UTF-8")); - settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), homeDir) - // no file watching, so we don't need a ResourceWatcherService - .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) - .put(settings) - .build(); - MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap(scriptSource, script -> "1")); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(scriptEngine)); - ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); - scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); - } - - public void testFileScriptFound() throws Exception { - Settings settings = Settings.builder() - .put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false").build(); - ScriptService scriptService = makeScriptService(settings); - Script script = new Script(ScriptType.FILE, MockScriptEngine.NAME, "script1", Collections.emptyMap()); - CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.SEARCH); - assertNotNull(compiledScript); - MockCompiledScript executable = (MockCompiledScript) compiledScript.compiled(); - assertEquals("script1.mockscript", executable.getName()); - assertSettingDeprecationsAndWarnings(ScriptSettingsTests.buildDeprecatedSettingsArray( - new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, - scriptSettings, "script.engine." + MockScriptEngine.NAME + ".file.aggs"), - "File scripts are deprecated. Use stored or inline scripts instead."); - } - - public void testAllOpsDisabled() throws Exception { - Settings settings = Settings.builder() - .put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false") - .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(); - ScriptService scriptService = makeScriptService(settings); - Script script = new Script(ScriptType.FILE, MockScriptEngine.NAME, "script1", Collections.emptyMap()); - for (ScriptContext context : ScriptContext.Standard.values()) { - try { - scriptService.compile(script, context); - fail(context.getKey() + " script should have been rejected"); - } catch(Exception e) { - assertTrue(e.getMessage(), e.getMessage().contains("scripts of type [file], operation [" + context.getKey() + "] and lang [" + MockScriptEngine.NAME + "] are disabled")); - } - } - assertSettingDeprecationsAndWarnings(ScriptSettingsTests.buildDeprecatedSettingsArray( - new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, scriptSettings, - "script.engine." + MockScriptEngine.NAME + ".file.aggs", - "script.engine." + MockScriptEngine.NAME + ".file.search", - "script.engine." + MockScriptEngine.NAME + ".file.update", - "script.engine." + MockScriptEngine.NAME + ".file.ingest"), - "File scripts are deprecated. Use stored or inline scripts instead."); - } -} diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 0960bc71bea4b..28a96d51a2796 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -46,7 +46,8 @@ public void testNativeScript() throws InterruptedException { .put("node.name", "testNativeScript") .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - ScriptModule scriptModule = new ScriptModule(settings, new Environment(settings), null, + + ScriptModule scriptModule = new ScriptModule(settings, singletonList(new NativeScriptEngine(settings, singletonMap("my", new MyNativeScriptFactory()))), emptyList()); List> scriptSettings = scriptModule.getSettings(); scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); @@ -68,15 +69,13 @@ public void testFineGrainedSettingsDontAffectNativeScripts() throws IOException builder.put("script" + "." + scriptContext.getKey(), randomBoolean()); } Settings settings = builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build(); - Environment environment = new Environment(settings); - ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null); Map nativeScriptFactoryMap = new HashMap<>(); nativeScriptFactoryMap.put("my", new MyNativeScriptFactory()); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(new NativeScriptEngine(settings, nativeScriptFactoryMap))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList<>()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - ScriptService scriptService = new ScriptService(settings, environment, resourceWatcherService, scriptEngineRegistry, + ScriptService scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings); for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) { diff --git a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java index 1d627c0d6a34b..182a6c1af58f7 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java @@ -45,8 +45,6 @@ public class ScriptContextTests extends ESTestCase { ScriptService makeScriptService() throws Exception { Settings settings = Settings.builder() .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(), "false") .put(SCRIPT_PLUGIN_CUSTOM_SETTING, "false") .put(SCRIPT_ENGINE_CUSTOM_SETTING, "false") .build(); @@ -59,7 +57,7 @@ ScriptService makeScriptService() throws Exception { new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op")); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - ScriptService scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); + ScriptService scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings); ClusterState empty = ClusterState.builder(new ClusterName("_name")).build(); ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE); @@ -85,8 +83,7 @@ public void testCustomGlobalScriptContextSettings() throws Exception { } } assertSettingDeprecationsAndWarnings( - ScriptSettingsTests.buildDeprecatedSettingsArray(new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, - scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); + ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); } public void testCustomScriptContextSettings() throws Exception { @@ -104,8 +101,7 @@ public void testCustomScriptContextSettings() throws Exception { assertNotNull(scriptService.compile(script, ScriptContext.Standard.SEARCH)); assertNotNull(scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"))); assertSettingDeprecationsAndWarnings( - ScriptSettingsTests.buildDeprecatedSettingsArray(new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, - scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); + ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); } public void testUnknownPluginScriptContext() throws Exception { @@ -120,8 +116,7 @@ public void testUnknownPluginScriptContext() throws Exception { } } assertSettingDeprecationsAndWarnings( - ScriptSettingsTests.buildDeprecatedSettingsArray(new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, - scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); + ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); } public void testUnknownCustomScriptContext() throws Exception { @@ -142,7 +137,6 @@ public String getKey() { } } assertSettingDeprecationsAndWarnings( - ScriptSettingsTests.buildDeprecatedSettingsArray(new Setting[] {ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING}, - scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); + ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING)); } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index 33d8c89ecd8b2..2dbf4e6d139db 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -88,7 +88,7 @@ public void assertAllSettingsWereChecked() { if (assertScriptModesNonNull) { assertThat(scriptModes, notNullValue()); int numberOfSettings = ScriptType.values().length * scriptContextRegistry.scriptContexts().size(); - numberOfSettings += 3; // for top-level inline/store/file settings + numberOfSettings += 2; // for top-level inline/store settings assertThat(scriptModes.scriptEnabled.size(), equalTo(numberOfSettings)); if (assertAllSettingsWereChecked) { assertThat(checkedSettings.size(), equalTo(numberOfSettings)); @@ -98,7 +98,6 @@ public void assertAllSettingsWereChecked() { public void testDefaultSettings() { this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, Settings.EMPTY); - assertScriptModesAllOps(true, ScriptType.FILE); assertScriptModesAllOps(false, ScriptType.STORED, ScriptType.INLINE); } @@ -136,9 +135,6 @@ public void testScriptTypeGenericSettings() { for (int i = 0; i < randomInt; i++) { assertScriptModesAllOps(randomScriptModes[i], randomScriptTypes[i]); } - if (randomScriptTypesSet.contains(ScriptType.FILE) == false) { - assertScriptModesAllOps(true, ScriptType.FILE); - } if (randomScriptTypesSet.contains(ScriptType.STORED) == false) { assertScriptModesAllOps(false, ScriptType.STORED); } @@ -174,7 +170,6 @@ public void testScriptContextGenericSettings() { } ScriptContext[] complementOf = complementOf(randomScriptContexts); - assertScriptModes(true, new ScriptType[]{ScriptType.FILE}, complementOf); assertScriptModes(false, new ScriptType[]{ScriptType.STORED, ScriptType.INLINE}, complementOf); assertSettingDeprecationsAndWarnings( ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {}))); @@ -190,7 +185,7 @@ public void testConflictingScriptTypeAndOpGenericSettings() { this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, builder.build()); assertScriptModesAllTypes(false, scriptContext); ScriptContext[] complementOf = complementOf(scriptContext); - assertScriptModes(true, new ScriptType[]{ScriptType.FILE, ScriptType.STORED}, complementOf); + assertScriptModes(true, new ScriptType[]{ScriptType.STORED}, complementOf); assertScriptModes(true, new ScriptType[]{ScriptType.INLINE}, complementOf); assertSettingDeprecationsAndWarnings( ScriptSettingsTests.buildDeprecatedSettingsArray( @@ -247,11 +242,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return null; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 55cf11c98697e..9b52ff81ef964 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -18,6 +18,16 @@ */ package org.elasticsearch.script; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; import org.elasticsearch.cluster.ClusterName; @@ -27,36 +37,21 @@ import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.ResourceWatcherService; import org.junit.Before; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.sameInstance; //TODO: this needs to be a base test class, and all scripting engines extend it public class ScriptServiceTests extends ESTestCase { - private ResourceWatcherService resourceWatcherService; private ScriptEngine scriptEngine; private ScriptEngine dangerousScriptEngine; private Map scriptEnginesByLangMap; @@ -65,13 +60,11 @@ public class ScriptServiceTests extends ESTestCase { private ScriptSettings scriptSettings; private ScriptContext[] scriptContexts; private ScriptService scriptService; - private Path scriptsFilePath; private Settings baseSettings; private static final Map DEFAULT_SCRIPT_ENABLED = new HashMap<>(); static { - DEFAULT_SCRIPT_ENABLED.put(ScriptType.FILE, true); DEFAULT_SCRIPT_ENABLED.put(ScriptType.STORED, false); DEFAULT_SCRIPT_ENABLED.put(ScriptType.INLINE, false); } @@ -84,7 +77,6 @@ public void setup() throws IOException { .put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder) .put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 10000) .build(); - resourceWatcherService = new ResourceWatcherService(baseSettings, null); scriptEngine = new TestEngine(); dangerousScriptEngine = new TestDangerousEngine(); TestEngine defaultScriptServiceEngine = new TestEngine(Script.DEFAULT_SCRIPT_LANG) {}; @@ -112,15 +104,12 @@ public void setup() throws IOException { scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]); logger.info("--> setup script service"); - scriptsFilePath = genericConfigFolder.resolve("scripts"); - Files.createDirectories(scriptsFilePath); } private void buildScriptService(Settings additionalSettings) throws IOException { Settings finalSettings = Settings.builder().put(baseSettings).put(additionalSettings).build(); - Environment environment = new Environment(finalSettings); // TODO: - scriptService = new ScriptService(finalSettings, environment, resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, scriptSettings) { + scriptService = new ScriptService(finalSettings, scriptEngineRegistry, scriptContextRegistry, scriptSettings) { @Override StoredScriptSource getScriptFromClusterState(String id, String lang) { //mock the script that gets retrieved from an index @@ -162,51 +151,6 @@ public void testNotSupportedDisableDynamicSetting() throws IOException { } } - public void testScriptsWithoutExtensions() throws IOException { - buildScriptService(Settings.EMPTY); - Path testFileNoExt = scriptsFilePath.resolve("test_no_ext"); - Path testFileWithExt = scriptsFilePath.resolve("test_script.test"); - Streams.copy("test_file_no_ext".getBytes("UTF-8"), Files.newOutputStream(testFileNoExt)); - Streams.copy("test_file".getBytes("UTF-8"), Files.newOutputStream(testFileWithExt)); - resourceWatcherService.notifyNow(); - - CompiledScript compiledScript = scriptService.compile(new Script(ScriptType.FILE, "test", "test_script", Collections.emptyMap()), - ScriptContext.Standard.SEARCH); - assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file")); - - Files.delete(testFileNoExt); - Files.delete(testFileWithExt); - resourceWatcherService.notifyNow(); - - try { - scriptService.compile(new Script(ScriptType.FILE, "test", "test_script", Collections.emptyMap()), ScriptContext.Standard.SEARCH); - fail("the script test_script should no longer exist"); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("unable to find file script [test_script] using lang [test]")); - } - assertWarnings("File scripts are deprecated. Use stored or inline scripts instead."); - } - - public void testScriptCompiledOnceHiddenFileDetected() throws IOException { - buildScriptService(Settings.EMPTY); - - Path testHiddenFile = scriptsFilePath.resolve(".hidden_file"); - Streams.copy("test_hidden_file".getBytes("UTF-8"), Files.newOutputStream(testHiddenFile)); - - Path testFileScript = scriptsFilePath.resolve("file_script.test"); - Streams.copy("test_file_script".getBytes("UTF-8"), Files.newOutputStream(testFileScript)); - resourceWatcherService.notifyNow(); - - CompiledScript compiledScript = scriptService.compile(new Script(ScriptType.FILE, "test", "file_script", Collections.emptyMap()), - ScriptContext.Standard.SEARCH); - assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file_script")); - - Files.delete(testHiddenFile); - Files.delete(testFileScript); - resourceWatcherService.notifyNow(); - assertWarnings("File scripts are deprecated. Use stored or inline scripts instead."); - } - public void testInlineScriptCompiledOnceCache() throws IOException { buildScriptService(Settings.EMPTY); CompiledScript compiledScript1 = scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), @@ -281,26 +225,11 @@ public void testAllowNoScriptContextSettings() throws IOException { public void testDefaultBehaviourFineGrainedSettings() throws IOException { Settings.Builder builder = Settings.builder(); - //rarely inject the default settings, which have no effect - boolean deprecate = false; - if (rarely()) { - builder.put("script.file", "true"); - deprecate = true; - } buildScriptService(builder.build()); - createFileScripts("dtest"); for (ScriptContext scriptContext : scriptContexts) { - // only file scripts are accepted by default assertCompileRejected("dtest", "script", ScriptType.INLINE, scriptContext); assertCompileRejected("dtest", "script", ScriptType.STORED, scriptContext); - assertCompileAccepted("dtest", "file_script", ScriptType.FILE, scriptContext); - } - if (deprecate) { - assertSettingDeprecationsAndWarnings(ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.file"), - "File scripts are deprecated. Use stored or inline scripts instead."); - } else { - assertWarnings("File scripts are deprecated. Use stored or inline scripts instead."); } } @@ -369,12 +298,9 @@ public void testFineGrainedSettings() throws IOException { } buildScriptService(builder.build()); - createFileScripts("expression", "mustache", "dtest"); for (ScriptType scriptType : ScriptType.values()) { - //make sure file scripts have a different name than inline ones. - //Otherwise they are always considered file ones as they can be found in the static cache. - String script = scriptType == ScriptType.FILE ? "file_script" : "script"; + String script = "script"; for (ScriptContext scriptContext : this.scriptContexts) { //fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings Boolean scriptEnabled = engineSettings.get(dangerousScriptEngine.getType() + "." + scriptType + "." + scriptContext.getKey()); @@ -397,8 +323,7 @@ public void testFineGrainedSettings() throws IOException { } } assertSettingDeprecationsAndWarnings( - ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {})), - "File scripts are deprecated. Use stored or inline scripts instead."); + ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {}))); } public void testCompileNonRegisteredContext() throws IOException { @@ -463,14 +388,6 @@ public void testCompilationStatsOnCacheHit() throws IOException { ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.inline")); } - public void testFileScriptCountedInCompilationStats() throws IOException { - buildScriptService(Settings.EMPTY); - createFileScripts("test"); - scriptService.compile(new Script(ScriptType.FILE, "test", "file_script", Collections.emptyMap()), randomFrom(scriptContexts)); - assertEquals(1L, scriptService.stats().getCompilations()); - assertWarnings("File scripts are deprecated. Use stored or inline scripts instead."); - } - public void testIndexedScriptCountedInCompilationStats() throws IOException { buildScriptService(Settings.EMPTY); scriptService.compile(new Script(ScriptType.STORED, "test", "script", Collections.emptyMap()), randomFrom(scriptContexts)); @@ -542,14 +459,6 @@ public void testGetStoredScript() throws Exception { assertNull(scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang"))); } - private void createFileScripts(String... langs) throws IOException { - for (String lang : langs) { - Path scriptPath = scriptsFilePath.resolve("file_script." + lang); - Streams.copy("10".getBytes("UTF-8"), Files.newOutputStream(scriptPath)); - } - resourceWatcherService.notifyNow(); - } - private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) { try { scriptService.compile(new Script(scriptType, lang, script, Collections.emptyMap()), scriptContext); @@ -585,11 +494,6 @@ public String getType() { return name; } - @Override - public String getExtension() { - return name; - } - @Override public Object compile(String scriptName, String scriptText, Map params) { return "compiled_" + scriptText; @@ -625,11 +529,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return "compiled_" + scriptSource; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java index 1315ce4970bdd..b435fff52debe 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java @@ -33,12 +33,9 @@ public class ScriptSettingsTests extends ESTestCase { - public static Setting[] buildDeprecatedSettingsArray(ScriptSettings scriptSettings, String... keys) { - return buildDeprecatedSettingsArray(null, scriptSettings, keys); - } - public static Setting[] buildDeprecatedSettingsArray(Setting[] deprecated, ScriptSettings scriptSettings, String... keys) { - Setting[] settings = new Setting[keys.length + (deprecated == null ? 0 : deprecated.length)]; + public static Setting[] buildDeprecatedSettingsArray(ScriptSettings scriptSettings, String... keys) { + Setting[] settings = new Setting[keys.length]; int count = 0; for (Setting setting : scriptSettings.getSettings()) { @@ -49,10 +46,6 @@ public static Setting[] buildDeprecatedSettingsArray(Setting[] deprecated, } } - if (deprecated != null) { - System.arraycopy(deprecated, 0, settings, keys.length, deprecated.length); - } - return settings; } @@ -82,11 +75,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return null; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index c51c0aec4bb61..9534bafa86248 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -418,11 +418,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; @@ -523,11 +518,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java index 63921114a918b..a2ebb378fc370 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java @@ -815,44 +815,6 @@ public void testInitMapCombineReduceWithParamsStored() { assertThat(((Number) object).longValue(), equalTo(numDocs * 3)); } - public void testInitMapCombineReduceWithParamsFile() { - Map varsMap = new HashMap<>(); - varsMap.put("multiplier", 1); - Map params = new HashMap<>(); - params.put("_agg", new ArrayList<>()); - params.put("vars", varsMap); - - SearchResponse response = client() - .prepareSearch("idx") - .setQuery(matchAllQuery()) - .addAggregation( - scriptedMetric("scripted") - .params(params) - .initScript(new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "init_script", Collections.emptyMap())) - .mapScript(new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "map_script", Collections.emptyMap())) - .combineScript( - new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "combine_script", Collections.emptyMap())) - .reduceScript( - new Script(ScriptType.FILE, CustomScriptPlugin.NAME, "reduce_script", Collections.emptyMap()))) - .get(); - assertSearchResponse(response); - assertThat(response.getHits().getTotalHits(), equalTo(numDocs)); - - Aggregation aggregation = response.getAggregations().get("scripted"); - assertThat(aggregation, notNullValue()); - assertThat(aggregation, instanceOf(ScriptedMetric.class)); - ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation; - assertThat(scriptedMetricAggregation.getName(), equalTo("scripted")); - assertThat(scriptedMetricAggregation.aggregation(), notNullValue()); - assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class)); - List aggregationList = (List) scriptedMetricAggregation.aggregation(); - assertThat(aggregationList.size(), equalTo(1)); - Object object = aggregationList.get(0); - assertThat(object, notNullValue()); - assertThat(object, instanceOf(Number.class)); - assertThat(((Number) object).longValue(), equalTo(numDocs * 3)); - } - public void testInitMapCombineReduceWithParamsAsSubAgg() { Map varsMap = new HashMap<>(); varsMap.put("multiplier", 1); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java index 86f59659ebc18..95540e5bd174c 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java @@ -418,11 +418,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; @@ -530,11 +525,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index 2cfb34431059c..362e77ebc86cc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -272,11 +272,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java index 75975d5a39ff8..a6b09dd143860 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java @@ -67,9 +67,6 @@ protected InternalScriptedMetric createTestInstance(String name, List params) { return scriptSource; diff --git a/core/src/test/java/org/elasticsearch/tribe/TribeServiceTests.java b/core/src/test/java/org/elasticsearch/tribe/TribeServiceTests.java index 409888f27109f..d40c4865c9055 100644 --- a/core/src/test/java/org/elasticsearch/tribe/TribeServiceTests.java +++ b/core/src/test/java/org/elasticsearch/tribe/TribeServiceTests.java @@ -65,12 +65,10 @@ public void testEnvironmentSettings() { .put("node.name", "nodename") .put("path.home", "some/path") .put("path.conf", "conf/path") - .put("path.scripts", "scripts/path") .put("path.logs", "logs/path").build(); Settings clientSettings = TribeService.buildClientSettings("tribe1", "parent_id", globalSettings, Settings.EMPTY); assertEquals("some/path", clientSettings.get("path.home")); assertEquals("conf/path", clientSettings.get("path.conf")); - assertEquals("scripts/path", clientSettings.get("path.scripts")); assertEquals("logs/path", clientSettings.get("path.logs")); Settings tribeSettings = Settings.builder() @@ -79,7 +77,6 @@ public void testEnvironmentSettings() { TribeService.buildClientSettings("tribe1", "parent_id", globalSettings, tribeSettings); }); assertTrue(e.getMessage(), e.getMessage().contains("Setting [path.home] not allowed in tribe client")); - assertSettingDeprecationsAndWarnings(new Setting[] {Environment.PATH_SCRIPTS_SETTING}); } public void testPassthroughSettings() { diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index d274399387ab5..defbc411c9ef7 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -91,11 +91,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return new Object(); // unused @@ -164,11 +159,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return scriptSource; @@ -230,11 +220,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return new Object(); // unused @@ -297,11 +282,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { return new Object(); // unused diff --git a/distribution/build.gradle b/distribution/build.gradle index b078008250e74..f78ec0bce618d 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -304,7 +304,6 @@ configure(distributions.findAll { ['deb', 'rpm'].contains(it.name) }) { /* Explicitly declare the outputs so that gradle won't skip this task if one of the other tasks like createEtc run first and create the packaging directory as a side effect. */ - outputs.dir("${packagingFiles}/scripts") outputs.dir("${packagingFiles}/env") outputs.dir("${packagingFiles}/systemd") } @@ -314,14 +313,8 @@ configure(distributions.findAll { ['deb', 'rpm'].contains(it.name) }) { dirMode 0750 } - task createEtcScripts(type: EmptyDirTask) { - dependsOn createEtc - dir "${packagingFiles}/etc/elasticsearch/scripts" - dirMode 0750 - } - task fillEtc(type: Copy) { - dependsOn createEtc, createEtcScripts + dependsOn createEtc with configFiles into "${packagingFiles}/etc/elasticsearch" /* Explicitly declare the output files so this task doesn't consider itself diff --git a/docs/build.gradle b/docs/build.gradle index fd5c53769210e..7ef951deaa432 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -66,12 +66,6 @@ integTestCluster { Closure configFile = { extraConfigFile it, "src/test/cluster/config/$it" } - configFile 'scripts/calculate_score.painless' - configFile 'scripts/my_script.painless' - configFile 'scripts/my_init_script.painless' - configFile 'scripts/my_map_script.painless' - configFile 'scripts/my_combine_script.painless' - configFile 'scripts/my_reduce_script.painless' configFile 'analysis/example_word_list.txt' configFile 'analysis/hyphenation_patterns.xml' configFile 'analysis/synonym.txt' @@ -371,3 +365,38 @@ buildRestTests.setups['exams'] = ''' {"grade": 100} {"index":{}} {"grade": 50}''' + +buildRestTests.setups['stored_example_script'] = ''' + # Simple script to load a field. Not really a good example, but a simple one. + - do: + put_script: + id: "my_script" + body: { "script": { "lang": "painless", "code": "doc[params.field].value" } } + - match: { acknowledged: true } +''' + +buildRestTests.setups['stored_scripted_metric_script'] = ''' + - do: + put_script: + id: "my_init_script" + body: { "script": { "lang": "painless", "code": "params._agg.transactions = []" } } + - match: { acknowledged: true } + + - do: + put_script: + id: "my_map_script" + body: { "script": { "lang": "painless", "code": "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } } + - match: { acknowledged: true } + + - do: + put_script: + id: "my_combine_script" + body: { "script": { "lang": "painless", "code": "double profit = 0;for (t in params._agg.transactions) { profit += t; } return profit" } } + - match: { acknowledged: true } + + - do: + put_script: + id: "my_reduce_script" + body: { "script": { "lang": "painless", "code": "double profit = 0;for (a in params._aggs) { profit += a; } return profit" } } + - match: { acknowledged: true } +''' diff --git a/docs/reference/aggregations/bucket/range-aggregation.asciidoc b/docs/reference/aggregations/bucket/range-aggregation.asciidoc index efcbd9715e1ac..63d4c04eea486 100644 --- a/docs/reference/aggregations/bucket/range-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/range-aggregation.asciidoc @@ -149,7 +149,7 @@ It is also possible to customize the key for each range: } -------------------------------------------------- -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -158,7 +158,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "price_ranges" : { "range" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "price" } @@ -174,8 +174,6 @@ This will interpret the `script` parameter as an `inline` script with the `painl } -------------------------------------------------- -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - ==== Value Script Lets say the product prices are in USD but we would like to get the price ranges in EURO. We can use value script to convert the prices prior the aggregation (assuming conversion rate of 0.8) diff --git a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc index 90a5586d9e4fd..7346af50daba4 100644 --- a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc @@ -469,7 +469,7 @@ Generating the terms using a script: } -------------------------------------------------- -This will interpret the `script` parameter as an `inline` script with the default script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the default script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -478,7 +478,7 @@ This will interpret the `script` parameter as an `inline` script with the defaul "genres" : { "terms" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "genre" } @@ -489,9 +489,6 @@ This will interpret the `script` parameter as an `inline` script with the defaul } -------------------------------------------------- -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - - ==== Value Script [source,js] diff --git a/docs/reference/aggregations/metrics/avg-aggregation.asciidoc b/docs/reference/aggregations/metrics/avg-aggregation.asciidoc index 6dfae1c578264..5e3b93c315226 100644 --- a/docs/reference/aggregations/metrics/avg-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/avg-aggregation.asciidoc @@ -57,7 +57,7 @@ POST /exams/_search?size=0 // CONSOLE // TEST[setup:exams] -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -67,7 +67,7 @@ POST /exams/_search?size=0 "avg_grade" : { "avg" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "grade" } @@ -78,9 +78,7 @@ POST /exams/_search?size=0 } -------------------------------------------------- // CONSOLE -// TEST[setup:exams] - -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:exams,stored_example_script] ===== Value Script diff --git a/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc b/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc index 9e24604769d16..3b613425dce91 100644 --- a/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc @@ -197,7 +197,7 @@ POST /sales/_search?size=0 // CONSOLE // TEST[setup:sales] -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -207,7 +207,7 @@ POST /sales/_search?size=0 "type_promoted_count" : { "cardinality" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "type_field": "type", "promoted_field": "promoted" @@ -221,8 +221,6 @@ POST /sales/_search?size=0 // CONSOLE // TEST[skip:no script] -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - ==== Missing value The `missing` parameter defines how documents that are missing a value should be treated. diff --git a/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc b/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc index 0e324089dc799..5a2b043ee058d 100644 --- a/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc @@ -109,7 +109,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "grades_stats" : { "extended_stats" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "grade" } @@ -120,8 +120,6 @@ This will interpret the `script` parameter as an `inline` script with the `painl } -------------------------------------------------- -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - ===== Value Script It turned out that the exam was way above the level of the students and a grade correction needs to be applied. We can use value script to get the new stats: diff --git a/docs/reference/aggregations/metrics/max-aggregation.asciidoc b/docs/reference/aggregations/metrics/max-aggregation.asciidoc index 34945bfc969a8..a9c91284056e7 100644 --- a/docs/reference/aggregations/metrics/max-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/max-aggregation.asciidoc @@ -67,7 +67,7 @@ POST /sales/_search // TEST[setup:sales] This will use the <> scripting language -and no script parameters. To use a file script use the following syntax: +and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -77,7 +77,7 @@ POST /sales/_search "max_price" : { "max" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "price" } @@ -88,9 +88,7 @@ POST /sales/_search } -------------------------------------------------- // CONSOLE -// TEST[setup:sales] - -TIP: For indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:sales,stored_example_script] ==== Value Script diff --git a/docs/reference/aggregations/metrics/min-aggregation.asciidoc b/docs/reference/aggregations/metrics/min-aggregation.asciidoc index 813a2aff9db2b..ac9f493e49314 100644 --- a/docs/reference/aggregations/metrics/min-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/min-aggregation.asciidoc @@ -68,7 +68,7 @@ POST /sales/_search // TEST[setup:sales] This will use the <> scripting language -and no script parameters. To use a file script use the following syntax: +and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -78,7 +78,7 @@ POST /sales/_search "min_price" : { "min" : { "script" : { - "file": "my_script", + "stored": "my_script", "params": { "field": "price" } @@ -89,9 +89,7 @@ POST /sales/_search } -------------------------------------------------- // CONSOLE -// TEST[setup:sales] - -TIP: For indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:sales,stored_example_script] ==== Value Script diff --git a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc index a9f49aecccf4d..ce275a6f3beaf 100644 --- a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc @@ -187,7 +187,7 @@ a script to convert them on-the-fly: script to generate values which percentiles are calculated on <2> Scripting supports parameterized input just like any other script -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -196,7 +196,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "load_time_outlier" : { "percentiles" : { "script" : { - "file": "my_script", + "stored": "my_script", "params" : { "timeUnit" : 1000 } @@ -207,8 +207,6 @@ This will interpret the `script` parameter as an `inline` script with the `painl } -------------------------------------------------- -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - [[search-aggregations-metrics-percentile-aggregation-approximation]] ==== Percentiles are (usually) approximate diff --git a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc index 75e8ca35868ee..a00d0fad799c2 100644 --- a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc @@ -136,7 +136,7 @@ a script to convert them on-the-fly: script to generate values which percentile ranks are calculated on <2> Scripting supports parameterized input just like any other script -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -146,7 +146,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "percentile_ranks" : { "values" : [3, 5], "script" : { - "file": "my_script", + "stored": "my_script", "params" : { "timeUnit" : 1000 } @@ -157,8 +157,6 @@ This will interpret the `script` parameter as an `inline` script with the `painl } -------------------------------------------------- -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. - ==== HDR Histogram experimental[] diff --git a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc index 2a375500b1a30..094bccfbbe639 100644 --- a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc @@ -50,7 +50,7 @@ The response for the above aggregation: // TESTRESPONSE[s/"took": 218/"took": $body.took/] // TESTRESPONSE[s/\.\.\./"_shards": $body._shards, "hits": $body.hits, "timed_out": false,/] -The above example can also be specified using file scripts as follows: +The above example can also be specified using stored scripts as follows: [source,js] -------------------------------------------------- @@ -60,20 +60,20 @@ POST ledger/_search?size=0 "profit": { "scripted_metric": { "init_script" : { - "file": "my_init_script" + "stored": "my_init_script" }, "map_script" : { - "file": "my_map_script" + "stored": "my_map_script" }, "combine_script" : { - "file": "my_combine_script" + "stored": "my_combine_script" }, "params": { "field": "amount", <1> "_agg": {} <2> }, "reduce_script" : { - "file": "my_reduce_script" + "stored": "my_reduce_script" } } } @@ -81,7 +81,7 @@ POST ledger/_search?size=0 } -------------------------------------------------- // CONSOLE -// TEST[setup:ledger] +// TEST[setup:ledger,stored_scripted_metric_script] <1> script parameters for `init`, `map` and `combine` scripts must be specified in a global `params` object so that it can be share between the scripts. diff --git a/docs/reference/aggregations/metrics/stats-aggregation.asciidoc b/docs/reference/aggregations/metrics/stats-aggregation.asciidoc index 8077a81f62b58..1892ce45cc181 100644 --- a/docs/reference/aggregations/metrics/stats-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/stats-aggregation.asciidoc @@ -65,7 +65,7 @@ POST /exams/_search?size=0 // CONSOLE // TEST[setup:exams] -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -75,7 +75,7 @@ POST /exams/_search?size=0 "grades_stats" : { "stats" : { "script" : { - "file": "my_script", + "stored": "my_script", "params" : { "field" : "grade" } @@ -86,9 +86,7 @@ POST /exams/_search?size=0 } -------------------------------------------------- // CONSOLE -// TEST[setup:exams] - -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:exams,stored_example_script] ===== Value Script diff --git a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc index cae684249c14f..975ef163cbcc5 100644 --- a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc @@ -71,7 +71,7 @@ POST /sales/_search?size=0 // CONSOLE // TEST[setup:sales] -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -88,7 +88,7 @@ POST /sales/_search?size=0 "hat_prices" : { "sum" : { "script" : { - "file": "my_script", + "stored": "my_script", "params" : { "field" : "price" } @@ -99,9 +99,7 @@ POST /sales/_search?size=0 } -------------------------------------------------- // CONSOLE -// TEST[setup:sales] - -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:sales,stored_example_script] ===== Value Script diff --git a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc index 35eeeef14bcf7..1be6c78047180 100644 --- a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc @@ -58,7 +58,7 @@ POST /sales/_search?size=0 // CONSOLE // TEST[setup:sales] -This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax: +This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a stored script use the following syntax: [source,js] -------------------------------------------------- @@ -68,7 +68,7 @@ POST /sales/_search?size=0 "types_count" : { "value_count" : { "script" : { - "file": "my_script", + "stored": "my_script", "params" : { "field" : "type" } @@ -79,6 +79,4 @@ POST /sales/_search?size=0 } -------------------------------------------------- // CONSOLE -// TEST[setup:sales] - -TIP: for indexed scripts replace the `file` parameter with an `id` parameter. +// TEST[setup:sales,stored_example_script] diff --git a/docs/reference/ingest/ingest-node.asciidoc b/docs/reference/ingest/ingest-node.asciidoc index 723d7205cfc63..e8150cd4dd90b 100644 --- a/docs/reference/ingest/ingest-node.asciidoc +++ b/docs/reference/ingest/ingest-node.asciidoc @@ -1698,7 +1698,7 @@ Renames an existing field. If the field doesn't exist or the new name is already [[script-processor]] === Script Processor -Allows inline, stored, and file scripts to be executed within ingest pipelines. +Allows inline and stored scripts to be executed within ingest pipelines. See <> to learn more about writing scripts. The Script Processor leverages caching of compiled scripts for improved performance. Since the @@ -1712,13 +1712,12 @@ caching see <>. |====== | Name | Required | Default | Description | `lang` | no | "painless" | The scripting language -| `file` | no | - | The script file to refer to | `id` | no | - | The stored script id to refer to | `inline` | no | - | An inline script to be executed | `params` | no | - | Script Parameters |====== -One of `file`, `id`, `inline` options must be provided in order to properly reference a script to execute. +One of `id` or `inline` options must be provided in order to properly reference a script to execute. You can access the current ingest document from within the script context by using the `ctx` variable. diff --git a/docs/reference/modules/scripting/security.asciidoc b/docs/reference/modules/scripting/security.asciidoc index 3e09943b46f6d..efb4b13a03972 100644 --- a/docs/reference/modules/scripting/security.asciidoc +++ b/docs/reference/modules/scripting/security.asciidoc @@ -144,12 +144,9 @@ or disabled based on where they are stored. For example: ----------------------------------- script.inline: false <1> script.stored: false <2> -script.file: true <3> ----------------------------------- <1> Refuse to run scripts provided inline in the API. <2> Refuse to run scripts stored using the API. -<3> Run scripts found on the filesystem in `/etc/elasticsearch/scripts` -(rpm or deb) or `config/scripts` (zip or tar). NOTE: These settings override the defaults mentioned <>. Recreating the defaults @@ -194,14 +191,14 @@ settings. They have two forms: [source,yaml] ------------------------ -script.engine.{lang}.{inline|file|stored}.{context}: true|false +script.engine.{lang}.{inline|stored}.{context}: true|false ------------------------ And [source,yaml] ------------------------ -script.engine.{lang}.{inline|file|stored}: true|false +script.engine.{lang}.{inline|stored}: true|false ------------------------ For example: @@ -210,7 +207,6 @@ For example: ----------------------------------- script.inline: false <1> script.stored: false <1> -script.file: false <1> script.engine.painless.inline: true <2> script.engine.painless.stored.search: true <3> diff --git a/docs/reference/modules/scripting/using.asciidoc b/docs/reference/modules/scripting/using.asciidoc index 0a64758f5aa2a..ec9f74c0af642 100644 --- a/docs/reference/modules/scripting/using.asciidoc +++ b/docs/reference/modules/scripting/using.asciidoc @@ -8,13 +8,13 @@ the same pattern: ------------------------------------- "script": { "lang": "...", <1> - "inline" | "stored" | "file": "...", <2> + "inline" | "stored": "...", <2> "params": { ... } <3> } ------------------------------------- // NOTCONSOLE <1> The language the script is written in, which defaults to `painless`. -<2> The script itself which may be specified as `inline`, `stored`, or `file`. +<2> The script itself which may be specified as `inline` or `stored`. <3> Any named parameters that should be passed into the script. For example, the following script is used in a search request to return a @@ -55,18 +55,12 @@ GET my_index/_search setting `script.default_lang` to the appropriate language. -`inline`, `stored`, `file`:: +`inline`, `stored`:: Specifies the source of the script. An `inline` script is specified - `inline` as in the example above, a `stored` script is specified `stored` - and is retrieved from the cluster state (see <>), - and a `file` script is retrieved from a file in the `config/scripts` - directory (see <>). -+ -While languages like `expression` and `painless` can be used out of the box as -inline or stored scripts, other languages can only be -specified as `file` unless you first adjust the default -<>. + `inline` as in the example above. A `stored` script is specified `stored` + and is retrieved from the cluster state (see <>). + `params`:: @@ -114,72 +108,6 @@ minute will be compiled. You can change this setting dynamically by setting ======================================== - -[float] -[[modules-scripting-file-scripts]] -=== File-based Scripts - -To increase security, non-sandboxed languages can only be specified in script -files stored on every node in the cluster. File scripts must be saved in the -`scripts` directory whose default location depends on whether you use the -<> (`$ES_HOME/config/scripts/`), -<>, or <> package. The default may be -changed with the `path.scripts` setting. - -The languages which are assumed to be safe by default are: `painless`, -`expression`, and `mustache` (used for search and query templates). - -Any files placed in the `scripts` directory will be compiled automatically -when the node starts up and then <>. - -The file should be named as follows: `{script-name}.{lang}`. For instance, -the following example creates a Groovy script called `calculate-score`: - -[source,sh] --------------------------------------------------- -cat "Math.log(_score * 2) + params.my_modifier" > config/scripts/calculate_score.painless --------------------------------------------------- - -This script can be used as follows: - -[source,js] --------------------------------------------------- -GET my_index/_search -{ - "query": { - "script": { - "script": { - "lang": "painless", <1> - "file": "calculate_score", <2> - "params": { - "my_modifier": 2 - } - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[continued] -<1> The language of the script, which should correspond with the script file suffix. -<2> The name of the script, which should be the name of the file. - -The `script` directory may contain sub-directories, in which case the -hierarchy of directories is flattened and concatenated with underscores. A -script in `group1/group2/my_script.painless` should use `group1_group2_myscript` -as the `file` name. - -[[reload-scripts]] -[float] -==== Automatic script reloading - -The `scripts` directory will be rescanned every `60s` (configurable with the -`resource.reload.interval` setting) and new, changed, or removed scripts will -be compiled, updated, or deleted from the script cache. - -Script reloading can be completely disabled by setting -`script.auto_reload_enabled` to `false`. - [float] [[modules-scripting-stored-scripts]] === Stored Scripts diff --git a/docs/reference/modules/tribe.asciidoc b/docs/reference/modules/tribe.asciidoc index ded8bc43a076e..f014932db7a06 100644 --- a/docs/reference/modules/tribe.asciidoc +++ b/docs/reference/modules/tribe.asciidoc @@ -90,7 +90,6 @@ configuration options are passed down from the tribe node to each node client: * `path.home` * `path.conf` * `path.logs` -* `path.scripts` * `shield.*` Almost any setting (except for `path.*`) may be configured at the node client @@ -109,16 +108,14 @@ include: [source,yaml] ------------------------ -path.scripts: some/path/to/config <1> -network.host: 192.168.1.5 <2> +network.host: 192.168.1.5 <1> tribe: t1: cluster.name: cluster_one t2: cluster.name: cluster_two - network.host: 10.1.2.3 <3> + network.host: 10.1.2.3 <2> ------------------------ -<1> The `path.scripts` setting is inherited by both `t1` and `t2`. -<2> The `network.host` setting is inherited by `t1`. -<3> The `t3` node client overrides the inherited from the tribe node. +<1> The `network.host` setting is inherited by `t1`. +<2> The `t3` node client overrides the inherited from the tribe node. diff --git a/docs/reference/search/search-template.asciidoc b/docs/reference/search/search-template.asciidoc index d8f0fbb9719d7..81a590fa04383 100644 --- a/docs/reference/search/search-template.asciidoc +++ b/docs/reference/search/search-template.asciidoc @@ -402,27 +402,8 @@ The previous query will be rendered as: [[pre-registered-templates]] ===== Pre-registered template -You can register search templates by storing it in the `config/scripts` directory, in a file using the `.mustache` extension. -In order to execute the stored template, reference it by it's name under the `template` key: - - -[source,js] ------------------------------------------- -GET _search/template -{ - "file": "storedTemplate", <1> - "params": { - "query_string": "search for these words" - } -} ------------------------------------------- -// CONSOLE -// TEST[catch:request] - -<1> Name of the query template in `config/scripts/`, i.e., `storedTemplate.mustache`. - -You can also register search templates by storing it in the cluster state. -There are REST APIs to manage these indexed templates. +You can register search templates by storing them in the cluster state. +There are REST APIs to manage these stored templates. [source,js] ------------------------------------------ @@ -501,7 +482,7 @@ because we'll use it later. ////////////////////////// -To use an indexed template at search time use: +To use a stored template at search time use: [source,js] ------------------------------------------ @@ -515,7 +496,7 @@ GET _search/template ------------------------------------------ // CONSOLE // TEST[catch:missing] -<1> Name of the query template stored in the `.scripts` index. +<1> Name of the stored template script. [float] ==== Validating templates @@ -556,22 +537,6 @@ This call will return the rendered template: // TESTRESPONSE <1> `status` array has been populated with values from the `params` object. -File and indexed templates can also be rendered by replacing `inline` with -`file` or `id` respectively. For example, to render a file template - -[source,js] ------------------------------------------- -GET _render/template -{ - "file": "my_template", - "params": { - "status": [ "pending", "published" ] - } -} ------------------------------------------- -// CONSOLE -// TEST[catch:request] - Pre-registered templates can also be rendered using [source,js] @@ -594,7 +559,7 @@ You can use `explain` parameter when running a template: ------------------------------------------ GET _search/template { - "file": "my_template", + "id": "my_template", "params": { "status": [ "pending", "published" ] }, @@ -602,7 +567,7 @@ GET _search/template } ------------------------------------------ // CONSOLE -// TEST[catch:request] +// TEST[catch:missing] [float] ===== Profiling @@ -613,7 +578,7 @@ You can use `profile` parameter when running a template: ------------------------------------------ GET _search/template { - "file": "my_template", + "id": "my_template", "params": { "status": [ "pending", "published" ] }, @@ -621,7 +586,7 @@ GET _search/template } ------------------------------------------ // CONSOLE -// TEST[catch:request] +// TEST[catch:missing] [[multi-search-template]] == Multi Search Template @@ -656,8 +621,6 @@ $ cat requests {"inline": {"query": {"{{query_type}}": {"name": "{{name}}" }}}, "params": {"query_type": "match_phrase_prefix", "name": "Smith"}} {"index": "_all"} {"id": "template_1", "params": {"query_string": "search for these words" }} <2> -{"types": "users"} -{"file": "template_2", "params": {"field_name": "fullname", "field_value": "john smith" }} <3> $ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo -------------------------------------------------- @@ -667,8 +630,6 @@ $ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/tem <2> Search template request based on a stored template -<3> Search template request based on a file template - The response returns a `responses` array, which includes the search template response for each search template request matching its order in the original multi search template request. If there was a complete failure for that specific diff --git a/docs/reference/setup/install/deb.asciidoc b/docs/reference/setup/install/deb.asciidoc index 179aa244072b2..14f626f0d1874 100644 --- a/docs/reference/setup/install/deb.asciidoc +++ b/docs/reference/setup/install/deb.asciidoc @@ -225,11 +225,6 @@ locations for a Debian-based system: d| Not configured | path.repo -| script - | Location of script files. - | /etc/elasticsearch/scripts - | path.scripts - |======================================================================= include::next-steps.asciidoc[] diff --git a/docs/reference/setup/install/rpm.asciidoc b/docs/reference/setup/install/rpm.asciidoc index 27806c2f98692..ec1b46306037d 100644 --- a/docs/reference/setup/install/rpm.asciidoc +++ b/docs/reference/setup/install/rpm.asciidoc @@ -213,11 +213,6 @@ locations for an RPM-based system: d| Not configured | path.repo -| script - | Location of script files. - | /etc/elasticsearch/scripts - | path.scripts - |======================================================================= include::next-steps.asciidoc[] diff --git a/docs/reference/setup/install/windows.asciidoc b/docs/reference/setup/install/windows.asciidoc index 40a413087bee8..d681ea2e69da7 100644 --- a/docs/reference/setup/install/windows.asciidoc +++ b/docs/reference/setup/install/windows.asciidoc @@ -255,11 +255,6 @@ directory so that you do not delete important data later on. d| Not configured | path.repo -| script - | Location of script files. - | %ES_HOME%\scripts - | path.scripts - |======================================================================= include::next-steps.asciidoc[] diff --git a/docs/reference/setup/install/zip-targz.asciidoc b/docs/reference/setup/install/zip-targz.asciidoc index c264aab61d7be..ffed25e64763b 100644 --- a/docs/reference/setup/install/zip-targz.asciidoc +++ b/docs/reference/setup/install/zip-targz.asciidoc @@ -187,11 +187,6 @@ directory so that you do not delete important data later on. d| Not configured | path.repo -| script - | Location of script files. - | $ES_HOME/scripts - | path.scripts - |======================================================================= diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index a5bc8034027ee..99c8695956ea4 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -37,7 +37,6 @@ import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalMap; import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalStringProperty; -import static org.elasticsearch.script.ScriptType.FILE; import static org.elasticsearch.script.ScriptType.INLINE; import static org.elasticsearch.script.ScriptType.STORED; @@ -100,19 +99,17 @@ public ScriptProcessor create(Map registry, String pr Map config) throws Exception { String lang = readOptionalStringProperty(TYPE, processorTag, config, "lang"); String inline = readOptionalStringProperty(TYPE, processorTag, config, "inline"); - String file = readOptionalStringProperty(TYPE, processorTag, config, "file"); String id = readOptionalStringProperty(TYPE, processorTag, config, "id"); Map params = readOptionalMap(TYPE, processorTag, config, "params"); - boolean containsNoScript = !hasLength(file) && !hasLength(id) && !hasLength(inline); + boolean containsNoScript = !hasLength(id) && !hasLength(inline); if (containsNoScript) { - throw newConfigurationException(TYPE, processorTag, null, "Need [file], [id], or [inline] parameter to refer to scripts"); + throw newConfigurationException(TYPE, processorTag, null, "Need [id] or [inline] parameter to refer to scripts"); } - boolean moreThanOneConfigured = (Strings.hasLength(file) && Strings.hasLength(id)) || - (Strings.hasLength(file) && Strings.hasLength(inline)) || (Strings.hasLength(id) && Strings.hasLength(inline)); + boolean moreThanOneConfigured = Strings.hasLength(id) && Strings.hasLength(inline); if (moreThanOneConfigured) { - throw newConfigurationException(TYPE, processorTag, null, "Only one of [file], [id], or [inline] may be configured"); + throw newConfigurationException(TYPE, processorTag, null, "Only one of [id] or [inline] may be configured"); } if (lang == null) { @@ -125,10 +122,7 @@ public ScriptProcessor create(Map registry, String pr final Script script; String scriptPropertyUsed; - if (Strings.hasLength(file)) { - script = new Script(FILE, lang, file, (Map)params); - scriptPropertyUsed = "file"; - } else if (Strings.hasLength(inline)) { + if (Strings.hasLength(inline)) { script = new Script(INLINE, lang, inline, (Map)params); scriptPropertyUsed = "inline"; } else if (Strings.hasLength(id)) { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java index b3ee7a23a5d6c..1610b9bf01cd1 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java @@ -44,7 +44,6 @@ public class ScriptProcessorFactoryTests extends ESTestCase { Map map = new HashMap<>(); map.put("id", "stored"); map.put("inline", "inline"); - map.put("file", "file"); ingestScriptParamToType = Collections.unmodifiableMap(map); } @@ -55,7 +54,7 @@ public void init() { public void testFactoryValidationWithDefaultLang() throws Exception { Map configMap = new HashMap<>(); - String randomType = randomFrom("id", "inline", "file"); + String randomType = randomFrom("id", "inline"); configMap.put(randomType, "foo"); ScriptProcessor processor = factory.create(null, randomAlphaOfLength(10), configMap); assertThat(processor.getScript().getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG)); @@ -65,7 +64,7 @@ public void testFactoryValidationWithDefaultLang() throws Exception { public void testFactoryValidationWithParams() throws Exception { Map configMap = new HashMap<>(); - String randomType = randomFrom("id", "inline", "file"); + String randomType = randomFrom("id", "inline"); Map randomParams = Collections.singletonMap(randomAlphaOfLength(10), randomAlphaOfLength(10)); configMap.put(randomType, "foo"); configMap.put("params", randomParams); @@ -77,19 +76,13 @@ public void testFactoryValidationWithParams() throws Exception { public void testFactoryValidationForMultipleScriptingTypes() throws Exception { Map configMap = new HashMap<>(); - String randomType = randomFrom("id", "inline", "file"); - String otherRandomType = randomFrom("id", "inline", "file"); - while (randomType.equals(otherRandomType)) { - otherRandomType = randomFrom("id", "inline", "file"); - } - - configMap.put(randomType, "foo"); - configMap.put(otherRandomType, "bar"); + configMap.put("id", "foo"); + configMap.put("inline", "bar"); configMap.put("lang", "mockscript"); ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, randomAlphaOfLength(10), configMap)); - assertThat(exception.getMessage(), is("Only one of [file], [id], or [inline] may be configured")); + assertThat(exception.getMessage(), is("Only one of [id] or [inline] may be configured")); } public void testFactoryValidationAtLeastOneScriptingType() throws Exception { @@ -99,11 +92,11 @@ public void testFactoryValidationAtLeastOneScriptingType() throws Exception { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, randomAlphaOfLength(10), configMap)); - assertThat(exception.getMessage(), is("Need [file], [id], or [inline] parameter to refer to scripts")); + assertThat(exception.getMessage(), is("Need [id] or [inline] parameter to refer to scripts")); } public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception { - String randomType = randomFrom("inline", "file", "id"); + String randomType = randomFrom("inline", "id"); ScriptService mockedScriptService = mock(ScriptService.class); ScriptException thrownException = new ScriptException("compile-time exception", new RuntimeException(), Collections.emptyList(), "script", "mockscript"); diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java index 815ff37e1265d..c8557a3c62038 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java @@ -69,11 +69,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public Object compile(String scriptName, String scriptSource, Map params) { // classloader created here diff --git a/modules/lang-mustache/build.gradle b/modules/lang-mustache/build.gradle index 8b695fbf574bc..eafd9969a35a0 100644 --- a/modules/lang-mustache/build.gradle +++ b/modules/lang-mustache/build.gradle @@ -31,5 +31,4 @@ integTestCluster { setting 'script.inline', 'true' setting 'script.stored', 'true' setting 'script.max_compilations_per_minute', '1000' - setting 'path.scripts', "${project.buildDir}/resources/test/templates" } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java index 774d5cd25b83d..8aa2c8555f544 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java @@ -85,11 +85,6 @@ public String getType() { return NAME; } - @Override - public String getExtension() { - return NAME; - } - @Override public ExecutableScript executable(CompiledScript compiledScript, @Nullable Map vars) { diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 7d386833a6fec..3e967fa4286c1 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -53,10 +53,6 @@ public class RestSearchTemplateAction extends BaseRestHandler { PARSER.declareField((parser, request, s) -> request.setScriptParams(parser.map()) , new ParseField("params"), ObjectParser.ValueType.OBJECT); - PARSER.declareString((request, s) -> { - request.setScriptType(ScriptType.FILE); - request.setScript(s); - }, new ParseField("file")); PARSER.declareString((request, s) -> { request.setScriptType(ScriptType.STORED); request.setScript(s); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java index 9a4c99b7135db..25f46b9a79e83 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java @@ -101,26 +101,6 @@ public void testParseInlineTemplateAsStringWithParams() throws Exception { assertThat((List) request.getScriptParams().get("status"), hasItems("pending", "published")); } - public void testParseFileTemplate() throws Exception { - String source = "{'file' : 'fileTemplate'}"; - - SearchTemplateRequest request = RestSearchTemplateAction.parse(newParser(source)); - assertThat(request.getScript(), equalTo("fileTemplate")); - assertThat(request.getScriptType(), equalTo(ScriptType.FILE)); - assertThat(request.getScriptParams(), nullValue()); - } - - public void testParseFileTemplateWithParams() throws Exception { - String source = "{'file' : 'template_foo', 'params' : {'foo': 'bar', 'size': 500}}"; - - SearchTemplateRequest request = RestSearchTemplateAction.parse(newParser(source)); - assertThat(request.getScript(), equalTo("template_foo")); - assertThat(request.getScriptType(), equalTo(ScriptType.FILE)); - assertThat(request.getScriptParams().size(), equalTo(2)); - assertThat(request.getScriptParams(), hasEntry("foo", "bar")); - assertThat(request.getScriptParams(), hasEntry("size", 500)); - } - public void testParseStoredTemplate() throws Exception { String source = "{'id' : 'storedTemplate'}"; diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml index f6fc458a08ec2..130a79108d348 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml @@ -29,23 +29,6 @@ - match: { template_output.query.match.text: "bar" } - match: { template_output.aggs.my_terms.terms.field: "field1" } ---- -"File Template validate tests": - - - do: - render_search_template: - body: { "file": "file_search_template", "params": { "my_value": "foo", "my_field": "field1" } } - - - match: { template_output.query.match.text: "foo" } - - match: { template_output.aggs.my_terms.terms.field: "field1" } - - - do: - render_search_template: - body: { "file": "file_search_template", "params": { "my_value": "bar", "my_field": "my_other_field" } } - - - match: { template_output.query.match.text: "bar" } - - match: { template_output.aggs.my_terms.terms.field: "my_other_field" } - --- "Inline Template validate tests": @@ -148,9 +131,3 @@ search_template: body: { "id" : "1", "params" : { "my_value" : "value1_foo", "my_size" : 1 } } - match: { hits.total: 1 } - - - do: - catch: /unable.to.find.file.script.\[simple1\].using.lang.\[mustache\]/ - search_template: - body: { "file" : "simple1"} - diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml index b09976885d435..d796731bdb4b2 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml @@ -22,12 +22,6 @@ - match: { hits.total: 1 } - - do: - search_template: - body: { "file" : "file_search_template", "params": { "my_value": "value1", "my_field" : "_type" } } - - - match: { hits.total: 1 } - - do: put_template: id: "1" @@ -93,23 +87,29 @@ - do: indices.refresh: {} + - do: + put_template: + id: "template_1" + body: { "template": { "query": { "match": { "{{field}}": { "query" : "{{value}}", "operator" : "{{operator}}{{^operator}}or{{/operator}}" } } }, "size": "{{size}}" } } + - match: { acknowledged: true } + - do: search_template: - body: { "file" : "template_1", "params": { "size": "2", "field": "theField", "value": "foo" } } + body: { "id" : "template_1", "params": { "size": "2", "field": "theField", "value": "foo" } } - match: { hits.total: 4 } - length: { hits.hits: 2 } - do: search_template: - body: { "file" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" } } + body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" } } - match: { hits.total: 1 } - length: { hits.hits: 1 } - do: search_template: - body: { "file" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "explain" : true } + body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "explain" : true } - match: { hits.total: 1 } - length: { hits.hits: 1 } @@ -117,7 +117,7 @@ - do: search_template: - body: { "file" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "profile" : true } + body: { "id" : "template_1", "params": { "size": "2", "field": "otherField", "value": "foo" }, "profile" : true } - match: { hits.total: 1 } - length: { hits.hits: 1 } diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml index 8b8ffcf8ae97a..658f2368d4e89 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml @@ -157,41 +157,3 @@ setup: - match: { responses.1.hits.total: 1 } - match: { responses.2.hits.total: 1 } ---- -"Basic multi-search using file template": - - - do: - render_search_template: - body: { "file": "template_1", "params": { "field": "foo", "value": "bar", "size": 20 } } - - - match: { template_output.query.match.foo.query: "bar" } - - match: { template_output.query.match.foo.operator: "or" } - - match: { template_output.size: 20 } - - - do: - msearch_template: - body: - - index: index_* - - file: template_1 - params: - field: "foo" - value: "foo" - size: 10 - - index: _all - - file: template_1 - params: - field: "foo" - value: "bar" - operator: "and" - size: 50 - - index: index_2 - - file: template_1 - params: - field: "foo" - value: "foo" - size: 0 - - - match: { responses.0.hits.total: 2 } - - match: { responses.1.hits.total: 1 } - - match: { responses.2.hits.total: 1 } - diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java index 296e9b2c4b80d..57ecb52cc272a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java @@ -93,15 +93,6 @@ public String getType() { return NAME; } - /** - * Get the extension(s) for the language. - * @return Always contains only the single extension of the language. - */ - @Override - public String getExtension() { - return NAME; - } - /** * When a script is anonymous (inline), we give it this name. */ diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml index eb7cb01da3395..88c40f7ddb577 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml @@ -5,7 +5,7 @@ - do: put_script: - lang: "1" + id: "1" body: { "script": {"lang": "painless", "code": "_score * doc['myParent.weight'].value" } } - match: { acknowledged: true } @@ -37,11 +37,11 @@ - do: catch: request put_script: - lang: "1" + id: "1" body: { "script": {"lang": "painless", "code": "_score * foo bar + doc['myParent.weight'].value"} } - do: catch: /compile error/ put_script: - lang: "1" + id: "1" body: { "script": {"lang": "painless", "code": "_score * foo bar + doc['myParent.weight'].value"} } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 30161503c113c..345b23bf64522 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -99,13 +99,6 @@ private static Script parseScript(Map config) { } else { throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); } - } else if (ScriptType.FILE.getParseField().match(parameterName)) { - if (parameterValue instanceof String || parameterValue == null) { - script = (String) parameterValue; - type = ScriptType.FILE; - } else { - throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); - } } else if (ScriptType.STORED.getParseField().match(parameterName)) { if (parameterValue instanceof String || parameterValue == null) { script = (String) parameterValue; @@ -116,9 +109,8 @@ private static Script parseScript(Map config) { } } if (script == null) { - throw new ElasticsearchParseException("expected one of [{}], [{}] or [{}] fields, but found none", - ScriptType.INLINE.getParseField().getPreferredName(), ScriptType.FILE.getParseField() - .getPreferredName(), ScriptType.STORED.getParseField().getPreferredName()); + throw new ElasticsearchParseException("expected one of [{}] or [{}] fields, but found none", + ScriptType.INLINE.getParseField().getPreferredName(), ScriptType.STORED.getParseField().getPreferredName()); } assert type != null : "if script is not null, type should definitely not be null"; diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java index 6d9476929bb18..bb4d1430fac78 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java @@ -78,7 +78,6 @@ public void testEnvironmentPaths() throws Exception { Settings.Builder settingsBuilder = Settings.builder(); settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.resolve("home").toString()); settingsBuilder.put(Environment.PATH_CONF_SETTING.getKey(), esHome.resolve("conf").toString()); - settingsBuilder.put(Environment.PATH_SCRIPTS_SETTING.getKey(), esHome.resolve("scripts").toString()); settingsBuilder.putArray(Environment.PATH_DATA_SETTING.getKey(), esHome.resolve("data1").toString(), esHome.resolve("data2").toString()); settingsBuilder.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), esHome.resolve("custom").toString()); @@ -117,9 +116,6 @@ public void testEnvironmentPaths() throws Exception { assertExactPermissions(new FilePermission(environment.modulesFile().toString(), "read,readlink"), permissions); // config file: ro assertExactPermissions(new FilePermission(environment.configFile().toString(), "read,readlink"), permissions); - // scripts file: ro - assertExactPermissions(new FilePermission(environment.scriptsFile().toString(), "read,readlink"), permissions); - assertSettingDeprecationsAndWarnings(new Setting[] {Environment.PATH_SCRIPTS_SETTING}); // plugins: ro assertExactPermissions(new FilePermission(environment.pluginsFile().toString(), "read,readlink"), permissions); diff --git a/qa/smoke-test-ingest-with-all-dependencies/build.gradle b/qa/smoke-test-ingest-with-all-dependencies/build.gradle index 73f80f29e2a5e..370adc8ba63d8 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/build.gradle +++ b/qa/smoke-test-ingest-with-all-dependencies/build.gradle @@ -31,6 +31,5 @@ dependencies { integTestCluster { plugin ':plugins:ingest-geoip' setting 'script.inline', 'true' - setting 'path.scripts', "${project.buildDir}/resources/test/scripts" setting 'script.max_compilations_per_minute', '1000' } diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java index 5c5dd7cfe01ea..6c6f7c02330d5 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java @@ -19,6 +19,9 @@ package org.elasticsearch.ingest; +import java.util.Arrays; +import java.util.Collections; + import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.script.ScriptContextRegistry; @@ -29,24 +32,17 @@ import org.elasticsearch.test.ESTestCase; import org.junit.Before; -import java.util.Arrays; -import java.util.Collections; - public abstract class AbstractScriptTestCase extends ESTestCase { protected TemplateService templateService; @Before public void init() throws Exception { - Settings settings = Settings.builder() - .put("path.home", createTempDir()) - .build(); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(new MustacheScriptEngine())); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - ScriptService scriptService = new ScriptService(settings, new Environment(settings), null, - scriptEngineRegistry, scriptContextRegistry, scriptSettings); + ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry, scriptSettings); templateService = new InternalTemplateService(scriptService); } diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml index 729347ee19734..b488c62972596 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml @@ -36,41 +36,6 @@ - match: { _source.bytes_out: 4321 } - match: { _source.bytes_total: 55550 } ---- -"Test script processor with file script": - - do: - ingest.put_pipeline: - id: "my_pipeline" - body: > - { - "description": "_description", - "processors": [ - { - "script" : { - "file": "master" - } - } - ] - } - - match: { acknowledged: true } - - - do: - index: - index: test - type: test - id: 1 - pipeline: "my_pipeline" - body: { bytes_in: 1234, bytes_out: 4321 } - - - do: - get: - index: test - type: test - id: 1 - - match: { _source.bytes_in: 1234 } - - match: { _source.bytes_out: 4321 } - - match: { _source.bytes_total: 5555 } - --- "Test script processor with stored script": - skip: @@ -78,7 +43,7 @@ - do: put_script: - lang: "sum_bytes" + id: "sum_bytes" body: > { "script": { diff --git a/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats b/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats index 9c5ca24d0a0bb..c6ffda809fb71 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats @@ -104,10 +104,6 @@ setup() { # Check that Elasticsearch is working ################################## @test "[TAR] test elasticsearch" { - # Install scripts used to test script filters and search templates before - # starting Elasticsearch so we don't have to wait for elasticsearch to scan for - # them. - install_elasticsearch_test_scripts start_elasticsearch_service run_elasticsearch_tests stop_elasticsearch_service diff --git a/qa/vagrant/src/test/resources/packaging/tests/30_deb_package.bats b/qa/vagrant/src/test/resources/packaging/tests/30_deb_package.bats index b07825d7f2fde..97d04c9405670 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/30_deb_package.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/30_deb_package.bats @@ -96,10 +96,6 @@ setup() { } @test "[DEB] test elasticsearch" { - # Install scripts used to test script filters and search templates before - # starting Elasticsearch so we don't have to wait for elasticsearch to scan for - # them. - install_elasticsearch_test_scripts start_elasticsearch_service run_elasticsearch_tests } @@ -153,7 +149,6 @@ setup() { # The configuration files are still here assert_file_exist "/etc/elasticsearch" - assert_file_exist "/etc/elasticsearch/scripts" assert_file_exist "/etc/elasticsearch/elasticsearch.yml" assert_file_exist "/etc/elasticsearch/jvm.options" assert_file_exist "/etc/elasticsearch/log4j2.properties" @@ -175,7 +170,6 @@ setup() { @test "[DEB] verify package purge" { # all remaining files are deleted by the purge assert_file_not_exist "/etc/elasticsearch" - assert_file_not_exist "/etc/elasticsearch/scripts" assert_file_not_exist "/etc/elasticsearch/elasticsearch.yml" assert_file_not_exist "/etc/elasticsearch/jvm.options" assert_file_not_exist "/etc/elasticsearch/log4j2.properties" diff --git a/qa/vagrant/src/test/resources/packaging/tests/40_rpm_package.bats b/qa/vagrant/src/test/resources/packaging/tests/40_rpm_package.bats index b92b692401e56..7df1593b62e80 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/40_rpm_package.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/40_rpm_package.bats @@ -91,10 +91,6 @@ setup() { } @test "[RPM] test elasticsearch" { - # Install scripts used to test script filters and search templates before - # starting Elasticsearch so we don't have to wait for elasticsearch to scan for - # them. - install_elasticsearch_test_scripts start_elasticsearch_service run_elasticsearch_tests } @@ -162,7 +158,6 @@ setup() { echo "# ping" >> "/etc/elasticsearch/elasticsearch.yml" echo "# ping" >> "/etc/elasticsearch/jvm.options" echo "# ping" >> "/etc/elasticsearch/log4j2.properties" - echo "# ping" >> "/etc/elasticsearch/scripts/script" rpm -e 'elasticsearch' } @@ -192,10 +187,6 @@ setup() { assert_file_exist "/etc/elasticsearch/jvm.options.rpmsave" assert_file_not_exist "/etc/elasticsearch/log4j2.properties" assert_file_exist "/etc/elasticsearch/log4j2.properties.rpmsave" - # older versions of rpm behave differently and preserve the - # directory but do not append the ".rpmsave" suffix - test -e "/etc/elasticsearch/scripts" || test -e "/etc/elasticsearch/scripts.rpmsave" - test -e "/etc/elasticsearch/scripts/script" || test -e "/etc/elasticsearch/scripts.rpmsave/script" assert_file_not_exist "/etc/init.d/elasticsearch" assert_file_not_exist "/usr/lib/systemd/system/elasticsearch.service" diff --git a/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats b/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats index b46fd6786bbcb..47c8ca85205f0 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats @@ -69,11 +69,6 @@ setup() { } @test "[SYSTEMD] start" { - # Install scripts used to test script filters and search templates before - # starting Elasticsearch so we don't have to wait for elasticsearch to scan for - # them. - install_elasticsearch_test_scripts - # Capture the current epoch in millis run date +%s epoch="$output" diff --git a/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats b/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats index fa6f91498ca02..0df802528b24a 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats +++ b/qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats @@ -84,10 +84,6 @@ setup() { } @test "[INIT.D] start" { - # Install scripts used to test script filters and search templates before - # starting Elasticsearch so we don't have to wait for elasticsearch to scan for - # them. - install_elasticsearch_test_scripts service elasticsearch start wait_for_elasticsearch_status assert_file_exist "/var/run/elasticsearch/elasticsearch.pid" diff --git a/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.mustache b/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.mustache deleted file mode 100644 index f43d6074d505b..0000000000000 --- a/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.mustache +++ /dev/null @@ -1,10 +0,0 @@ -{ - "query": { - "script": { - "script": { - "file": "is_guide", - "lang": "painless" - } - } - } -} diff --git a/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.painless b/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.painless deleted file mode 100644 index f07435eaf6678..0000000000000 --- a/qa/vagrant/src/test/resources/packaging/tests/example/scripts/is_guide.painless +++ /dev/null @@ -1,5 +0,0 @@ -def min = 300; -if (params.min_num_pages != null) { - min = params.min_num_pages; -} -return doc['pages'].value >= min; diff --git a/qa/vagrant/src/test/resources/packaging/utils/utils.bash b/qa/vagrant/src/test/resources/packaging/utils/utils.bash index bb0ebbf1814eb..aee9f7e506010 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/utils.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/utils.bash @@ -1,7 +1,7 @@ #!/bin/bash -# This file contains some utilities to test the elasticsearch scripts, -# the .deb/.rpm packages and the SysV/Systemd scripts. +# This file contains some utilities to test the the .deb/.rpm +# packages and the SysV/Systemd scripts. # WARNING: This testing file must be executed as root and can # dramatically change your system. It should only be executed @@ -476,11 +476,6 @@ check_elasticsearch_version() { } } -install_elasticsearch_test_scripts() { - install_script is_guide.painless - install_script is_guide.mustache -} - # Executes some basic Elasticsearch tests run_elasticsearch_tests() { # TODO this assertion is the same the one made when waiting for @@ -502,24 +497,6 @@ run_elasticsearch_tests() { curl -s -XGET 'http://localhost:9200/_count?pretty' | grep \"count\"\ :\ 2 - curl -s -H "Content-Type: application/json" -XPOST 'http://localhost:9200/library/book/_count?pretty' -d '{ - "query": { - "script": { - "script": { - "file": "is_guide", - "lang": "painless", - "params": { - "min_num_pages": 100 - } - } - } - } - }' | grep \"count\"\ :\ 2 - - curl -s -H "Content-Type: application/json" -XGET 'http://localhost:9200/library/book/_search/template?pretty' -d '{ - "file": "is_guide" - }' | grep \"total\"\ :\ 1 - curl -s -XDELETE 'http://localhost:9200/_all' } @@ -537,15 +514,6 @@ move_config() { assert_file_exist "$ESCONFIG/log4j2.properties" } -# Copies a script into the Elasticsearch install. -install_script() { - local name=$1 - mkdir -p $ESSCRIPTS - local script="$BATS_TEST_DIRNAME/example/scripts/$name" - echo "Installing $script to $ESSCRIPTS" - cp $script $ESSCRIPTS -} - # permissions from the user umask with the executable bit set executable_privileges_for_user_from_umask() { local user=$1 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/put_script.json b/rest-api-spec/src/main/resources/rest-api-spec/api/put_script.json index 93fef4c030b7a..c29fdbbca0ad9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/put_script.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/put_script.json @@ -3,8 +3,8 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html", "methods": ["PUT", "POST"], "url": { - "path": "/_scripts/{lang}", - "paths": [ "/_scripts/{lang}", "/_scripts/{lang}/{id}" ], + "path": "/_scripts/{id}", + "paths": [ "/_scripts/{id}", "/_scripts/{lang}/{id}" ], "parts": { "id": { "type" : "string", @@ -25,4 +25,4 @@ "required" : true } } -} \ No newline at end of file +} diff --git a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java index 2f6677d1d6811..a6dbc083fe143 100644 --- a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java +++ b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java @@ -66,11 +66,6 @@ public String getType() { return type; } - @Override - public String getExtension() { - return getType(); - } - @Override public Object compile(String name, String source, Map params) { // Scripts are always resolved using the script's source. For inline scripts, it's easy because they don't have names and the diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index 79d813940fa60..2946f626d6eb8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -1087,12 +1087,7 @@ ScriptModule createScriptModule(List scriptPlugins) { if (scriptPlugins == null || scriptPlugins.isEmpty()) { return newTestScriptModule(); } - - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) - .build(); - Environment environment = new Environment(settings); - return ScriptModule.create(settings, environment, null, scriptPlugins); + return ScriptModule.create(Settings.EMPTY, scriptPlugins); } } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 101a6d7cb452e..e96451999788e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -1200,12 +1200,8 @@ public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Setti } public static ScriptModule newTestScriptModule() { - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) - .build(); - Environment environment = new Environment(settings); MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1")); - return new ScriptModule(settings, environment, null, singletonList(scriptEngine), emptyList()); + return new ScriptModule(Settings.EMPTY, singletonList(scriptEngine), emptyList()); } /** Creates an IndicesModule for testing with the given mappers and metadata mappers. */ diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java index 5f97eb4af6a8f..eab62c2514539 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java @@ -53,6 +53,9 @@ public static ClientYamlTestSuite parse(String api, Path file) throws IOExceptio //our yaml parser seems to be too tolerant. Each yaml suite must end with \n, otherwise clients tests might break. try (FileChannel channel = FileChannel.open(file, StandardOpenOption.READ)) { ByteBuffer bb = ByteBuffer.wrap(new byte[1]); + if (channel.size() == 0) { + throw new IllegalArgumentException("test suite file " + file.toString() + " is empty"); + } channel.read(bb, channel.size() - 1); if (bb.get(0) != 10) { throw new IOException("test suite [" + api + "/" + filename + "] doesn't end with line feed (\\n)");