Scripting: Deprecate native scripts (#24692)

Native scripts are no longer documented and instead using a ScriptEngine
is recommended. This change adds a deprecation warning for removal in
6.0.

relates #19966
This commit is contained in:
Ryan Ernst 2017-05-16 11:57:18 -07:00 committed by GitHub
parent d09e64323f
commit 25dd64497b
3 changed files with 12 additions and 0 deletions

View File

@ -19,9 +19,12 @@
package org.elasticsearch.script; package org.elasticsearch.script;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.search.lookup.SearchLookup;
@ -41,6 +44,11 @@ public class NativeScriptEngine extends AbstractComponent implements ScriptEngin
public NativeScriptEngine(Settings settings, Map<String, NativeScriptFactory> scripts) { public NativeScriptEngine(Settings settings, Map<String, NativeScriptFactory> scripts) {
super(settings); super(settings);
if (scripts.isEmpty() == false) {
Logger logger = Loggers.getLogger(ScriptModule.class);
DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
deprecationLogger.deprecated("Native scripts are deprecated. Use a custom ScriptEngine to write scripts in java.");
}
this.scripts = unmodifiableMap(scripts); this.scripts = unmodifiableMap(scripts);
} }

View File

@ -31,7 +31,9 @@ import java.util.Map;
* @see AbstractSearchScript * @see AbstractSearchScript
* @see AbstractLongSearchScript * @see AbstractLongSearchScript
* @see AbstractDoubleSearchScript * @see AbstractDoubleSearchScript
* @deprecated Create a {@link ScriptEngine} instead of using native scripts
*/ */
@Deprecated
public interface NativeScriptFactory { public interface NativeScriptFactory {
/** /**

View File

@ -55,6 +55,7 @@ public class NativeScriptTests extends ESTestCase {
CompiledScript compiledScript = scriptModule.getScriptService().compile(script, ScriptContext.Standard.SEARCH); CompiledScript compiledScript = scriptModule.getScriptService().compile(script, ScriptContext.Standard.SEARCH);
ExecutableScript executable = scriptModule.getScriptService().executable(compiledScript, script.getParams()); ExecutableScript executable = scriptModule.getScriptService().executable(compiledScript, script.getParams());
assertThat(executable.run().toString(), equalTo("test")); assertThat(executable.run().toString(), equalTo("test"));
assertWarnings("Native scripts are deprecated. Use a custom ScriptEngine to write scripts in java.");
} }
public void testFineGrainedSettingsDontAffectNativeScripts() throws IOException { public void testFineGrainedSettingsDontAffectNativeScripts() throws IOException {
@ -82,6 +83,7 @@ public class NativeScriptTests extends ESTestCase {
assertThat(scriptService.compile(new Script(ScriptType.INLINE, NativeScriptEngine.NAME, "my", Collections.emptyMap()), assertThat(scriptService.compile(new Script(ScriptType.INLINE, NativeScriptEngine.NAME, "my", Collections.emptyMap()),
scriptContext), notNullValue()); scriptContext), notNullValue());
} }
assertWarnings("Native scripts are deprecated. Use a custom ScriptEngine to write scripts in java.");
} }
public static class MyNativeScriptFactory implements NativeScriptFactory { public static class MyNativeScriptFactory implements NativeScriptFactory {