From 1dc839bd983dc4fa3b4d51a0757429c2bcbe3da6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 22 Nov 2016 22:45:15 -0800 Subject: [PATCH] Remove groovy scripting language (elastic/elasticsearch#4162) This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#21607 Original commit: elastic/x-pack-elasticsearch@125843e814ca1ffdfb304fd7d9b1e0edcc134e11 --- .../elasticsearch/xpack/watcher/Watcher.java | 12 +- .../xpack/watcher/actions/ActionRegistry.java | 4 +- .../xpack/watcher/actions/ActionWrapper.java | 6 +- .../watcher/condition/ConditionFactory.java | 6 +- .../watcher/condition/ConditionRegistry.java | 7 +- .../watcher/condition/ScriptCondition.java | 10 +- .../xpack/watcher/input/InputFactory.java | 9 +- .../xpack/watcher/input/InputRegistry.java | 15 +- .../input/chain/ChainInputFactory.java | 2 +- .../watcher/input/http/HttpInputFactory.java | 2 +- .../watcher/input/none/NoneInputFactory.java | 2 +- .../watcher/input/search/SearchInput.java | 4 +- .../input/search/SearchInputFactory.java | 5 +- .../input/simple/SimpleInputFactory.java | 2 +- .../search/WatcherSearchTemplateRequest.java | 16 -- .../watcher/transform/TransformFactory.java | 9 +- .../watcher/transform/TransformRegistry.java | 13 +- .../transform/chain/ChainTransform.java | 5 +- .../chain/ChainTransformFactory.java | 4 +- .../transform/script/ScriptTransform.java | 10 +- .../script/ScriptTransformFactory.java | 5 +- .../transform/search/SearchTransform.java | 8 +- .../search/SearchTransformFactory.java | 5 +- .../xpack/watcher/watch/Watch.java | 8 +- .../condition/ScriptConditionTests.java | 13 +- .../watcher/input/chain/ChainInputTests.java | 6 +- .../watcher/input/http/HttpInputTests.java | 4 +- .../input/simple/SimpleInputTests.java | 4 +- .../watcher/support/WatcherUtilsTests.java | 6 +- .../WatcherSearchTemplateRequestTests.java | 4 +- .../test/integration/SearchInputTests.java | 2 +- .../integration/SearchTransformTests.java | 2 +- .../transform/chain/ChainTransformTests.java | 6 +- .../script/ScriptTransformTests.java | 8 +- .../xpack/watcher/watch/WatchTests.java | 16 +- .../build.gradle | 15 -- .../smoketest/WatcherRestTestCase.java | 42 ---- .../smoketest/WatcherWithGroovyIT.java | 17 -- .../test/watcher_groovy/10_basic.yaml | 89 ------- .../test/watcher_groovy/20_minimal_body.yaml | 48 ---- .../test/watcher_groovy/30_inline_watch.yaml | 74 ------ .../test/watcher_groovy/40_index_action.yaml | 238 ------------------ .../watcher_groovy/50_script_condition.yaml | 141 ----------- 43 files changed, 86 insertions(+), 818 deletions(-) delete mode 100644 qa/smoke-test-watcher-with-groovy/build.gradle delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherRestTestCase.java delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherWithGroovyIT.java delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/10_basic.yaml delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/20_minimal_body.yaml delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/30_inline_watch.yaml delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/40_index_action.yaml delete mode 100644 qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/50_script_condition.yaml diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 28946874034..349ad06991d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -216,13 +216,11 @@ public class Watcher implements ActionPlugin, ScriptPlugin { } final Map parsers = new HashMap<>(); - parsers.put(AlwaysCondition.TYPE, (c, id, p, upgrade) -> AlwaysCondition.parse(id, p)); - parsers.put(NeverCondition.TYPE, (c, id, p, upgrade) -> NeverCondition.parse(id, p)); - parsers.put(ArrayCompareCondition.TYPE, (c, id, p, upgrade) -> ArrayCompareCondition.parse(c, id, p)); - parsers.put(CompareCondition.TYPE, (c, id, p, upgrade) -> CompareCondition.parse(c, id, p)); - String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings); - parsers.put(ScriptCondition.TYPE, (c, id, p, upgrade) -> ScriptCondition.parse(scriptService, id, p, upgrade, - defaultLegacyScriptLanguage)); + parsers.put(AlwaysCondition.TYPE, (c, id, p) -> AlwaysCondition.parse(id, p)); + parsers.put(NeverCondition.TYPE, (c, id, p) -> NeverCondition.parse(id, p)); + parsers.put(ArrayCompareCondition.TYPE, (c, id, p) -> ArrayCompareCondition.parse(c, id, p)); + parsers.put(CompareCondition.TYPE, (c, id, p) -> CompareCondition.parse(c, id, p)); + parsers.put(ScriptCondition.TYPE, (c, id, p) -> ScriptCondition.parse(scriptService, id, p)); final ConditionRegistry conditionRegistry = new ConditionRegistry(Collections.unmodifiableMap(parsers), clock); final Map transformFactories = new HashMap<>(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java index 0aa8801d2dd..2312a49b7ed 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java @@ -41,7 +41,7 @@ public class ActionRegistry { return parsers.get(type); } - public List parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException { + public List parseActions(String watchId, XContentParser parser) throws IOException { if (parser.currentToken() != XContentParser.Token.START_OBJECT) { throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead", watchId, parser.currentToken()); @@ -58,7 +58,7 @@ public class ActionRegistry { watchId); } } else if (token == XContentParser.Token.START_OBJECT && id != null) { - actions.add(ActionWrapper.parse(watchId, id, parser, this, clock, licenseState, upgradeActionSource)); + actions.add(ActionWrapper.parse(watchId, id, parser, this, clock, licenseState)); } } return actions; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionWrapper.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionWrapper.java index d6194bfe60f..a7c23ba0d65 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionWrapper.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionWrapper.java @@ -194,7 +194,7 @@ public class ActionWrapper implements ToXContent { } static ActionWrapper parse(String watchId, String actionId, XContentParser parser, ActionRegistry actionRegistry, Clock clock, - XPackLicenseState licenseState, boolean upgradeActionSource) throws IOException { + XPackLicenseState licenseState) throws IOException { assert parser.currentToken() == XContentParser.Token.START_OBJECT; @@ -210,9 +210,9 @@ public class ActionWrapper implements ToXContent { currentFieldName = parser.currentName(); } else { if (ParseFieldMatcher.STRICT.match(currentFieldName, Watch.Field.CONDITION)) { - condition = actionRegistry.getConditionRegistry().parseExecutable(watchId, parser, upgradeActionSource); + condition = actionRegistry.getConditionRegistry().parseExecutable(watchId, parser); } else if (ParseFieldMatcher.STRICT.match(currentFieldName, Transform.Field.TRANSFORM)) { - transform = actionRegistry.getTransformRegistry().parse(watchId, parser, upgradeActionSource); + transform = actionRegistry.getTransformRegistry().parse(watchId, parser); } else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD)) { throttlePeriod = timeValueMillis(parser.longValue()); } else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD_HUMAN)) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionFactory.java index 3e30b50800b..fbb41378d94 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionFactory.java @@ -17,11 +17,9 @@ public interface ConditionFactory { /** * Parses the given xcontent and creates a concrete condition - * @param watchId The id of the watch + * @param watchId The id of the watch * @param parser The parsing that contains the condition content - * @param upgradeConditionSource Whether to upgrade the source related to condition if in legacy format - * Note: depending on the version, only conditions implementations that have a */ - Condition parse(Clock clock, String watchId, XContentParser parser, boolean upgradeConditionSource) throws IOException; + Condition parse(Clock clock, String watchId, XContentParser parser) throws IOException; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java index db114c631ef..bf55c051f7a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java @@ -34,11 +34,8 @@ public class ConditionRegistry { * * @param watchId The id of the watch * @param parser The parsing that contains the condition content - * @param upgradeConditionSource Whether to upgrade the source related to condition if in legacy format - * Note: depending on the version, only conditions implementations that have a - * known legacy format will support this option, otherwise this is a noop. */ - public Condition parseExecutable(String watchId, XContentParser parser, boolean upgradeConditionSource) throws IOException { + public Condition parseExecutable(String watchId, XContentParser parser) throws IOException { Condition condition = null; ConditionFactory factory; @@ -56,7 +53,7 @@ public class ConditionRegistry { throw new ElasticsearchParseException("could not parse condition for watch [{}]. unknown condition type [{}]", watchId, type); } - condition = factory.parse(clock, watchId, parser, upgradeConditionSource); + condition = factory.parse(clock, watchId, parser); } } if (condition == null) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ScriptCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ScriptCondition.java index c1fb3931cb0..cf9036d9706 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ScriptCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ScriptCondition.java @@ -53,15 +53,9 @@ public final class ScriptCondition extends Condition { return script; } - public static ScriptCondition parse(ScriptService scriptService, String watchId, XContentParser parser, boolean upgradeConditionSource, - String defaultLegacyScriptLanguage) throws IOException { + public static ScriptCondition parse(ScriptService scriptService, String watchId, XContentParser parser) throws IOException { try { - Script script; - if (upgradeConditionSource) { - script = Script.parse(parser, ParseFieldMatcher.STRICT, defaultLegacyScriptLanguage); - } else { - script = Script.parse(parser, ParseFieldMatcher.STRICT); - } + Script script = Script.parse(parser, ParseFieldMatcher.STRICT); return new ScriptCondition(script, scriptService); } catch (ElasticsearchParseException pe) { throw new ElasticsearchParseException("could not parse [{}] condition for watch [{}]. failed to parse script", pe, TYPE, diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputFactory.java index a37dbcb7cde..b868998aee8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputFactory.java @@ -31,19 +31,16 @@ public abstract class InputFactory indices = new ArrayList<>(); @@ -210,20 +208,6 @@ public class WatcherSearchTemplateRequest implements ToXContent { try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) { builder.copyCurrentStructure(parser); searchSource = builder.bytes(); - if (upgradeSearchSource) { - XContentParser searchSourceParser = XContentHelper.createParser(searchSource); - QueryParseContext context = new QueryParseContext(defaultLegacyScriptLanguage, - searchRequestParsers.queryParsers, searchSourceParser, parseFieldMatcher); - try (XContentBuilder upgradeBuilder = XContentBuilder.builder(parser.contentType().xContent())) { - SearchSourceBuilder sourceBuilder = SearchSourceBuilder.fromXContent(context, - searchRequestParsers.aggParsers, searchRequestParsers.suggesters, - searchRequestParsers.searchExtParsers); - upgradeBuilder.value(sourceBuilder); - searchSource = upgradeBuilder.bytes(); - } catch (Exception e) { - logger.warn("Unable to upgrade search source: [" + searchSource.utf8ToString() + "]", e); - } - } } } else if (ParseFieldMatcher.STRICT.match(currentFieldName, INDICES_OPTIONS_FIELD)) { boolean expandOpen = DEFAULT_INDICES_OPTIONS.expandWildcardsOpen(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformFactory.java index d4166944585..f2d592c86c4 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformFactory.java @@ -28,19 +28,16 @@ public abstract class TransformFactory ScriptCondition.parse(scriptService, "_watch", parser, false, defaultScriptLang)); + () -> ScriptCondition.parse(scriptService, "_watch", parser)); } public void testScriptConditionParser_badLang() throws Exception { @@ -175,7 +174,7 @@ public class ScriptConditionTests extends ESTestCase { XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> ScriptCondition.parse(scriptService, "_watch", parser, false, defaultScriptLang)); + () -> ScriptCondition.parse(scriptService, "_watch", parser)); assertThat(exception.getMessage(), containsString("script_lang not supported [not_a_valid_lang]")); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java index c4c6da46cab..f8e41eb4ca6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java @@ -84,7 +84,7 @@ public class ChainInputTests extends ESTestCase { // first pass JSON and check for correct inputs XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); - ChainInput chainInput = chainInputFactory.parseInput("test", parser, false); + ChainInput chainInput = chainInputFactory.parseInput("test", parser); assertThat(chainInput.getInputs(), hasSize(2)); assertThat(chainInput.getInputs().get(0).v1(), is("first")); @@ -195,7 +195,7 @@ public class ChainInputTests extends ESTestCase { XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); ElasticsearchParseException e = - expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser, false)); + expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser)); assertThat(e.getMessage(), containsString("Expected closing JSON object after parsing input [simple] named [first] in watch [test]")); } @@ -225,7 +225,7 @@ public class ChainInputTests extends ESTestCase { XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); ElasticsearchParseException e = - expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser, false)); + expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser)); assertThat(e.getMessage(), containsString("Expected starting JSON object after [first] in watch [test]")); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java index d33c9275139..2363d397d85 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java @@ -187,7 +187,7 @@ public class HttpInputTests extends ESTestCase { BytesReference source = jsonBuilder().value(inputBuilder.build()).bytes(); XContentParser parser = XContentHelper.createParser(source); parser.nextToken(); - HttpInput result = httpParser.parseInput("_id", parser, false); + HttpInput result = httpParser.parseInput("_id", parser); assertThat(result.type(), equalTo(HttpInput.TYPE)); assertThat(result.getRequest().scheme(), equalTo(scheme != null ? scheme : Scheme.HTTP)); // http is the default @@ -225,7 +225,7 @@ public class HttpInputTests extends ESTestCase { XContentParser parser = XContentHelper.createParser(builder.bytes()); parser.nextToken(); try { - httpParser.parseInput("_id", parser, false); + httpParser.parseInput("_id", parser); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("unsupported http method [_METHOD]")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java index 2eabaf2314f..10b27d5420f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java @@ -46,7 +46,7 @@ public class SimpleInputTests extends ESTestCase { InputFactory parser = new SimpleInputFactory(Settings.builder().build()); XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes()); xContentParser.nextToken(); - ExecutableInput input = parser.parseExecutable("_id", xContentParser, false); + ExecutableInput input = parser.parseExecutable("_id", xContentParser); assertEquals(input.type(), SimpleInput.TYPE); @@ -63,7 +63,7 @@ public class SimpleInputTests extends ESTestCase { XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes()); xContentParser.nextToken(); try { - parser.parseInput("_id", xContentParser, false); + parser.parseInput("_id", xContentParser); fail("[simple] input parse should fail with an InputException for an empty json object"); } catch (ElasticsearchParseException e) { assertThat(e.getMessage(), containsString("expected an object but found [VALUE_STRING] instead")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java index 38772c68c3c..c84bba10b30 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java @@ -123,8 +123,7 @@ public class WatcherUtilsTests extends ESTestCase { request.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentParser parser = XContentHelper.createParser(builder.bytes()); assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); - WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, - false, null, null, null); + WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, null, null); assertThat(result.getIndices(), arrayContainingInAnyOrder(expectedIndices != null ? expectedIndices : new String[0])); assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes != null ? expectedTypes : new String[0])); @@ -213,8 +212,7 @@ public class WatcherUtilsTests extends ESTestCase { XContentParser parser = XContentHelper.createParser(builder.bytes()); assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); - WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, - false, null, null, null); + WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, null, null); assertThat(result.getIndices(), arrayContainingInAnyOrder(indices)); assertThat(result.getTypes(), arrayContainingInAnyOrder(types)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java index a90ac5869ec..0af4b38f4c3 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java @@ -42,7 +42,7 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase { parser.nextToken(); WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent( - logger, parser, randomFrom(SearchType.values()), false, null, null, null); + logger, parser, randomFrom(SearchType.values()), null, null); assertNotNull(result.getTemplate()); assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedScript)); assertThat(result.getTemplate().getLang(), equalTo(expectedLang)); @@ -91,7 +91,7 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase { SearchRequestParsers searchRequestParsers = new SearchModule(Settings.EMPTY, false, Collections.emptyList()) .getSearchRequestParsers(); WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent( - logger, parser, SearchType.DEFAULT, true, "your_legacy_lang", ParseFieldMatcher.STRICT, searchRequestParsers); + logger, parser, SearchType.DEFAULT, ParseFieldMatcher.STRICT, searchRequestParsers); Map parsedResult = XContentHelper.convertToMap(result.getSearchSource(), true).v2(); // after upgrading the language must be equal to legacy language, because no language was defined explicitly in these scripts: assertThat(XContentMapValues.extractValue("query.script.script.lang", parsedResult), equalTo("your_legacy_lang")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java index 35111c97332..5216a1b75b6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java @@ -150,7 +150,7 @@ public class SearchInputTests extends ESIntegTestCase { SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, WatcherClientProxy.of(client()), searchParsers, scriptService()); - SearchInput searchInput = factory.parseInput("_id", parser, false); + SearchInput searchInput = factory.parseInput("_id", parser); assertEquals(SearchInput.TYPE, searchInput.type()); assertThat(searchInput.getTimeout(), equalTo(timeout)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java index f6708bf20ab..e160cd7616b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java @@ -218,7 +218,7 @@ public class SearchTransformTests extends ESIntegTestCase { SearchRequestParsers searchRequestParsers = internalCluster().getInstance(SearchRequestParsers.class); SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, WatcherClientProxy.of(client()), searchRequestParsers, scriptService()); - ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser, false); + ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser); assertThat(executable, notNullValue()); assertThat(executable.type(), is(SearchTransform.TYPE)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java index 414c9b3c4a9..59b77fd3dfd 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java @@ -123,7 +123,7 @@ public class ChainTransformTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - ExecutableChainTransform executable = transformParser.parseExecutable("_id", parser, false); + ExecutableChainTransform executable = transformParser.parseExecutable("_id", parser); assertThat(executable, notNullValue()); assertThat(executable.transform().getTransforms(), notNullValue()); assertThat(executable.transform().getTransforms(), hasSize(4)); @@ -201,7 +201,7 @@ public class ChainTransformTests extends ESTestCase { } @Override - public Transform parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException { + public Transform parseTransform(String watchId, XContentParser parser) throws IOException { if (parser.currentToken() == XContentParser.Token.VALUE_STRING) { return new Transform(parser.text()); } @@ -270,7 +270,7 @@ public class ChainTransformTests extends ESTestCase { } @Override - public Transform parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException { + public Transform parseTransform(String watchId, XContentParser parser) throws IOException { assert parser.currentToken() == XContentParser.Token.START_OBJECT; XContentParser.Token token = parser.nextToken(); assert token == XContentParser.Token.END_OBJECT; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java index 52afb4c6891..2aef33c4c79 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java @@ -154,7 +154,7 @@ public class ScriptTransformTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser, false); + ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser); Script script = new Script(type, "_lang", "_script", singletonMap("key", "value")); assertThat(transform.transform().getScript(), equalTo(script)); } @@ -165,7 +165,7 @@ public class ScriptTransformTests extends ESTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser, false); + ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser); assertThat(transform.transform().getScript(), equalTo(new Script("_script"))); } @@ -185,7 +185,7 @@ public class ScriptTransformTests extends ESTestCase { XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); - ScriptTransform scriptTransform = transformFactory.parseTransform("_watch", parser, false); + ScriptTransform scriptTransform = transformFactory.parseTransform("_watch", parser); Exception e = expectThrows(ScriptException.class, () -> transformFactory.createExecutable(scriptTransform)); assertThat(e.getMessage(), containsString(errorMessage)); } @@ -203,7 +203,7 @@ public class ScriptTransformTests extends ESTestCase { XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); parser.nextToken(); - ScriptTransform scriptCondition = transformFactory.parseTransform("_watch", parser, false); + ScriptTransform scriptCondition = transformFactory.parseTransform("_watch", parser); Exception e = expectThrows(IllegalArgumentException.class, () -> transformFactory.createExecutable(scriptCondition)); assertThat(e.getMessage(), containsString("script_lang not supported [not_a_valid_lang]")); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java index 19d2a2e9196..1ac60a86a9c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java @@ -345,10 +345,10 @@ public class WatchTests extends ESTestCase { // parse in legacy mode: watch = watchParser.parse("_id", false, builder.bytes(), true); - assertThat(((ScriptCondition) watch.condition()).getScript().getLang(), equalTo("groovy")); + assertThat(((ScriptCondition) watch.condition()).getScript().getLang(), equalTo("painless")); request = ((SearchInput) watch.input().input()).getRequest(); searchRequest = searchTemplateService.toSearchRequest(request); - assertThat(((ScriptQueryBuilder) searchRequest.source().query()).script().getLang(), equalTo("groovy")); + assertThat(((ScriptQueryBuilder) searchRequest.source().query()).script().getLang(), equalTo("painless")); } private static Schedule randomSchedule() { @@ -437,13 +437,11 @@ public class WatchTests extends ESTestCase { private ConditionRegistry conditionRegistry() { Map parsers = new HashMap<>(); - parsers.put(AlwaysCondition.TYPE, (c, id, p, upgrade) -> AlwaysCondition.parse(id, p)); - parsers.put(NeverCondition.TYPE, (c, id, p, upgrade) -> NeverCondition.parse(id, p)); - parsers.put(ArrayCompareCondition.TYPE, (c, id, p, upgrade) -> ArrayCompareCondition.parse(c, id, p)); - parsers.put(CompareCondition.TYPE, (c, id, p, upgrade) -> CompareCondition.parse(c, id, p)); - String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings); - parsers.put(ScriptCondition.TYPE, (c, id, p, upgrade) -> ScriptCondition.parse(scriptService, id, p, upgrade, - defaultLegacyScriptLanguage)); + parsers.put(AlwaysCondition.TYPE, (c, id, p) -> AlwaysCondition.parse(id, p)); + parsers.put(NeverCondition.TYPE, (c, id, p) -> NeverCondition.parse(id, p)); + parsers.put(ArrayCompareCondition.TYPE, (c, id, p) -> ArrayCompareCondition.parse(c, id, p)); + parsers.put(CompareCondition.TYPE, (c, id, p) -> CompareCondition.parse(c, id, p)); + parsers.put(ScriptCondition.TYPE, (c, id, p) -> ScriptCondition.parse(scriptService, id, p)); return new ConditionRegistry(parsers, new ClockMock()); } diff --git a/qa/smoke-test-watcher-with-groovy/build.gradle b/qa/smoke-test-watcher-with-groovy/build.gradle deleted file mode 100644 index 1b4205dd165..00000000000 --- a/qa/smoke-test-watcher-with-groovy/build.gradle +++ /dev/null @@ -1,15 +0,0 @@ -apply plugin: 'elasticsearch.rest-test' - -dependencies { - testCompile project(path: ':x-plugins:elasticsearch', configuration: 'runtime') - testCompile project(path: ':modules:lang-groovy', configuration: 'runtime') -} - -integTest { - cluster { - plugin ':x-plugins:elasticsearch' - setting 'script.inline', 'true' - setting 'xpack.security.enabled', 'false' - setting 'xpack.monitoring.enabled', 'false' - } -} diff --git a/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherRestTestCase.java b/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherRestTestCase.java deleted file mode 100644 index de8f23fb65d..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherRestTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.smoketest; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; - -import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; -import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; -import org.junit.After; -import org.junit.Before; - -import java.io.IOException; - -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; - -public abstract class WatcherRestTestCase extends ESClientYamlSuiteTestCase { - - public WatcherRestTestCase(@Name("yaml") ClientYamlTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws IOException, ClientYamlTestParseException { - return ESClientYamlSuiteTestCase.createParameters(); - } - - @Before - public void startWatcher() throws Exception { - getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap()); - } - - @After - public void stopWatcher() throws Exception { - getAdminExecutionContext().callApi("xpack.watcher.stop", emptyMap(), emptyList(), emptyMap()); - } -} diff --git a/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherWithGroovyIT.java b/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherWithGroovyIT.java deleted file mode 100644 index e218055c370..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/java/org/elasticsearch/smoketest/WatcherWithGroovyIT.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.smoketest; - -import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; - -/** Runs rest tests against external cluster */ -public class WatcherWithGroovyIT extends WatcherRestTestCase { - - public WatcherWithGroovyIT(ClientYamlTestCandidate testCandidate) { - super(testCandidate); - } - -} diff --git a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/10_basic.yaml b/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/10_basic.yaml deleted file mode 100644 index 2a5ea88d5d8..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/10_basic.yaml +++ /dev/null @@ -1,89 +0,0 @@ ---- -"Test execute watch api": - - do: - cluster.health: - wait_for_status: green - - - do: - xpack.watcher.put_watch: - id: "my_exe_watch" - body: > - { - "trigger" : { - "schedule" : { "cron" : "0 0 0 1 * ? 2099" } - }, - "input" : { - "search" : { - "request" : { - "indices" : [ "logstash*" ], - "body" : { - "query" : { - "bool": { - "must" : { - "match": { - "response": 404 - } - }, - "filter": { - "range": { - "@timestamp" : { - "from": "{{ctx.trigger.scheduled_time}}||-5m", - "to": "{{ctx.trigger.triggered_time}}" - } - } - } - } - } - } - } - } - }, - "condition" : { - "script" : { - "inline" : "ctx.payload.hits.total > 1" - } - }, - "actions" : { - "email_admin" : { - "email" : { - "to" : "someone@domain.host.com", - "subject" : "404 recently encountered" - } - } - } - } - - match: { _id: "my_exe_watch" } - - - do: - xpack.watcher.execute_watch: - id: "my_exe_watch" - body: > - { - "trigger_data" : { - "scheduled_time" : "2015-05-05T20:58:02.443Z", - "triggered_time" : "2015-05-05T20:58:02.443Z" - }, - "alternative_input" : { - "foo" : "bar" - }, - "ignore_condition" : true, - "action_modes" : { - "_all" : "force_simulate" - }, - "record_execution" : true - } - - match: { "watch_record.watch_id": "my_exe_watch" } - - match: { "watch_record.state": "executed" } - - match: { "watch_record.trigger_event.type": "manual" } - - match: { "watch_record.trigger_event.triggered_time": "2015-05-05T20:58:02.443Z" } - - match: { "watch_record.trigger_event.manual.schedule.scheduled_time": "2015-05-05T20:58:02.443Z" } - - match: { "watch_record.result.input.type": "simple" } - - match: { "watch_record.result.input.status": "success" } - - match: { "watch_record.result.input.payload.foo": "bar" } - - match: { "watch_record.result.condition.type": "always" } - - match: { "watch_record.result.condition.status": "success" } - - match: { "watch_record.result.condition.met": true } - - match: { "watch_record.result.actions.0.id" : "email_admin" } - - match: { "watch_record.result.actions.0.status" : "simulated" } - - match: { "watch_record.result.actions.0.type" : "email" } - - match: { "watch_record.result.actions.0.email.message.subject" : "404 recently encountered" } diff --git a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/20_minimal_body.yaml b/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/20_minimal_body.yaml deleted file mode 100644 index 3026c7dbf27..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/20_minimal_body.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -"Test execute watch api with minimal body": - - do: - cluster.health: - wait_for_status: green - - - do: - xpack.watcher.put_watch: - id: "my_logging_watch" - body: > - { - "trigger" : { - "schedule" : { "cron" : "0 0 0 1 * ? 2099" } - }, - "input" : { - "simple" : { - "count" : 1 - } - }, - "condition" : { - "script" : "ctx.payload.count == 1" - }, - "actions" : { - "logging" : { - "logging" : { - "text" : "foobar" - } - } - } - } - - match: { _id: "my_logging_watch" } - - - do: - xpack.watcher.execute_watch: - id: "my_logging_watch" - - - match: { "watch_record.watch_id": "my_logging_watch" } - - match: { "watch_record.state": "executed" } - - match: { "watch_record.result.input.type": "simple" } - - match: { "watch_record.result.input.status": "success" } - - match: { "watch_record.result.input.payload.count": 1 } - - match: { "watch_record.result.condition.type": "script" } - - match: { "watch_record.result.condition.status": "success" } - - match: { "watch_record.result.condition.met": true } - - match: { "watch_record.result.actions.0.id" : "logging" } - - match: { "watch_record.result.actions.0.type" : "logging" } - - match: { "watch_record.result.actions.0.status" : "success" } - - match: { "watch_record.result.actions.0.logging.logged_text" : "foobar" } diff --git a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/30_inline_watch.yaml b/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/30_inline_watch.yaml deleted file mode 100644 index a54ab176b62..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/30_inline_watch.yaml +++ /dev/null @@ -1,74 +0,0 @@ ---- -"Test execute watch api with an inline watch": - - do: - cluster.health: - wait_for_status: green - - - do: - xpack.watcher.execute_watch: - body: > - { - "trigger_data" : { - "scheduled_time" : "2015-05-05T20:58:02.443Z", - "triggered_time" : "2015-05-05T20:58:02.443Z" - }, - "alternative_input" : { - "foo" : "bar" - }, - "ignore_condition" : true, - "action_modes" : { - "_all" : "force_simulate" - }, - "watch" : { - "trigger" : { - "schedule" : { "cron" : "0 0 0 1 * ? 2099" } - }, - "input" : { - "search" : { - "request" : { - "indices" : [ "logstash*" ], - "body" : { - "query" : { - "bool" : { - "must": { - "match": { - "response": 404 - } - }, - "filter": { - "range": { - "@timestamp" : { - "from": "{{ctx.trigger.scheduled_time}}||-5m", - "to": "{{ctx.trigger.triggered_time}}" - } - } - } - } - } - } - } - } - }, - "condition" : { - "script" : { - "inline" : "ctx.payload.hits.total > 1" - } - }, - "actions" : { - "email_admin" : { - "email" : { - "to" : "someone@domain.host.com", - "subject" : "404 recently encountered" - } - } - } - } - } - - match: { "watch_record.state": "executed" } - - match: { "watch_record.trigger_event.manual.schedule.scheduled_time": "2015-05-05T20:58:02.443Z" } - - match: { "watch_record.result.input.type": "simple" } - - match: { "watch_record.result.input.payload.foo": "bar" } - - match: { "watch_record.result.condition.met": true } - - match: { "watch_record.result.actions.0.id" : "email_admin" } - - match: { "watch_record.result.actions.0.status" : "simulated" } - - match: { "watch_record.result.actions.0.email.message.subject" : "404 recently encountered" } diff --git a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/40_index_action.yaml b/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/40_index_action.yaml deleted file mode 100644 index 1c90ab603b6..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/40_index_action.yaml +++ /dev/null @@ -1,238 +0,0 @@ ---- -"Test simple input to index action": - - do: - xpack.watcher.put_watch: - id: my_watch - body: > - { - "trigger" : { "schedule" : { "cron" : "0/1 * * * * ? 2020" } }, - "input" : { "simple" : { "foo": "bar" } }, - "actions" : { - "index_action" : { - "index" : { - "index" : "idx", - "doc_type" : "type", - "execution_time_field" : "@timestamp" - } - } - } - } - - - match: { _id: "my_watch" } - - - - do: - xpack.watcher.execute_watch: - id: "my_watch" - body: > - { - "trigger_data" : { - "triggered_time" : "2016-07-07T09:00:00Z", - "scheduled_time" : "2016-07-07T09:00:00Z" - } - } - - - match: { "watch_record.state": "executed" } - - - do: - indices.refresh: {} - - - do: - search: - index: idx - type: type - - - match: { hits.total: 1 } - - match: { hits.hits.0._source.foo: bar } - - gte: { hits.hits.0._source.@timestamp: '2016-07-08' } - ---- -"Test simple input with document field": - - - do: - xpack.watcher.put_watch: - id: my_watch - body: > - { - "trigger" : { "schedule" : { "cron" : "0/1 * * * * ? 2020" } }, - "input" : { "simple" : { "foo": "bar" } }, - "actions" : { - "index_action" : { - "transform" : { "script" : { "inline": "return [ '_doc' : ctx.payload ]" } }, - "index" : { - "index" : "idx", - "doc_type" : "type", - "execution_time_field" : "@timestamp" - } - } - } - } - - - match: { _id: "my_watch" } - - - - do: - xpack.watcher.execute_watch: - id: "my_watch" - body: > - { - "trigger_data" : { - "triggered_time" : "2016-07-07T09:00:00Z", - "scheduled_time" : "2016-07-07T09:00:00Z" - } - } - - - match: { "watch_record.state": "executed" } - - - do: - indices.refresh: {} - - - do: - search: - index: idx - type: type - - - match: { hits.total: 1 } - - match: { hits.hits.0._source.foo: bar } - - gte: { hits.hits.0._source.@timestamp: '2016-07-08"' } - - ---- -"Test simple input with wrong document results in error": - - - do: - xpack.watcher.put_watch: - id: my_watch - body: > - { - "trigger" : { "schedule" : { "cron" : "0/1 * * * * ? 2020" } }, - "input" : { "simple" : { "foo": "bar" } }, - "actions" : { - "index_action" : { - "transform" : { "script" : { "inline": "return [ '_doc' : 1 ]" } }, - "index" : { - "index" : "idx", - "doc_type" : "type", - "execution_time_field" : "@timestamp" - } - } - } - } - - - match: { _id: "my_watch" } - - - - do: - xpack.watcher.execute_watch: - id: "my_watch" - body: > - { - "record_execution" : true, - "trigger_data" : { - "triggered_time" : "2016-07-07T09:00:00Z", - "scheduled_time" : "2016-07-07T09:00:00Z" - } - } - - - match: { "watch_record.state": "executed" } - - - do: - indices.refresh: {} - - - do: - indices.exists: - index: idx - - - is_false: '' - - - do: - search: - index: .watcher-history-* - type: watch_record - body: > - { - "query" : { - "match" : { - "result.actions.status": "failure" - } - } - } - - - match: { hits.total: 1 } - ---- -"Test search input to index action with aggs": - - - do: - bulk: - refresh: true - body: - - '{"index": {"_index": "idx", "_type": "type", "_id": "1"}}' - - '{"@timestamp": "2016-07-07" }' - - '{"index": {"_index": "idx", "_type": "type", "_id": "2"}}' - - '{"@timestamp": "2016-07-08" }' - - '{"index": {"_index": "idx", "_type": "type", "_id": "3"}}' - - '{"@timestamp": "2016-07-09" }' - - - do: - xpack.watcher.put_watch: - id: my_watch - body: > - { - "trigger" : { "schedule" : { "cron" : "0/1 * * * * ? 2020" } }, - "input" : { - "search" : { - "request": { - "indices" : [ "idx" ], - "types" : [ "type" ], - "body" : { - "aggs" : { - "trend" : { - "date_histogram" : { - "field" : "@timestamp", - "interval" : "day" - } - } - } - } - } - } - }, - "actions" : { - "index_action" : { - "transform" : { "script" : { "inline": "return [ '_doc' : ctx.payload.aggregations.trend.buckets]" } }, - "index" : { - "index" : "idx", - "doc_type" : "bucket", - "execution_time_field" : "@timestamp" - } - } - } - } - - - match: { _id: "my_watch" } - - - - do: - xpack.watcher.execute_watch: - id: "my_watch" - body: > - { - "trigger_data" : { - "triggered_time" : "2016-07-07T09:00:00Z", - "scheduled_time" : "2016-07-07T09:00:00Z" - } - } - - - match: { "watch_record.state": "executed" } - - - do: - indices.refresh: {} - - - do: - search: - index: idx - type: bucket - - - match: { hits.total: 3 } - diff --git a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/50_script_condition.yaml b/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/50_script_condition.yaml deleted file mode 100644 index d8ee955f1ab..00000000000 --- a/qa/smoke-test-watcher-with-groovy/src/test/resources/rest-api-spec/test/watcher_groovy/50_script_condition.yaml +++ /dev/null @@ -1,141 +0,0 @@ ---- -"Test the execution of a Groovy closure in script condition": - - - do: - bulk: - refresh: true - body: | - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "green", "@timestamp": "2005-01-01T00:00:00" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "yellow", "@timestamp": "2005-01-01T00:00:05" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "green", "@timestamp": "2005-01-01T00:00:55" } - - - do: - xpack.watcher.put_watch: - id: "watch_with_groovy_closure" - body: > - { - "trigger" : { - "schedule" : { "cron" : "0 0 0 1 * ? 2099" } - }, - "input" : { - "search" : { - "request" : { - "indices" : [ ".monitoring" ], - "body" : { - "query" : { - "match_all" : { - } - }, - "aggregations" : { - "minutes" : { - "date_histogram" : { - "field" : "@timestamp", - "interval" : "5s", - "order" : { - "_count" : "desc" - } - }, - "aggregations": { - "status" : { - "terms" : { - "field" : "status.keyword", - "size" : 3 - } - } - } - } - } - } - } - } - }, - "condition" : { - "script" : { - "inline" : "if (ctx.payload.hits.total < 1) return false; def rows = ctx.payload.hits.hits; if (ctx.payload.aggregations.minutes.buckets.size() < 12) return false; def last60Seconds = ctx.payload.aggregations.minutes.buckets[-12..-1]; return last60Seconds.every { it.status.buckets.every { s -> s.key == 'red' } }", - "lang": "groovy" - } - }, - "actions" : { - "log" : { - "logging" : { - "text" : "executed at {{ctx.execution_time}}" - } - } - } - } - - - match: { _id: "watch_with_groovy_closure" } - - - do: - warnings: - - '[groovy] scripts are deprecated, use [painless] scripts instead' - xpack.watcher.execute_watch: - id: "watch_with_groovy_closure" - body: > - { - "trigger_data" : { - "scheduled_time" : "2015-05-05T20:58:02.443Z", - "triggered_time" : "2015-05-05T20:58:02.443Z" - }, - "ignore_condition" : false, - "action_modes" : { - "_all" : "force_simulate" - }, - "record_execution" : false - } - - - match: { "watch_record.state": "execution_not_needed" } - - match: { "watch_record.result.condition.met": false } - - - do: - bulk: - refresh: true - body: | - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:00" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:05" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:10" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:15" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:20" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:25" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:30" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:35" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:40" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:45" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:50" } - {"index": {"_index": ".monitoring", "_type": "cluster_stats"}} - { "status": "red", "@timestamp": "2005-01-01T00:01:55" } - - - do: - warnings: - - '[groovy] scripts are deprecated, use [painless] scripts instead' - xpack.watcher.execute_watch: - id: "watch_with_groovy_closure" - body: > - { - "trigger_data" : { - "scheduled_time" : "2015-05-05T20:58:02.443Z", - "triggered_time" : "2015-05-05T20:58:02.443Z" - }, - "ignore_condition" : false, - "action_modes" : { - "_all" : "force_simulate" - }, - "record_execution" : false - } - - - match: { "watch_record.state": "executed" } - - match: { "watch_record.result.condition.met": true }