Scripting: Remove file scripts (#24627)

This commit removes file scripts, which were deprecated in 5.5.

closes #21798
This commit is contained in:
Ryan Ernst 2017-05-17 14:42:25 -07:00 committed by GitHub
parent f8a48badcf
commit 463fe2f4d4
86 changed files with 216 additions and 1220 deletions

View File

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

View File

@ -338,7 +338,7 @@ public class QueryDSLDocumentationTests extends ESTestCase {
Map<String, Object> parameters = new HashMap<>();
parameters.put("param1", 5);
scriptQuery(new Script(
ScriptType.FILE, // <1>
ScriptType.STORED, // <1>
"painless", // <2>
"myscript", // <3>
singletonMap("param1", 5))); // <4>

View File

@ -256,7 +256,6 @@ final class Security {
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");

View File

@ -302,7 +302,6 @@ public final class ClusterSettings extends AbstractScopedSettings {
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 final class ClusterSettings extends AbstractScopedSettings {
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,

View File

@ -55,8 +55,6 @@ public class Environment {
public static final Setting<String> DEFAULT_PATH_CONF_SETTING = Setting.simpleString("default.path.conf", Property.NodeScope);
public static final Setting<String> PATH_CONF_SETTING =
new Setting<>("path.conf", DEFAULT_PATH_CONF_SETTING, Function.identity(), Property.NodeScope);
public static final Setting<String> PATH_SCRIPTS_SETTING =
Setting.simpleString("path.scripts", Property.NodeScope, Property.Deprecated);
public static final Setting<List<String>> DEFAULT_PATH_DATA_SETTING =
Setting.listSetting("default.path.data", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<List<String>> 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 class Environment {
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<String> dataPaths = PATH_DATA_SETTING.get(settings);
@ -281,13 +271,6 @@ public class Environment {
return configFile;
}
/**
* Location of on-disk scripts
*/
public Path scriptsFile() {
return scriptsFile;
}
public Path pluginsFile() {
return pluginsFile;
}
@ -332,7 +315,6 @@ public class Environment {
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");

View File

@ -325,8 +325,7 @@ public class Node implements Closeable {
}
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

View File

@ -57,11 +57,6 @@ public class NativeScriptEngine extends AbstractComponent implements ScriptEngin
return NAME;
}
@Override
public String getExtension() {
return ""; // Native scripts have no extensions
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
NativeScriptFactory scriptFactory = scripts.get(scriptSource);

View File

@ -74,15 +74,6 @@ import java.util.Objects;
* <li> {@link Script#params} - {@link Map} of user-defined parameters; must not be {@code null},
* use an empty {@link Map} to specify no params
* </ul>
* <li> {@link ScriptType#FILE}
* <ul>
* <li> {@link Script#lang} - specifies the language for look up, defaults to {@link Script#DEFAULT_SCRIPT_LANG}
* <li> {@link Script#idOrCode} - specifies the id of the file script to be looked up, must not be {@code null}
* <li> {@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}
* <li> {@link Script#params} - {@link Map} of user-defined parameters; must not be {@code null},
* use an empty {@link Map} to specify no params
* </ul>
* </ul>
*/
public final class Script implements ToXContentObject, Writeable {
@ -193,26 +184,13 @@ public final class Script implements ToXContentObject, Writeable {
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 @@ public final class Script implements ToXContentObject, Writeable {
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 @@ public final class Script implements ToXContentObject, Writeable {
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 <code> 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 @@ public final class Script implements ToXContentObject, Writeable {
// 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 final class Script implements ToXContentObject, Writeable {
/**
* 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 final class Script implements ToXContentObject, Writeable {
/**
* 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 final class Script implements ToXContentObject, Writeable {
"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 final class Script implements ToXContentObject, Writeable {
}
/**
* @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 final class Script implements ToXContentObject, Writeable {
}
/**
* @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() {

View File

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

View File

@ -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<ScriptPlugin> scriptPlugins) {
public static ScriptModule create(Settings settings, List<ScriptPlugin> scriptPlugins) {
Map<String, NativeScriptFactory> 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 class ScriptModule {
scriptEngines.add(nativeScriptEngineService);
List<ScriptContext.Plugin> 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<ScriptEngine> scriptEngines,
public ScriptModule(Settings settings, List<ScriptEngine> scriptEngines,
List<ScriptContext.Plugin> 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);
}

View File

@ -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.Cache;
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<TimeValue> SCRIPT_CACHE_EXPIRE_SETTING =
Setting.positiveTimeSetting("script.cache.expire", TimeValue.timeValueMillis(0), Property.NodeScope);
public static final Setting<Boolean> SCRIPT_AUTO_RELOAD_ENABLED_SETTING =
Setting.boolSetting("script.auto_reload_enabled", true, Property.NodeScope, Property.Deprecated);
public static final Setting<Integer> SCRIPT_MAX_SIZE_IN_BYTES =
Setting.intSetting("script.max_size_in_bytes", 65535, Property.NodeScope);
public static final Setting<Integer> SCRIPT_MAX_COMPILATIONS_PER_MINUTE =
Setting.intSetting("script.max_compilations_per_minute", 15, 0, Property.Dynamic, Property.NodeScope);
private final Collection<ScriptEngine> scriptEngines;
private final Map<String, ScriptEngine> scriptEnginesByLang;
private final Map<String, ScriptEngine> scriptEnginesByExt;
private final ConcurrentMap<CacheKey, CompiledScript> staticCache = ConcurrentCollections.newConcurrentMap();
private final Map<String, ScriptEngine> engines;
private final Cache<CacheKey, CompiledScript> 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 class ScriptService extends AbstractComponent implements Closeable, Clust
"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 class ScriptService extends AbstractComponent implements Closeable, Clust
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);
this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();
Map<String, ScriptEngine> enginesByLangBuilder = new HashMap<>();
Map<String, ScriptEngine> 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 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
@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 class ScriptService extends AbstractComponent implements Closeable, Clust
" 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 class ScriptService extends AbstractComponent implements Closeable, Clust
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 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
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 class ScriptService extends AbstractComponent implements Closeable, Clust
}
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 class ScriptService extends AbstractComponent implements Closeable, Clust
* Executes a previously compiled script provided as an argument
*/
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> params) {
return getScriptEngineServiceForLang(compiledScript.lang()).executable(compiledScript, params);
return getEngine(compiledScript.lang()).executable(compiledScript, params);
}
/**
@ -497,7 +419,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
* {@link SearchScript} ready for execution
*/
public SearchScript search(SearchLookup lookup, CompiledScript compiledScript, Map<String, Object> 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 class ScriptService extends AbstractComponent implements Closeable, Clust
}
}
private class ScriptChangesListener implements FileChangesListener {
private boolean deprecationEmitted = false;
private Tuple<String, String> 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<String, String> 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<String, String> 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;

View File

@ -84,9 +84,6 @@ public class ScriptSettings {
final boolean defaultNonFileScriptMode = scriptEngineRegistry.getDefaultInlineScriptEnableds().get(language);
boolean defaultLangAndType = defaultNonFileScriptMode;
// Files are treated differently because they are never default-deny
if (ScriptType.FILE == scriptType) {
defaultLangAndType = ScriptType.FILE.isDefaultEnabled();
}
final boolean defaultIfNothingSet = defaultLangAndType;
Function<Settings, String> defaultLangAndTypeFn = settings -> {

View File

@ -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() + "]]");
}

View File

@ -253,9 +253,6 @@ public class TribeService extends AbstractLifecycleComponent {
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()));

View File

@ -151,8 +151,6 @@ public class UpdateRequestTests extends ESTestCase {
new ResourceWatcherService(baseSettings, null);
ScriptService scriptService = new ScriptService(
baseSettings,
environment,
watcherService,
scriptEngineRegistry,
scriptContextRegistry,
scriptSettings);

View File

@ -131,8 +131,7 @@ public class IndexModuleTests extends ESTestCase {
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();

View File

@ -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.");
}
}

View File

@ -46,7 +46,8 @@ public class NativeScriptTests extends ESTestCase {
.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<Setting<?>> scriptSettings = scriptModule.getSettings();
scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
@ -68,15 +69,13 @@ public class NativeScriptTests extends ESTestCase {
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<String, NativeScriptFactory> 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()) {

View File

@ -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 @@ public class ScriptContextTests extends ESTestCase {
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 class ScriptContextTests extends ESTestCase {
}
}
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 class ScriptContextTests extends ESTestCase {
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 class ScriptContextTests extends ESTestCase {
}
}
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 class ScriptContextTests extends ESTestCase {
}
}
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));
}
}

View File

@ -88,7 +88,7 @@ public class ScriptModesTests extends ESTestCase {
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 class ScriptModesTests extends ESTestCase {
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 class ScriptModesTests extends ESTestCase {
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 class ScriptModesTests extends ESTestCase {
}
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 class ScriptModesTests extends ESTestCase {
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 class ScriptModesTests extends ESTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return null;

View File

@ -18,27 +18,7 @@
*/
package org.elasticsearch.script;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
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;
@ -48,15 +28,30 @@ 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;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.breaker.CircuitBreakingException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
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.junit.Before;
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<String, ScriptEngine> 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<ScriptType, Boolean> 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 class ScriptServiceTests extends ESTestCase {
.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 class ScriptServiceTests extends ESTestCase {
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 class ScriptServiceTests extends ESTestCase {
}
}
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 class ScriptServiceTests extends ESTestCase {
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 class ScriptServiceTests extends ESTestCase {
}
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 class ScriptServiceTests extends ESTestCase {
}
}
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 class ScriptServiceTests extends ESTestCase {
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 class ScriptServiceTests extends ESTestCase {
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 class ScriptServiceTests extends ESTestCase {
return name;
}
@Override
public String getExtension() {
return name;
}
@Override
public Object compile(String scriptName, String scriptText, Map<String, String> params) {
return "compiled_" + scriptText;
@ -625,11 +529,6 @@ public class ScriptServiceTests extends ESTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return "compiled_" + scriptSource;

View File

@ -33,12 +33,9 @@ import static org.hamcrest.Matchers.equalTo;
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 class ScriptSettingsTests extends ESTestCase {
}
}
if (deprecated != null) {
System.arraycopy(deprecated, 0, settings, keys.length, deprecated.length);
}
return settings;
}
@ -82,11 +75,6 @@ public class ScriptSettingsTests extends ESTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return null;

View File

@ -418,11 +418,6 @@ public class AvgIT extends AbstractNumericTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;
@ -523,11 +518,6 @@ public class AvgIT extends AbstractNumericTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;

View File

@ -815,44 +815,6 @@ public class ScriptedMetricIT extends ESIntegTestCase {
assertThat(((Number) object).longValue(), equalTo(numDocs * 3));
}
public void testInitMapCombineReduceWithParamsFile() {
Map<String, Object> varsMap = new HashMap<>();
varsMap.put("multiplier", 1);
Map<String, Object> 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<String, Object> varsMap = new HashMap<>();
varsMap.put("multiplier", 1);

View File

@ -418,11 +418,6 @@ public class SumIT extends AbstractNumericTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;
@ -530,11 +525,6 @@ public class SumIT extends AbstractNumericTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;

View File

@ -272,11 +272,6 @@ public class ValueCountIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;

View File

@ -67,9 +67,6 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
*/
@Override
protected ScriptService mockScriptService() {
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.build();
// mock script always retuns the size of the input aggs list as result
@SuppressWarnings("unchecked")
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME,
@ -80,7 +77,7 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
try {
return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry,
return new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry,
scriptSettings);
} catch (IOException e) {
throw new ElasticsearchException(e);

View File

@ -198,15 +198,13 @@ public class ScriptedMetricAggregatorTests extends AggregatorTestCase {
@Override
protected QueryShardContext queryShardContextMock(MapperService mapperService, final MappedFieldType[] fieldTypes,
CircuitBreakerService circuitBreakerService) {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS);
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService;
try {
scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry,
scriptSettings);
scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
} catch (IOException e) {
throw new ElasticsearchException(e);
}

View File

@ -93,8 +93,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngine()));
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptService = new ScriptService(baseSettings, environment,
new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
scriptService = new ScriptService(baseSettings, scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
@Override
public CompiledScript compile(Script script, ScriptContext scriptContext) {
return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);

View File

@ -1030,11 +1030,6 @@ public class SuggestSearchIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;

View File

@ -65,12 +65,10 @@ public class TribeServiceTests extends ESTestCase {
.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 class TribeServiceTests extends ESTestCase {
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() {

View File

@ -91,11 +91,6 @@ public class UpdateIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return new Object(); // unused
@ -164,11 +159,6 @@ public class UpdateIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;
@ -230,11 +220,6 @@ public class UpdateIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return new Object(); // unused
@ -297,11 +282,6 @@ public class UpdateIT extends ESIntegTestCase {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return new Object(); // unused

View File

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

View File

@ -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 }
'''

View File

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

View File

@ -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]

View File

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

View File

@ -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.

View File

@ -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:

View File

@ -67,7 +67,7 @@ POST /sales/_search
// TEST[setup:sales]
This will use the <<modules-scripting-painless, Painless>> 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

View File

@ -68,7 +68,7 @@ POST /sales/_search
// TEST[setup:sales]
This will use the <<modules-scripting-painless, Painless>> 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

View File

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

View File

@ -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[]

View File

@ -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.

View File

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

View File

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

View File

@ -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]

View File

@ -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 <<modules-scripting-using, How to use scripts>> 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 <<modules-scripting-using-caching, Script Caching>>.
|======
| 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.

View File

@ -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
<<modules-scripting-security-do-no-weaken, above>>. 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>

View File

@ -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 <<modules-scripting-stored-scripts,Stored Scripts>>),
and a `file` script is retrieved from a file in the `config/scripts`
directory (see <<modules-scripting-file-scripts, File Scripts>>).
+
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
<<modules-scripting-security,scripting security settings>>.
`inline` as in the example above. A `stored` script is specified `stored`
and is retrieved from the cluster state (see <<modules-scripting-stored-scripts,Stored Scripts>>).
`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
<<zip-targz-layout,`zip`/`tar.gz`>> (`$ES_HOME/config/scripts/`),
<<rpm-layout,RPM>>, or <<deb-layout,Debian>> 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 <<reload-scripts,every 60 seconds thereafter>>.
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

View File

@ -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.

View File

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

View File

@ -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[]

View File

@ -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[]

View File

@ -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[]

View File

@ -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
|=======================================================================

View File

@ -37,7 +37,6 @@ import static org.elasticsearch.common.Strings.hasLength;
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 final class ScriptProcessor extends AbstractProcessor {
Map<String, Object> 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<String, ?> 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 final class ScriptProcessor extends AbstractProcessor {
final Script script;
String scriptPropertyUsed;
if (Strings.hasLength(file)) {
script = new Script(FILE, lang, file, (Map<String, Object>)params);
scriptPropertyUsed = "file";
} else if (Strings.hasLength(inline)) {
if (Strings.hasLength(inline)) {
script = new Script(INLINE, lang, inline, (Map<String, Object>)params);
scriptPropertyUsed = "inline";
} else if (Strings.hasLength(id)) {

View File

@ -44,7 +44,6 @@ public class ScriptProcessorFactoryTests extends ESTestCase {
Map<String, String> map = new HashMap<>();
map.put("id", "stored");
map.put("inline", "inline");
map.put("file", "file");
ingestScriptParamToType = Collections.unmodifiableMap(map);
}
@ -55,7 +54,7 @@ public class ScriptProcessorFactoryTests extends ESTestCase {
public void testFactoryValidationWithDefaultLang() throws Exception {
Map<String, Object> 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 class ScriptProcessorFactoryTests extends ESTestCase {
public void testFactoryValidationWithParams() throws Exception {
Map<String, Object> configMap = new HashMap<>();
String randomType = randomFrom("id", "inline", "file");
String randomType = randomFrom("id", "inline");
Map<String, Object> randomParams = Collections.singletonMap(randomAlphaOfLength(10), randomAlphaOfLength(10));
configMap.put(randomType, "foo");
configMap.put("params", randomParams);
@ -77,19 +76,13 @@ public class ScriptProcessorFactoryTests extends ESTestCase {
public void testFactoryValidationForMultipleScriptingTypes() throws Exception {
Map<String, Object> 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 class ScriptProcessorFactoryTests extends ESTestCase {
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");

View File

@ -69,11 +69,6 @@ public class ExpressionScriptEngine extends AbstractComponent implements ScriptE
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
// classloader created here

View File

@ -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"
}

View File

@ -85,11 +85,6 @@ public final class MustacheScriptEngine implements ScriptEngine {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public ExecutableScript executable(CompiledScript compiledScript,
@Nullable Map<String, Object> vars) {

View File

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

View File

@ -101,26 +101,6 @@ public class SearchTemplateRequestTests extends ESTestCase {
assertThat((List<String>) 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'}";

View File

@ -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"}

View File

@ -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 }

View File

@ -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 }

View File

@ -93,15 +93,6 @@ public final class PainlessScriptEngine extends AbstractComponent implements Scr
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.
*/

View File

@ -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"} }

View File

@ -99,13 +99,6 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
} 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 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
}
}
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";

View File

@ -78,7 +78,6 @@ public class EvilSecurityTests extends ESTestCase {
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 class EvilSecurityTests extends ESTestCase {
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);

View File

@ -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'
}

View File

@ -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.script.mustache.MustacheScriptEngine;
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);
}

View File

@ -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": {

View File

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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -1,10 +0,0 @@
{
"query": {
"script": {
"script": {
"file": "is_guide",
"lang": "painless"
}
}
}
}

View File

@ -1,5 +0,0 @@
def min = 300;
if (params.min_num_pages != null) {
min = params.min_num_pages;
}
return doc['pages'].value >= min;

View File

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

View File

@ -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
}
}
}
}

View File

@ -66,11 +66,6 @@ public class MockScriptEngine implements ScriptEngine {
return type;
}
@Override
public String getExtension() {
return getType();
}
@Override
public Object compile(String name, String source, Map<String, String> params) {
// Scripts are always resolved using the script's source. For inline scripts, it's easy because they don't have names and the

View File

@ -1087,12 +1087,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
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);
}
}
}

View File

@ -1200,12 +1200,8 @@ public abstract class ESTestCase extends LuceneTestCase {
}
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. */

View File

@ -53,6 +53,9 @@ public class ClientYamlTestSuite {
//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)");