Remove overrides of isInlineScriptEnabled (elastic/x-pack-elasticsearch#1500)
This is the xpack side of elastic/elasticsearch#24815 Original commit: elastic/x-pack-elasticsearch@5aa314a49d
This commit is contained in:
parent
d18c48f820
commit
883f5d8a7a
|
@ -93,11 +93,6 @@ public class LatchScriptEngine implements ScriptEngine {
|
||||||
return new Script(ScriptType.INLINE, NAME, "", Collections.emptyMap());
|
return new Script(ScriptType.INLINE, NAME, "", Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInlineScriptEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LatchScriptPlugin extends Plugin implements ScriptPlugin {
|
public static class LatchScriptPlugin extends Plugin implements ScriptPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,9 +46,4 @@ public class MockMustacheScriptEngine extends MockScriptEngine {
|
||||||
// We always return the script's source as it is
|
// We always return the script's source as it is
|
||||||
return new MockCompiledScript(name, params, script, null);
|
return new MockCompiledScript(name, params, script, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInlineScriptEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,4 @@ public class MockPainlessScriptEngine extends MockScriptEngine {
|
||||||
// We always return the script's source as it is
|
// We always return the script's source as it is
|
||||||
return new MockCompiledScript(name, params, script, null);
|
return new MockCompiledScript(name, params, script, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInlineScriptEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
import org.elasticsearch.env.Environment;
|
|
||||||
import org.elasticsearch.script.GeneralScriptException;
|
import org.elasticsearch.script.GeneralScriptException;
|
||||||
import org.elasticsearch.script.MockScriptEngine;
|
import org.elasticsearch.script.MockScriptEngine;
|
||||||
import org.elasticsearch.script.Script;
|
import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.script.ScriptContext;
|
import org.elasticsearch.script.ScriptContext;
|
||||||
import org.elasticsearch.script.ScriptContextRegistry;
|
import org.elasticsearch.script.ScriptContextRegistry;
|
||||||
import org.elasticsearch.script.ScriptEngine;
|
import org.elasticsearch.script.ScriptEngine;
|
||||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
|
||||||
import org.elasticsearch.script.ScriptException;
|
import org.elasticsearch.script.ScriptException;
|
||||||
import org.elasticsearch.script.ScriptMetaData;
|
import org.elasticsearch.script.ScriptMetaData;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
|
@ -40,6 +38,7 @@ import org.joda.time.DateTimeZone;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -86,10 +85,8 @@ public class ScriptConditionTests extends ESTestCase {
|
||||||
});
|
});
|
||||||
|
|
||||||
ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts);
|
ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts);
|
||||||
|
|
||||||
ScriptEngineRegistry registry = new ScriptEngineRegistry(singleton(engine));
|
|
||||||
ScriptContextRegistry contextRegistry = new ScriptContextRegistry(singleton(new ScriptContext.Plugin("xpack", "watch")));
|
ScriptContextRegistry contextRegistry = new ScriptContextRegistry(singleton(new ScriptContext.Plugin("xpack", "watch")));
|
||||||
scriptService = new ScriptService(Settings.EMPTY, registry, contextRegistry);
|
scriptService = new ScriptService(Settings.EMPTY, Collections.singletonMap(engine.getType(), engine), contextRegistry);
|
||||||
|
|
||||||
ClusterState.Builder clusterState = new ClusterState.Builder(new ClusterName("_name"));
|
ClusterState.Builder clusterState = new ClusterState.Builder(new ClusterName("_name"));
|
||||||
clusterState.metaData(MetaData.builder().putCustom(ScriptMetaData.TYPE, new ScriptMetaData.Builder(null).build()));
|
clusterState.metaData(MetaData.builder().putCustom(ScriptMetaData.TYPE, new ScriptMetaData.Builder(null).build()));
|
||||||
|
|
|
@ -16,15 +16,12 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
import org.elasticsearch.common.xcontent.XContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.env.Environment;
|
|
||||||
import org.elasticsearch.script.ScriptContext;
|
import org.elasticsearch.script.ScriptContext;
|
||||||
import org.elasticsearch.script.ScriptContextRegistry;
|
import org.elasticsearch.script.ScriptContextRegistry;
|
||||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
|
||||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||||
import org.elasticsearch.xpack.common.http.HttpMethod;
|
import org.elasticsearch.xpack.common.http.HttpMethod;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
|
@ -241,11 +238,7 @@ public final class WatcherTestUtils {
|
||||||
.build();
|
.build();
|
||||||
ScriptContextRegistry scriptContextRegistry =
|
ScriptContextRegistry scriptContextRegistry =
|
||||||
new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch")));
|
new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch")));
|
||||||
|
return new ScriptService(settings, Collections.emptyMap(), scriptContextRegistry);
|
||||||
ScriptEngineRegistry scriptEngineRegistry =
|
|
||||||
new ScriptEngineRegistry(Collections.emptyList());
|
|
||||||
|
|
||||||
return new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SearchType getRandomSupportedSearchType() {
|
public static SearchType getRandomSupportedSearchType() {
|
||||||
|
|
|
@ -10,18 +10,15 @@ import com.fasterxml.jackson.core.io.JsonStringEncoder;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.env.Environment;
|
|
||||||
import org.elasticsearch.script.ScriptContext;
|
import org.elasticsearch.script.ScriptContext;
|
||||||
import org.elasticsearch.script.ScriptContextRegistry;
|
import org.elasticsearch.script.ScriptContextRegistry;
|
||||||
import org.elasticsearch.script.ScriptEngineRegistry;
|
import org.elasticsearch.script.ScriptEngine;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.script.mustache.MustacheScriptEngine;
|
import org.elasticsearch.script.mustache.MustacheScriptEngine;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -36,17 +33,16 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
public class WatcherTemplateIT extends ESTestCase {
|
public class WatcherTemplateIT extends ESTestCase {
|
||||||
|
|
||||||
private TextTemplateEngine engine;
|
private TextTemplateEngine textTemplateEngine;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
ScriptContextRegistry registry = new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch")));
|
ScriptContextRegistry registry = new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch")));
|
||||||
|
|
||||||
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(
|
MustacheScriptEngine engine = new MustacheScriptEngine();
|
||||||
Collections.singleton(new MustacheScriptEngine())
|
Map<String, ScriptEngine> engines = Collections.singletonMap(engine.getType(), engine);
|
||||||
);
|
ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, registry);
|
||||||
ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, registry);
|
textTemplateEngine = new TextTemplateEngine(Settings.EMPTY, scriptService);
|
||||||
engine = new TextTemplateEngine(Settings.EMPTY, scriptService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEscaping() throws Exception {
|
public void testEscaping() throws Exception {
|
||||||
|
@ -91,7 +87,7 @@ public class WatcherTemplateIT extends ESTestCase {
|
||||||
|
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
dataMap.put("data", unescaped.toString());
|
dataMap.put("data", unescaped.toString());
|
||||||
String renderedTemplate = engine.render(new TextTemplate(template), dataMap);
|
String renderedTemplate = textTemplateEngine.render(new TextTemplate(template), dataMap);
|
||||||
assertThat(renderedTemplate, notNullValue());
|
assertThat(renderedTemplate, notNullValue());
|
||||||
|
|
||||||
if (contentType == XContentType.JSON) {
|
if (contentType == XContentType.JSON) {
|
||||||
|
@ -116,7 +112,7 @@ public class WatcherTemplateIT extends ESTestCase {
|
||||||
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}" + "}}, \"negative_boost\": {{boost_val}} } }}";
|
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}" + "}}, \"negative_boost\": {{boost_val}} } }}";
|
||||||
Map<String, Object> vars = new HashMap<>();
|
Map<String, Object> vars = new HashMap<>();
|
||||||
vars.put("boost_val", "0.3");
|
vars.put("boost_val", "0.3");
|
||||||
String result = engine.render(new TextTemplate(template), vars);
|
String result = textTemplateEngine.render(new TextTemplate(template), vars);
|
||||||
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
||||||
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.3 } }}",
|
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.3 } }}",
|
||||||
result);
|
result);
|
||||||
|
@ -127,7 +123,7 @@ public class WatcherTemplateIT extends ESTestCase {
|
||||||
Map<String, Object> vars = new HashMap<>();
|
Map<String, Object> vars = new HashMap<>();
|
||||||
vars.put("boost_val", "0.3");
|
vars.put("boost_val", "0.3");
|
||||||
vars.put("body_val", "\"quick brown\"");
|
vars.put("body_val", "\"quick brown\"");
|
||||||
String result = engine.render(new TextTemplate(template), vars);
|
String result = textTemplateEngine.render(new TextTemplate(template), vars);
|
||||||
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
|
||||||
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"\\\"quick brown\\\"\"}}}, \"negative_boost\": 0.3 } }}",
|
+ "\"negative\": {\"term\": {\"body\": {\"value\": \"\\\"quick brown\\\"\"}}}, \"negative_boost\": 0.3 } }}",
|
||||||
result);
|
result);
|
||||||
|
@ -151,7 +147,7 @@ public class WatcherTemplateIT extends ESTestCase {
|
||||||
|
|
||||||
vars.put("test_var1", var1Writer.toString());
|
vars.put("test_var1", var1Writer.toString());
|
||||||
vars.put("test_var2", var2Writer.toString());
|
vars.put("test_var2", var2Writer.toString());
|
||||||
String s1 = engine.render(new TextTemplate(template), vars);
|
String s1 = textTemplateEngine.render(new TextTemplate(template), vars);
|
||||||
String s2 = prefix + " " + var1Writer.toString() + " " + var2Writer.toString();
|
String s2 = prefix + " " + var1Writer.toString() + " " + var2Writer.toString();
|
||||||
assertThat(s1, equalTo(s2));
|
assertThat(s1, equalTo(s2));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue