Migrated from indexed scripts to store scripts
Original commit: elastic/x-pack-elasticsearch@a0218f1c9e
This commit is contained in:
parent
276d5fbbca
commit
b9515357fa
|
@ -6,6 +6,9 @@
|
|||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -19,6 +22,7 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.junit.Ignore;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
@ -43,8 +47,11 @@ public final class MessyTestUtils {
|
|||
);
|
||||
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,
|
||||
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings));
|
||||
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings),
|
||||
clusterService);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
case FILE:
|
||||
script = "nonExisting_script";
|
||||
break;
|
||||
|
@ -212,7 +212,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
case FILE:
|
||||
builder.field("file", script);
|
||||
break;
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
builder.field("id", script);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.messy.tests;
|
|||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -77,7 +78,10 @@ public class TransformIT extends AbstractWatcherIntegrationTestCase {
|
|||
script = Script.inline("return [key3 : ctx.payload.key1 + ctx.payload.key2]").lang("groovy").build();
|
||||
} else if (randomBoolean()) {
|
||||
logger.info("testing script transform with an indexed script");
|
||||
client().preparePutIndexedScript("groovy", "_id", "{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}")
|
||||
client().admin().cluster().preparePutStoredScript()
|
||||
.setId("_id")
|
||||
.setScriptLang("groovy")
|
||||
.setSource(new BytesArray("{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}"))
|
||||
.get();
|
||||
script = Script.indexed("_id").lang("groovy").build();
|
||||
} else {
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
@ -192,14 +193,17 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
public void testSearchIndexedTemplate() throws Exception {
|
||||
WatchExecutionContext ctx = createContext();
|
||||
|
||||
PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache","test-template",
|
||||
TEMPLATE_QUERY).request();
|
||||
assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true));
|
||||
PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript()
|
||||
.setId("test-template")
|
||||
.setScriptLang("mustache")
|
||||
.setSource(new BytesArray(TEMPLATE_QUERY))
|
||||
.request();
|
||||
assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true));
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("seconds_param", "30s");
|
||||
|
||||
Template template = new Template("test-template", ScriptType.INDEXED, null, null, params);
|
||||
Template template = new Template("test-template", ScriptType.STORED, null, null, params);
|
||||
|
||||
jsonBuilder().value(TextTemplate.indexed("test-template").params(params).build()).bytes();
|
||||
SearchRequest request = client().prepareSearch().setSearchType(ExecutableSearchInput.DEFAULT_SEARCH_TYPE)
|
||||
|
@ -209,7 +213,7 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
Template resultTemplate = executedResult.executedRequest().template();
|
||||
assertThat(resultTemplate, notNullValue());
|
||||
assertThat(resultTemplate.getScript(), equalTo("test-template"));
|
||||
assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED));
|
||||
assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED));
|
||||
}
|
||||
|
||||
public void testSearchOnDiskTemplate() throws Exception {
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.common.Base64;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -388,8 +389,12 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
"{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," +
|
||||
"\"include_lower\":true,\"include_upper\":true}}}]}}}";
|
||||
|
||||
PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache", "test-script", templateQuery).request();
|
||||
assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true));
|
||||
PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript()
|
||||
.setId("mustache")
|
||||
.setScriptLang("test-script")
|
||||
.setSource(new BytesArray(templateQuery))
|
||||
.request();
|
||||
assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true));
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("seconds_param", "30s");
|
||||
|
@ -397,7 +402,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
BytesReference templateSource = jsonBuilder()
|
||||
.value(TextTemplate.indexed("test-script").params(params).build())
|
||||
.bytes();
|
||||
Template template = new Template("test-script", ScriptType.INDEXED, null, null, null);
|
||||
Template template = new Template("test-script", ScriptType.STORED, null, null, null);
|
||||
|
||||
SearchRequest request = client()
|
||||
.prepareSearch()
|
||||
|
@ -411,7 +416,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
Template resultTemplate = result.executedRequest().template();
|
||||
assertThat(resultTemplate, notNullValue());
|
||||
assertThat(resultTemplate.getScript(), equalTo("test-script"));
|
||||
assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED));
|
||||
assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED));
|
||||
}
|
||||
|
||||
public void testSearchOnDiskTemplate() throws Exception {
|
||||
|
@ -466,7 +471,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
new ExecutableAlwaysCondition(logger),
|
||||
null,
|
||||
null,
|
||||
new ExecutableActions(new ArrayList<ActionWrapper>()),
|
||||
new ExecutableActions(new ArrayList<>()),
|
||||
null,
|
||||
new WatchStatus( new DateTime(40000, UTC), emptyMap())),
|
||||
new DateTime(60000, UTC),
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.indices.TermsLookup;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -72,7 +73,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
|
|||
public void loadData() {
|
||||
index("data", "a", "1", "{ \"name\": \"John\", \"token\": \"token1\" }");
|
||||
index("tokens", "tokens", "1", "{ \"group\": \"1\", \"tokens\": [\"token1\", \"token2\"] }");
|
||||
client().preparePutIndexedScript().setOpType(IndexRequest.OpType.CREATE).setSource("{\n" +
|
||||
client().admin().cluster().preparePutStoredScript().setSource(new BytesArray("{\n" +
|
||||
"\"template\": {\n" +
|
||||
" \"query\": {\n" +
|
||||
" \"exists\": {\n" +
|
||||
|
@ -80,7 +81,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}")
|
||||
"}"))
|
||||
.setScriptLang("mustache")
|
||||
.setId("testTemplate")
|
||||
.execute().actionGet();
|
||||
|
@ -110,7 +111,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
|
|||
|
||||
public void testThatScriptServiceDoesntLeakData() {
|
||||
SearchResponse response = client().prepareSearch("data").setTypes("a")
|
||||
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null,
|
||||
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null,
|
||||
Collections.<String, Object>singletonMap("name", "token")))
|
||||
.execute().actionGet();
|
||||
assertThat(response.isTimedOut(), is(false));
|
||||
|
@ -121,7 +122,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase {
|
|||
response = client().filterWithHeader(Collections.singletonMap("Authorization", basicAuthHeaderValue(READ_ONE_IDX_USER,
|
||||
new SecuredString("changeme".toCharArray()))))
|
||||
.prepareSearch("data").setTypes("a")
|
||||
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null,
|
||||
.setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null,
|
||||
Collections.<String, Object>singletonMap("name", "token")))
|
||||
.execute().actionGet();
|
||||
fail("search phase exception should have been thrown! response was:\n" + response.toString());
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
package org.elasticsearch.smoketest;
|
||||
|
||||
import com.fasterxml.jackson.core.io.JsonStringEncoder;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
@ -59,7 +62,9 @@ public class WatcherTemplateTests extends ESTestCase {
|
|||
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry);
|
||||
ScriptService scriptService = new ScriptService(setting, environment, engines, resourceWatcherService, scriptEngineRegistry,
|
||||
registry, scriptSettings);
|
||||
engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService));
|
||||
ClusterService clusterService = Mockito.mock(ClusterService.class);
|
||||
Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build());
|
||||
engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService, clusterService));
|
||||
}
|
||||
|
||||
public void testEscaping() throws Exception {
|
||||
|
|
|
@ -62,7 +62,7 @@ indices:data/read/mpercolate
|
|||
indices:data/read/msearch
|
||||
indices:data/read/mtv
|
||||
indices:data/read/percolate
|
||||
indices:data/read/script/get
|
||||
cluster:admin/script/get
|
||||
indices:data/read/scroll
|
||||
indices:data/read/scroll/clear
|
||||
indices:data/read/search
|
||||
|
@ -70,8 +70,8 @@ indices:data/read/tv
|
|||
indices:data/write/bulk
|
||||
indices:data/write/delete
|
||||
indices:data/write/index
|
||||
indices:data/write/script/delete
|
||||
indices:data/write/script/put
|
||||
cluster:admin/script/delete
|
||||
cluster:admin/script/put
|
||||
indices:data/write/update
|
||||
cluster:monitor/xpack/info
|
||||
cluster:monitor/xpack/license/get
|
||||
|
|
|
@ -94,7 +94,7 @@ public class Script implements ToXContent {
|
|||
builder.field(Field.FILE.getPreferredName(), script);
|
||||
break;
|
||||
default:
|
||||
assert type == ScriptType.INDEXED : "script type [" + type + "] is not supported";
|
||||
assert type == ScriptType.STORED : "script type [" + type + "] is not supported";
|
||||
builder.field(Field.ID.getPreferredName(), script);
|
||||
}
|
||||
if (lang != null) {
|
||||
|
@ -141,7 +141,7 @@ public class Script implements ToXContent {
|
|||
token);
|
||||
}
|
||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ID)) {
|
||||
type = ScriptType.INDEXED;
|
||||
type = ScriptType.STORED;
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
script = parser.text();
|
||||
} else {
|
||||
|
@ -240,7 +240,7 @@ public class Script implements ToXContent {
|
|||
public static class Indexed extends Builder<Indexed> {
|
||||
|
||||
public Indexed(String id) {
|
||||
super(id, ScriptType.INDEXED);
|
||||
super(id, ScriptType.STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.init.proxy;
|
||||
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
|
@ -27,14 +28,16 @@ public class ScriptServiceProxy implements LazyInitializable {
|
|||
|
||||
private ScriptService service;
|
||||
private SecurityContext securityContext;
|
||||
private ClusterService clusterService;
|
||||
|
||||
/**
|
||||
* Creates a proxy to the given script service (can be used for testing)
|
||||
*/
|
||||
public static ScriptServiceProxy of(ScriptService service) {
|
||||
public static ScriptServiceProxy of(ScriptService service, ClusterService clusterService) {
|
||||
ScriptServiceProxy proxy = new ScriptServiceProxy();
|
||||
proxy.service = service;
|
||||
proxy.securityContext = SecurityContext.Insecure.INSTANCE;
|
||||
proxy.clusterService = clusterService;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
@ -42,16 +45,16 @@ public class ScriptServiceProxy implements LazyInitializable {
|
|||
public void init(Injector injector) {
|
||||
this.service = injector.getInstance(ScriptService.class);
|
||||
this.securityContext = injector.getInstance(SecurityContext.class);
|
||||
this.clusterService = injector.getInstance(ClusterService.class);
|
||||
}
|
||||
|
||||
public CompiledScript compile(Script script) {
|
||||
return securityContext.executeAs(XPackUser.INSTANCE, () ->
|
||||
compile(new org.elasticsearch.script.Script(script.script(), script.type(), script.lang(), script.params()), emptyMap()));
|
||||
return compile(new org.elasticsearch.script.Script(script.script(), script.type(), script.lang(), script.params()), emptyMap());
|
||||
}
|
||||
|
||||
public CompiledScript compile(org.elasticsearch.script.Script script, Map<String, String> compileParams) {
|
||||
return securityContext.executeAs(XPackUser.INSTANCE, () ->
|
||||
service.compile(script, WatcherScriptContext.CTX, compileParams));
|
||||
service.compile(script, WatcherScriptContext.CTX, compileParams, clusterService.state()));
|
||||
}
|
||||
|
||||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
|
@ -59,12 +62,6 @@ public class ScriptServiceProxy implements LazyInitializable {
|
|||
service.executable(compiledScript, vars));
|
||||
}
|
||||
|
||||
|
||||
public ExecutableScript executable(org.elasticsearch.script.Script script) {
|
||||
return securityContext.executeAs(XPackUser.INSTANCE, () ->
|
||||
service.executable(script, WatcherScriptContext.CTX, emptyMap()));
|
||||
}
|
||||
|
||||
public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("xpack", "watch");
|
||||
|
||||
private static class WatcherScriptContext implements ScriptContext {
|
||||
|
|
|
@ -99,8 +99,8 @@ public class TextTemplate implements ToXContent {
|
|||
case FILE:
|
||||
builder.field(Field.FILE.getPreferredName(), template);
|
||||
break;
|
||||
default: // INDEXED
|
||||
assert type == ScriptType.INDEXED : "template type [" + type + "] is not supported";
|
||||
default: // STORED
|
||||
assert type == ScriptType.STORED : "template type [" + type + "] is not supported";
|
||||
builder.field(Field.ID.getPreferredName(), template);
|
||||
}
|
||||
if (this.params != null) {
|
||||
|
@ -145,7 +145,7 @@ public class TextTemplate implements ToXContent {
|
|||
currentFieldName, token);
|
||||
}
|
||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ID)) {
|
||||
type = ScriptType.INDEXED;
|
||||
type = ScriptType.STORED;
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
template = parser.text();
|
||||
} else {
|
||||
|
@ -242,7 +242,7 @@ public class TextTemplate implements ToXContent {
|
|||
public static class Indexed extends Builder<Indexed> {
|
||||
|
||||
public Indexed(String id) {
|
||||
super(id, ScriptType.INDEXED);
|
||||
super(id, ScriptType.STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -124,7 +124,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
case FILE:
|
||||
script = "nonExisting_script";
|
||||
break;
|
||||
|
@ -212,7 +212,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
case FILE:
|
||||
builder.field("file", script);
|
||||
break;
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
builder.field("id", script);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -125,7 +125,7 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
Template template = randomFrom(
|
||||
new Template(text, ScriptType.INLINE, null, null, params),
|
||||
new Template(text, ScriptType.FILE, null, null, params),
|
||||
new Template(text, ScriptType.INDEXED, null, null, params)
|
||||
new Template(text, ScriptType.STORED, null, null, params)
|
||||
);
|
||||
expectedRequest.template(template);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class TextTemplateTests extends ESTestCase {
|
|||
case FILE:
|
||||
builder.field("file", template.getTemplate());
|
||||
break;
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
builder.field("id", template.getTemplate());
|
||||
}
|
||||
builder.field("params", template.getParams());
|
||||
|
@ -173,7 +173,7 @@ public class TextTemplateTests extends ESTestCase {
|
|||
|
||||
public void testParserInvalidMissingText() throws Exception {
|
||||
XContentBuilder builder = jsonBuilder().startObject()
|
||||
.field("type", ScriptType.INDEXED)
|
||||
.field("type", ScriptType.STORED)
|
||||
.startObject("params").endObject()
|
||||
.endObject();
|
||||
BytesReference bytes = builder.bytes();
|
||||
|
@ -195,7 +195,7 @@ public class TextTemplateTests extends ESTestCase {
|
|||
switch (type) {
|
||||
case INLINE: return TextTemplate.inline(text);
|
||||
case FILE: return TextTemplate.file(text);
|
||||
case INDEXED: return TextTemplate.indexed(text);
|
||||
case STORED: return TextTemplate.indexed(text);
|
||||
default:
|
||||
throw illegalArgument("unsupported script type [{}]", type);
|
||||
}
|
||||
|
|
|
@ -668,7 +668,8 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
|
|||
"test:\n" + // a user for the test infra.
|
||||
" cluster: [ 'cluster:monitor/nodes/info', 'cluster:monitor/state', 'cluster:monitor/health', 'cluster:monitor/stats'," +
|
||||
" 'cluster:admin/settings/update', 'cluster:admin/repository/delete', 'cluster:monitor/nodes/liveness'," +
|
||||
" 'indices:admin/template/get', 'indices:admin/template/put', 'indices:admin/template/delete' ]\n" +
|
||||
" 'indices:admin/template/get', 'indices:admin/template/put', 'indices:admin/template/delete'," +
|
||||
" 'cluster:admin/script/put' ]\n" +
|
||||
" indices:\n" +
|
||||
" - names: '*'\n" +
|
||||
" privileges: [ all ]\n" +
|
||||
|
|
|
@ -8,6 +8,9 @@ package org.elasticsearch.watcher.test;
|
|||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -67,6 +70,7 @@ import org.elasticsearch.watcher.watch.Watch;
|
|||
import org.elasticsearch.watcher.watch.WatchStatus;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.joda.time.DateTime;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
import java.io.IOException;
|
||||
|
@ -248,8 +252,11 @@ public final class WatcherTestUtils {
|
|||
ScriptEngineRegistry scriptEngineRegistry =
|
||||
new ScriptEngineRegistry(Collections.emptyList());
|
||||
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(),
|
||||
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings));
|
||||
new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings),
|
||||
clusterService);
|
||||
}
|
||||
|
||||
public static SearchType getRandomSupportedSearchType() {
|
||||
|
|
|
@ -257,14 +257,13 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
|
||||
public void testConditionSearchWithIndexedTemplate() throws Exception {
|
||||
SearchSourceBuilder searchSourceBuilder = searchSource().query(matchQuery("level", "a"));
|
||||
client().preparePutIndexedScript()
|
||||
client().admin().cluster().preparePutStoredScript()
|
||||
.setScriptLang("mustache")
|
||||
.setId("my-template")
|
||||
.setSource(jsonBuilder().startObject().field("template").value(searchSourceBuilder).endObject())
|
||||
.setSource(jsonBuilder().startObject().field("template").value(searchSourceBuilder).endObject().bytes())
|
||||
.get();
|
||||
refresh();
|
||||
|
||||
Template template = new Template("my-template", ScriptType.INDEXED, null, null, null);
|
||||
Template template = new Template("my-template", ScriptType.STORED, null, null, null);
|
||||
SearchRequest searchRequest = newInputSearchRequest("events");
|
||||
// TODO (2.0 upgrade): move back to BytesReference instead of coverting to a string
|
||||
searchRequest.template(template);
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.watcher.transform;
|
|||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -68,7 +69,10 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
script = Script.inline("return [key3 : ctx.payload.key1 + ctx.payload.key2]").lang("groovy").build();
|
||||
} else if (randomBoolean()) {
|
||||
logger.info("testing script transform with an indexed script");
|
||||
client().preparePutIndexedScript("groovy", "_id", "{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}")
|
||||
client().admin().cluster().preparePutStoredScript()
|
||||
.setId("id")
|
||||
.setScriptLang("groovy")
|
||||
.setSource(new BytesArray("{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}"))
|
||||
.get();
|
||||
script = Script.indexed("_id").lang("groovy").build();
|
||||
} else {
|
||||
|
|
|
@ -174,7 +174,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
case INDEXED:
|
||||
case STORED:
|
||||
case FILE:
|
||||
script = "nonExisting_script";
|
||||
break;
|
||||
|
@ -227,7 +227,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||
switch (type) {
|
||||
case INLINE: return Script.inline(script);
|
||||
case FILE: return Script.file(script);
|
||||
case INDEXED: return Script.indexed(script);
|
||||
case STORED: return Script.indexed(script);
|
||||
default:
|
||||
throw illegalArgument("unsupported script type [{}]", type);
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||
switch (type) {
|
||||
case INLINE: return "inline";
|
||||
case FILE: return "file";
|
||||
case INDEXED: return "id";
|
||||
case STORED: return "id";
|
||||
default:
|
||||
throw illegalArgument("unsupported script type [{}]", type);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue