diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java index c4bbc2186b9..dee4d8ae66b 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; -import org.elasticsearch.script.ScriptEngineService; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.groovy.GroovyScriptEngineService; @@ -25,8 +24,7 @@ import org.junit.Ignore; import org.mockito.Mockito; import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.Collections; @Ignore // not a test. @SuppressForbidden(reason = "gradle is broken and tries to run me as a test") @@ -38,19 +36,13 @@ public final class MessyTestUtils { .put("path.home", LuceneTestCase.createTempDir()) .build(); GroovyScriptEngineService groovyScriptEngineService = new GroovyScriptEngineService(settings); - Set engineServiceSet = new HashSet<>(); - engineServiceSet.add(groovyScriptEngineService); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry( - Arrays.asList( - new ScriptEngineRegistry.ScriptEngineRegistration(GroovyScriptEngineService.class, GroovyScriptEngineService.NAME) - ) - ); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(groovyScriptEngineService)); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Arrays.asList(ScriptServiceProxy.INSTANCE)); ClusterService clusterService = Mockito.mock(ClusterService.class); Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), engineServiceSet, + return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings), clusterService); } diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java index efe00900d07..5475529e2d8 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java @@ -49,18 +49,14 @@ public class WatcherTemplateTests extends ESTestCase { public void init() throws Exception { Settings setting = Settings.builder().put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, true).build(); Environment environment = Mockito.mock(Environment.class); - Set engines = Collections.singleton(new MustacheScriptEngineService(setting)); ResourceWatcherService resourceWatcherService = Mockito.mock(ResourceWatcherService.class); ScriptContextRegistry registry = new ScriptContextRegistry(Collections.singletonList(ScriptServiceProxy.INSTANCE)); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry( - Arrays.asList( - new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, - MustacheScriptEngineService.NAME) - ) + Collections.singleton(new MustacheScriptEngineService(setting)) ); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry); - ScriptService scriptService = new ScriptService(setting, environment, engines, resourceWatcherService, scriptEngineRegistry, + ScriptService scriptService = new ScriptService(setting, environment, resourceWatcherService, scriptEngineRegistry, registry, scriptSettings); ClusterService clusterService = Mockito.mock(ClusterService.class); Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); diff --git a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/test/GraphTests.java b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/test/GraphTests.java index 9fe576c8dc5..9131921669f 100644 --- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/test/GraphTests.java +++ b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/test/GraphTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.ScriptQueryBuilder; import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptFactory; @@ -34,6 +35,8 @@ import org.elasticsearch.xpack.graph.action.Vertex; import org.elasticsearch.xpack.graph.action.VertexRequest; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; @@ -346,7 +349,7 @@ public class GraphTests extends ESSingleNodeTestCase { assertThat(why, strongVertex.getWeight(), greaterThan(weakVertex.getWeight())); } - public static class ScriptedTimeoutPlugin extends Plugin { + public static class ScriptedTimeoutPlugin extends Plugin implements ScriptPlugin { @Override public String name() { return "test-scripted-graph-timeout"; @@ -357,8 +360,9 @@ public class GraphTests extends ESSingleNodeTestCase { return "Test for scripted timeouts on graph searches"; } - public void onModule(ScriptModule module) { - module.registerScript(NativeTestScriptedTimeout.TEST_NATIVE_SCRIPT_TIMEOUT, NativeTestScriptedTimeout.Factory.class); + @Override + public List getNativeScripts() { + return Collections.singletonList(new NativeTestScriptedTimeout.Factory()); } } @@ -377,6 +381,11 @@ public class GraphTests extends ESSingleNodeTestCase { public boolean needsScores() { return false; } + + @Override + public String getName() { + return TEST_NATIVE_SCRIPT_TIMEOUT; + } } @Override diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 456f8db3598..17aefe14881 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -22,6 +22,8 @@ import org.elasticsearch.index.IndexModule; import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.ScriptPlugin; +import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.shield.Security; import org.elasticsearch.shield.authc.AuthenticationModule; @@ -31,6 +33,7 @@ import org.elasticsearch.xpack.action.TransportXPackInfoAction; import org.elasticsearch.xpack.action.TransportXPackUsageAction; import org.elasticsearch.xpack.action.XPackInfoAction; import org.elasticsearch.xpack.action.XPackUsageAction; +import org.elasticsearch.xpack.common.ScriptServiceProxy; import org.elasticsearch.xpack.common.http.HttpClientModule; import org.elasticsearch.xpack.common.init.LazyInitializationModule; import org.elasticsearch.xpack.common.init.LazyInitializationService; @@ -55,7 +58,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -public class XPackPlugin extends Plugin { +public class XPackPlugin extends Plugin implements ScriptPlugin { public static final String NAME = "x-pack"; @@ -182,8 +185,9 @@ public class XPackPlugin extends Plugin { return builder.build(); } - public void onModule(ScriptModule module) { - watcher.onModule(module); + @Override + public ScriptContext.Plugin getCustomScriptContexts() { + return ScriptServiceProxy.INSTANCE; } public void onModule(SettingsModule module) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 2f8b1e1ce2f..50d34f72318 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -140,9 +140,6 @@ public class Watcher { return Settings.EMPTY; } - public void onModule(ScriptModule module) { - module.registerScriptContext(ScriptServiceProxy.INSTANCE); - } public void onModule(SettingsModule module) { for (TemplateConfig templateConfig : WatcherIndexTemplateRegistry.TEMPLATE_CONFIGS) { diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java index 6430fde4a16..31b4f8fb44f 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java @@ -5,10 +5,9 @@ */ package org.elasticsearch.script; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.common.text.DefaultTextTemplateEngine; -import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -27,10 +26,10 @@ public class MockMustacheScriptEngine extends MockScriptEngine { return NAME; } - public void onModule(ScriptModule module) { - module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MockMustacheScriptEngine.class, NAME, true)); + @Override + public ScriptEngineService getScriptEngineService(Settings settings) { + return new MockMustacheScriptEngine(); } - } @Override @@ -51,4 +50,9 @@ public class MockMustacheScriptEngine extends MockScriptEngine { return super.compile(name, script, params); } + + @Override + public boolean isInlineScriptEnabled() { + return true; + } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/SleepScriptEngine.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/SleepScriptEngine.java index c0cf787d7e8..ad593bfe8ac 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/SleepScriptEngine.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/SleepScriptEngine.java @@ -6,12 +6,13 @@ package org.elasticsearch.script; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.search.lookup.SearchLookup; import java.io.IOException; import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -21,7 +22,7 @@ public class SleepScriptEngine implements ScriptEngineService { public static final String NAME = "sleep"; - public static class TestPlugin extends Plugin { + public static class TestPlugin extends Plugin implements ScriptPlugin { public TestPlugin() { } @@ -36,11 +37,10 @@ public class SleepScriptEngine implements ScriptEngineService { return "Mock script engine for integration tests"; } - public void onModule(ScriptModule module) { - module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(SleepScriptEngine.class, - SleepScriptEngine.NAME, true)); + @Override + public ScriptEngineService getScriptEngineService(Settings settings) { + return new SleepScriptEngine(); } - } @Override @@ -92,4 +92,8 @@ public class SleepScriptEngine implements ScriptEngineService { .params(Collections.singletonMap("millis", millis)).build(); } + @Override + public boolean isInlineScriptEnabled() { + return true; + } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index e576cfd50ab..f11d07a3f4a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -254,7 +254,7 @@ public final class WatcherTestUtils { ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); ClusterService clusterService = Mockito.mock(ClusterService.class); Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); - return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), Collections.emptySet(), + return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings), clusterService); }