Merge pull request elastic/elasticsearch#3902 from jdconrad/stype
Refactor ScriptType to be a top-level class. Original commit: elastic/x-pack-elasticsearch@22862a3727
This commit is contained in:
commit
54a71289cc
|
@ -15,7 +15,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.rest.RestUtils;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
|
||||
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
|
||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||
|
@ -459,7 +459,7 @@ public class HttpRequestTemplate implements ToXContent {
|
|||
}
|
||||
|
||||
public Builder body(XContentBuilder content) throws IOException {
|
||||
return body(new TextTemplate(content.string(), content.contentType(), ScriptService.ScriptType.INLINE, null));
|
||||
return body(new TextTemplate(content.string(), content.contentType(), ScriptType.INLINE, null));
|
||||
}
|
||||
|
||||
public Builder connectionTimeout(TimeValue timeout) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchRequestParsers;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||
|
@ -54,7 +54,7 @@ public class WatcherSearchTemplateRequest implements ToXContent {
|
|||
this.indicesOptions = indicesOptions;
|
||||
// Here we convert a watch search request body into an inline search template,
|
||||
// this way if any Watcher related context variables are used, they will get resolved.
|
||||
this.template = new Script(searchSource.utf8ToString(), ScriptService.ScriptType.INLINE, TextTemplate.DEFAULT_TEMPLATE_LANG, null);
|
||||
this.template = new Script(searchSource.utf8ToString(), ScriptType.INLINE, TextTemplate.DEFAULT_TEMPLATE_LANG, null);
|
||||
this.searchSource = null;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class WatcherSearchTemplateRequest implements ToXContent {
|
|||
if (template != null) {
|
||||
return template;
|
||||
} else {
|
||||
return new Script(searchSource.utf8ToString(), ScriptService.ScriptType.INLINE, TextTemplate.DEFAULT_TEMPLATE_LANG, null);
|
||||
return new Script(searchSource.utf8ToString(), ScriptType.INLINE, TextTemplate.DEFAULT_TEMPLATE_LANG, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SleepScriptEngine implements ScriptEngineService {
|
|||
}
|
||||
|
||||
public static Script sleepScript(long millis) {
|
||||
return new Script("", ScriptService.ScriptType.INLINE, "sleep", Collections.singletonMap("millis", millis));
|
||||
return new Script("", ScriptType.INLINE, "sleep", Collections.singletonMap("millis", millis));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.watcher.Watcher;
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.elasticsearch.script.AbstractSearchScript;
|
|||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.NativeScriptFactory;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.graph.action.GraphExploreAction;
|
||||
|
|
|
@ -73,6 +73,7 @@ import org.elasticsearch.script.ExecutableScript;
|
|||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.aggregations.LeafBucketCollector;
|
||||
import org.elasticsearch.xpack.security.authz.accesscontrol.DocumentSubsetReader.DocumentSubsetDirectoryReader;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
|
@ -591,7 +592,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
|
|||
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
String query = new TermQueryBuilder("field", "{{_user.username}}").toXContent(builder, ToXContent.EMPTY_PARAMS).string();
|
||||
Script script = new Script(query, ScriptService.ScriptType.INLINE, null, Collections.singletonMap("custom", "value"));
|
||||
Script script = new Script(query, ScriptType.INLINE, null, Collections.singletonMap("custom", "value"));
|
||||
builder = jsonBuilder().startObject().field("template");
|
||||
script.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
BytesReference querySource = builder.endObject().bytes();
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.script.ScriptEngineRegistry;
|
|||
import org.elasticsearch.script.ScriptEngineService;
|
||||
import org.elasticsearch.script.ScriptException;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.script.ScriptSettings;
|
||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
import org.elasticsearch.xpack.watcher.WatcherService;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||
|
@ -348,7 +348,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
}
|
||||
|
||||
public void testWatchExecutionDuration() throws Exception {
|
||||
Script script = new Script("sleep", ScriptService.ScriptType.INLINE, null, singletonMap("millis", 100L));
|
||||
Script script = new Script("sleep", ScriptType.INLINE, null, singletonMap("millis", 100L));
|
||||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
|
@ -364,7 +364,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
}
|
||||
|
||||
public void testForceDeletionOfLongRunningWatch() throws Exception {
|
||||
Script script = new Script("sleep", ScriptService.ScriptType.INLINE, null, singletonMap("millis", 10000L));
|
||||
Script script = new Script("sleep", ScriptType.INLINE, null, singletonMap("millis", 10000L));
|
||||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
|
@ -265,7 +265,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
* @return Never {@code null}
|
||||
*/
|
||||
private static Condition mockScriptCondition(String inlineScript) {
|
||||
Script script = new Script(inlineScript, ScriptService.ScriptType.INLINE, MockScriptPlugin.NAME, null, null);
|
||||
Script script = new Script(inlineScript, ScriptType.INLINE, MockScriptPlugin.NAME, null, null);
|
||||
return new ScriptCondition(script);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
|
@ -32,7 +31,8 @@ import java.util.Map;
|
|||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.script.ScriptService.ScriptType;
|
||||
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import static org.elasticsearch.xpack.watcher.input.search.ExecutableSearchInput.DEFAULT_SEARCH_TYPE;
|
||||
import static org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils.formatDate;
|
||||
import static org.elasticsearch.xpack.watcher.support.WatcherUtils.flattenModel;
|
||||
|
@ -107,7 +107,7 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
String text = randomAsciiOfLengthBetween(1, 5);
|
||||
ScriptService.ScriptType scriptType = randomFrom(ScriptService.ScriptType.values());
|
||||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
expectedTemplate = new Script(text, scriptType, "mustache", params);
|
||||
request = new WatcherSearchTemplateRequest(expectedIndices, expectedTypes, expectedSearchType,
|
||||
expectedIndicesOptions, expectedTemplate);
|
||||
|
@ -206,7 +206,7 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
String text = randomAsciiOfLengthBetween(1, 5);
|
||||
ScriptService.ScriptType scriptType = randomFrom(ScriptService.ScriptType.values());
|
||||
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||
template = new Script(text, scriptType, "mustache", params);
|
||||
builder.field("template", template);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.action.search.SearchType;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
|
@ -256,7 +256,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(jsonBuilder().startObject().field("template").value(searchSourceBuilder).endObject().bytes())
|
||||
.get());
|
||||
|
||||
Script template = new Script("my-template", ScriptService.ScriptType.STORED, "mustache", null);
|
||||
Script template = new Script("my-template", ScriptType.STORED, "mustache", null);
|
||||
WatcherSearchTemplateRequest searchRequest = new WatcherSearchTemplateRequest(new String[]{"events"}, new String[0],
|
||||
SearchType.DEFAULT, WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, template);
|
||||
testConditionSearch(searchRequest);
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.elasticsearch.script.MockMustacheScriptEngine;
|
|||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchRequestParsers;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -192,7 +193,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||
builder.field("search_type", searchType.name());
|
||||
}
|
||||
if (templateName != null) {
|
||||
TextTemplate template = new TextTemplate(templateName, null, ScriptService.ScriptType.FILE, null);
|
||||
TextTemplate template = new TextTemplate(templateName, null, ScriptType.FILE, null);
|
||||
builder.field("template", template);
|
||||
}
|
||||
|
||||
|
@ -229,7 +230,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||
}
|
||||
if (templateName != null) {
|
||||
assertThat(executable.transform().getRequest().getTemplate(),
|
||||
equalTo(new Script("template1", ScriptService.ScriptType.FILE, "mustache", null)));
|
||||
equalTo(new Script("template1", ScriptType.FILE, "mustache", null)));
|
||||
}
|
||||
assertThat(executable.transform().getRequest().getSearchSource().utf8ToString(), equalTo("{\"query\":{\"match_all\":{}}}"));
|
||||
assertThat(executable.transform().getTimeout(), equalTo(readTimeout));
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.env.Environment;
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -128,10 +128,10 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setScriptLang("painless")
|
||||
.setSource(new BytesArray("{\"script\" : \"['key3' : ctx.payload.key1 + ctx.payload.key2]\"}"))
|
||||
.get());
|
||||
script = new Script("my-script", ScriptService.ScriptType.STORED, "painless", null);
|
||||
script = new Script("my-script", ScriptType.STORED, "painless", null);
|
||||
} else {
|
||||
logger.info("testing script transform with a file script");
|
||||
script = new Script("my-script", ScriptService.ScriptType.FILE, "painless", null);
|
||||
script = new Script("my-script", ScriptType.FILE, "painless", null);
|
||||
}
|
||||
|
||||
// put a watch that has watch level transform:
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.script.ExecutableScript;
|
|||
import org.elasticsearch.script.GeneralScriptException;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
|
Loading…
Reference in New Issue