mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
Remove groovy scripting language (elastic/elasticsearch#4162)
This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#21607 Original commit: elastic/x-pack-elasticsearch@125843e814
This commit is contained in:
parent
ecbdd92c8c
commit
1dc839bd98
@ -216,13 +216,11 @@ public class Watcher implements ActionPlugin, ScriptPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, ConditionFactory> parsers = new HashMap<>();
|
final Map<String, ConditionFactory> parsers = new HashMap<>();
|
||||||
parsers.put(AlwaysCondition.TYPE, (c, id, p, upgrade) -> AlwaysCondition.parse(id, p));
|
parsers.put(AlwaysCondition.TYPE, (c, id, p) -> AlwaysCondition.parse(id, p));
|
||||||
parsers.put(NeverCondition.TYPE, (c, id, p, upgrade) -> NeverCondition.parse(id, p));
|
parsers.put(NeverCondition.TYPE, (c, id, p) -> NeverCondition.parse(id, p));
|
||||||
parsers.put(ArrayCompareCondition.TYPE, (c, id, p, upgrade) -> ArrayCompareCondition.parse(c, id, p));
|
parsers.put(ArrayCompareCondition.TYPE, (c, id, p) -> ArrayCompareCondition.parse(c, id, p));
|
||||||
parsers.put(CompareCondition.TYPE, (c, id, p, upgrade) -> CompareCondition.parse(c, id, p));
|
parsers.put(CompareCondition.TYPE, (c, id, p) -> CompareCondition.parse(c, id, p));
|
||||||
String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings);
|
parsers.put(ScriptCondition.TYPE, (c, id, p) -> ScriptCondition.parse(scriptService, id, p));
|
||||||
parsers.put(ScriptCondition.TYPE, (c, id, p, upgrade) -> ScriptCondition.parse(scriptService, id, p, upgrade,
|
|
||||||
defaultLegacyScriptLanguage));
|
|
||||||
|
|
||||||
final ConditionRegistry conditionRegistry = new ConditionRegistry(Collections.unmodifiableMap(parsers), clock);
|
final ConditionRegistry conditionRegistry = new ConditionRegistry(Collections.unmodifiableMap(parsers), clock);
|
||||||
final Map<String, TransformFactory> transformFactories = new HashMap<>();
|
final Map<String, TransformFactory> transformFactories = new HashMap<>();
|
||||||
|
@ -41,7 +41,7 @@ public class ActionRegistry {
|
|||||||
return parsers.get(type);
|
return parsers.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ActionWrapper> parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException {
|
public List<ActionWrapper> parseActions(String watchId, XContentParser parser) throws IOException {
|
||||||
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
||||||
throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead",
|
throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead",
|
||||||
watchId, parser.currentToken());
|
watchId, parser.currentToken());
|
||||||
@ -58,7 +58,7 @@ public class ActionRegistry {
|
|||||||
watchId);
|
watchId);
|
||||||
}
|
}
|
||||||
} else if (token == XContentParser.Token.START_OBJECT && id != null) {
|
} 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;
|
return actions;
|
||||||
|
@ -194,7 +194,7 @@ public class ActionWrapper implements ToXContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ActionWrapper parse(String watchId, String actionId, XContentParser parser, ActionRegistry actionRegistry, Clock clock,
|
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;
|
assert parser.currentToken() == XContentParser.Token.START_OBJECT;
|
||||||
|
|
||||||
@ -210,9 +210,9 @@ public class ActionWrapper implements ToXContent {
|
|||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else {
|
} else {
|
||||||
if (ParseFieldMatcher.STRICT.match(currentFieldName, Watch.Field.CONDITION)) {
|
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)) {
|
} 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)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD)) {
|
||||||
throttlePeriod = timeValueMillis(parser.longValue());
|
throttlePeriod = timeValueMillis(parser.longValue());
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD_HUMAN)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD_HUMAN)) {
|
||||||
|
@ -17,11 +17,9 @@ public interface ConditionFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given xcontent and creates a concrete condition
|
* 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 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,8 @@ public class ConditionRegistry {
|
|||||||
*
|
*
|
||||||
* @param watchId The id of the watch
|
* @param watchId The id of the watch
|
||||||
* @param parser The parsing that contains the condition content
|
* @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;
|
Condition condition = null;
|
||||||
ConditionFactory factory;
|
ConditionFactory factory;
|
||||||
|
|
||||||
@ -56,7 +53,7 @@ public class ConditionRegistry {
|
|||||||
throw new ElasticsearchParseException("could not parse condition for watch [{}]. unknown condition type [{}]",
|
throw new ElasticsearchParseException("could not parse condition for watch [{}]. unknown condition type [{}]",
|
||||||
watchId, type);
|
watchId, type);
|
||||||
}
|
}
|
||||||
condition = factory.parse(clock, watchId, parser, upgradeConditionSource);
|
condition = factory.parse(clock, watchId, parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (condition == null) {
|
if (condition == null) {
|
||||||
|
@ -53,15 +53,9 @@ public final class ScriptCondition extends Condition {
|
|||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScriptCondition parse(ScriptService scriptService, String watchId, XContentParser parser, boolean upgradeConditionSource,
|
public static ScriptCondition parse(ScriptService scriptService, String watchId, XContentParser parser) throws IOException {
|
||||||
String defaultLegacyScriptLanguage) throws IOException {
|
|
||||||
try {
|
try {
|
||||||
Script script;
|
Script script = Script.parse(parser, ParseFieldMatcher.STRICT);
|
||||||
if (upgradeConditionSource) {
|
|
||||||
script = Script.parse(parser, ParseFieldMatcher.STRICT, defaultLegacyScriptLanguage);
|
|
||||||
} else {
|
|
||||||
script = Script.parse(parser, ParseFieldMatcher.STRICT);
|
|
||||||
}
|
|
||||||
return new ScriptCondition(script, scriptService);
|
return new ScriptCondition(script, scriptService);
|
||||||
} catch (ElasticsearchParseException pe) {
|
} catch (ElasticsearchParseException pe) {
|
||||||
throw new ElasticsearchParseException("could not parse [{}] condition for watch [{}]. failed to parse script", pe, TYPE,
|
throw new ElasticsearchParseException("could not parse [{}] condition for watch [{}]. failed to parse script", pe, TYPE,
|
||||||
|
@ -31,19 +31,16 @@ public abstract class InputFactory<I extends Input, R extends Input.Result, E ex
|
|||||||
*
|
*
|
||||||
* @param watchId The id of the watch
|
* @param watchId The id of the watch
|
||||||
* @param parser The parser containing the input content of the watch
|
* @param parser The parser containing the input content of the watch
|
||||||
* @param upgradeInputSource Whether to upgrade the source related to the inpit if that source is in legacy format
|
|
||||||
* Note: depending on the version, only input implementations that have a known legacy
|
|
||||||
* format will support this option, otherwise this is a noop.
|
|
||||||
*/
|
*/
|
||||||
public abstract I parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException;
|
public abstract I parseInput(String watchId, XContentParser parser) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an executable input out of the given input.
|
* Creates an executable input out of the given input.
|
||||||
*/
|
*/
|
||||||
public abstract E createExecutable(I input);
|
public abstract E createExecutable(I input);
|
||||||
|
|
||||||
public E parseExecutable(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public E parseExecutable(String watchId, XContentParser parser) throws IOException {
|
||||||
I input = parseInput(watchId, parser, upgradeInputSource);
|
I input = parseInput(watchId, parser);
|
||||||
return createExecutable(input);
|
return createExecutable(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,24 +26,13 @@ public class InputRegistry {
|
|||||||
this.factories = Collections.unmodifiableMap(map);
|
this.factories = Collections.unmodifiableMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the contents of parser to create the correct Input
|
|
||||||
*
|
|
||||||
* @param parser The parser containing the input definition
|
|
||||||
* @return A new input instance from the parser
|
|
||||||
*/
|
|
||||||
public ExecutableInput parse(String watchId, XContentParser parser) throws IOException {
|
|
||||||
return parse(watchId, parser, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the contents of parser to create the correct Input
|
* Reads the contents of parser to create the correct Input
|
||||||
*
|
*
|
||||||
* @param parser The parser containing the input definition
|
* @param parser The parser containing the input definition
|
||||||
* @param upgradeInputSource Whether to upgrade the source related to input if in legacy format.
|
|
||||||
* @return A new input instance from the parser
|
* @return A new input instance from the parser
|
||||||
*/
|
*/
|
||||||
public ExecutableInput parse(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public ExecutableInput parse(String watchId, XContentParser parser) throws IOException {
|
||||||
String type = null;
|
String type = null;
|
||||||
|
|
||||||
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
||||||
@ -64,7 +53,7 @@ public class InputRegistry {
|
|||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new ElasticsearchParseException("could not parse input for watch [{}]. unknown input type [{}]", watchId, type);
|
throw new ElasticsearchParseException("could not parse input for watch [{}]. unknown input type [{}]", watchId, type);
|
||||||
}
|
}
|
||||||
input = factory.parseExecutable(watchId, parser, upgradeInputSource);
|
input = factory.parseExecutable(watchId, parser);
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchParseException("could not parse input for watch [{}]. expected an object representing input [{}], " +
|
throw new ElasticsearchParseException("could not parse input for watch [{}]. expected an object representing input [{}], " +
|
||||||
"but found [{}] instead", watchId, type, token);
|
"but found [{}] instead", watchId, type, token);
|
||||||
|
@ -33,7 +33,7 @@ public class ChainInputFactory extends InputFactory<ChainInput, ChainInput.Resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChainInput parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public ChainInput parseInput(String watchId, XContentParser parser) throws IOException {
|
||||||
return ChainInput.parse(watchId, parser, inputRegistry);
|
return ChainInput.parse(watchId, parser, inputRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public final class HttpInputFactory extends InputFactory<HttpInput, HttpInput.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpInput parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public HttpInput parseInput(String watchId, XContentParser parser) throws IOException {
|
||||||
return HttpInput.parse(watchId, parser, requestTemplateParser);
|
return HttpInput.parse(watchId, parser, requestTemplateParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class NoneInputFactory extends InputFactory<NoneInput, NoneInput.Result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NoneInput parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public NoneInput parseInput(String watchId, XContentParser parser) throws IOException {
|
||||||
return NoneInput.parse(watchId, parser);
|
return NoneInput.parse(watchId, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +109,6 @@ public class SearchInput implements Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SearchInput parse(Logger inputLogger, String watchId, XContentParser parser,
|
public static SearchInput parse(Logger inputLogger, String watchId, XContentParser parser,
|
||||||
boolean upgradeInputSource,
|
|
||||||
String defaultLegacyScriptLanguage,
|
|
||||||
ParseFieldMatcher parseFieldMatcher,
|
ParseFieldMatcher parseFieldMatcher,
|
||||||
SearchRequestParsers searchRequestParsers) throws IOException {
|
SearchRequestParsers searchRequestParsers) throws IOException {
|
||||||
WatcherSearchTemplateRequest request = null;
|
WatcherSearchTemplateRequest request = null;
|
||||||
@ -126,7 +124,7 @@ public class SearchInput implements Input {
|
|||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
|
||||||
try {
|
try {
|
||||||
request = WatcherSearchTemplateRequest.fromXContent(inputLogger, parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE,
|
request = WatcherSearchTemplateRequest.fromXContent(inputLogger, parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE,
|
||||||
upgradeInputSource, defaultLegacyScriptLanguage, parseFieldMatcher, searchRequestParsers);
|
parseFieldMatcher, searchRequestParsers);
|
||||||
} catch (ElasticsearchParseException srpe) {
|
} catch (ElasticsearchParseException srpe) {
|
||||||
throw new ElasticsearchParseException("could not parse [{}] input for watch [{}]. failed to parse [{}]", srpe, TYPE,
|
throw new ElasticsearchParseException("could not parse [{}] input for watch [{}]. failed to parse [{}]", srpe, TYPE,
|
||||||
watchId, currentFieldName);
|
watchId, currentFieldName);
|
||||||
|
@ -52,9 +52,8 @@ public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SearchInput parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public SearchInput parseInput(String watchId, XContentParser parser) throws IOException {
|
||||||
String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings);
|
return SearchInput.parse(inputLogger, watchId, parser,
|
||||||
return SearchInput.parse(inputLogger, watchId, parser, upgradeInputSource, defaultLegacyScriptLanguage,
|
|
||||||
parseFieldMatcher, searchRequestParsers);
|
parseFieldMatcher, searchRequestParsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class SimpleInputFactory extends InputFactory<SimpleInput, SimpleInput.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SimpleInput parseInput(String watchId, XContentParser parser, boolean upgradeInputSource) throws IOException {
|
public SimpleInput parseInput(String watchId, XContentParser parser) throws IOException {
|
||||||
return SimpleInput.parse(watchId, parser);
|
return SimpleInput.parse(watchId, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +167,6 @@ public class WatcherSearchTemplateRequest implements ToXContent {
|
|||||||
*/
|
*/
|
||||||
public static WatcherSearchTemplateRequest fromXContent(Logger logger, XContentParser parser,
|
public static WatcherSearchTemplateRequest fromXContent(Logger logger, XContentParser parser,
|
||||||
SearchType searchType,
|
SearchType searchType,
|
||||||
boolean upgradeSearchSource,
|
|
||||||
String defaultLegacyScriptLanguage,
|
|
||||||
ParseFieldMatcher parseFieldMatcher,
|
ParseFieldMatcher parseFieldMatcher,
|
||||||
SearchRequestParsers searchRequestParsers) throws IOException {
|
SearchRequestParsers searchRequestParsers) throws IOException {
|
||||||
List<String> indices = new ArrayList<>();
|
List<String> indices = new ArrayList<>();
|
||||||
@ -210,20 +208,6 @@ public class WatcherSearchTemplateRequest implements ToXContent {
|
|||||||
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
|
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
|
||||||
builder.copyCurrentStructure(parser);
|
builder.copyCurrentStructure(parser);
|
||||||
searchSource = builder.bytes();
|
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)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, INDICES_OPTIONS_FIELD)) {
|
||||||
boolean expandOpen = DEFAULT_INDICES_OPTIONS.expandWildcardsOpen();
|
boolean expandOpen = DEFAULT_INDICES_OPTIONS.expandWildcardsOpen();
|
||||||
|
@ -28,19 +28,16 @@ public abstract class TransformFactory<T extends Transform, R extends Transform.
|
|||||||
*
|
*
|
||||||
* @param watchId The id of the watch
|
* @param watchId The id of the watch
|
||||||
* @param parser The parsing that contains the condition content
|
* @param parser The parsing that contains the condition content
|
||||||
* @param upgradeTransformSource Whether to upgrade the source related to transform if in legacy format
|
|
||||||
* Note: depending on the version, only transform implementations that have a
|
|
||||||
* known legacy format will support this option, otherwise this is a noop.
|
|
||||||
*/
|
*/
|
||||||
public abstract T parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException;
|
public abstract T parseTransform(String watchId, XContentParser parser) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an executable transform out of the given transform.
|
* Creates an executable transform out of the given transform.
|
||||||
*/
|
*/
|
||||||
public abstract E createExecutable(T transform);
|
public abstract E createExecutable(T transform);
|
||||||
|
|
||||||
public E parseExecutable(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException {
|
public E parseExecutable(String watchId, XContentParser parser) throws IOException {
|
||||||
T transform = parseTransform(watchId, parser, upgradeTransformSource);
|
T transform = parseTransform(watchId, parser);
|
||||||
return createExecutable(transform);
|
return createExecutable(transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class TransformRegistry {
|
|||||||
return factories.get(type);
|
return factories.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutableTransform parse(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException {
|
public ExecutableTransform parse(String watchId, XContentParser parser) throws IOException {
|
||||||
String type = null;
|
String type = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
ExecutableTransform transform = null;
|
ExecutableTransform transform = null;
|
||||||
@ -38,26 +38,25 @@ public class TransformRegistry {
|
|||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
type = parser.currentName();
|
type = parser.currentName();
|
||||||
} else if (type != null) {
|
} else if (type != null) {
|
||||||
transform = parse(watchId, type, parser, upgradeTransformSource);
|
transform = parse(watchId, type, parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecutableTransform parse(String watchId, String type, XContentParser parser,
|
private ExecutableTransform parse(String watchId, String type, XContentParser parser) throws IOException {
|
||||||
boolean upgradeTransformSource) throws IOException {
|
|
||||||
TransformFactory factory = factories.get(type);
|
TransformFactory factory = factories.get(type);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new ElasticsearchParseException("could not parse transform for watch [{}], unknown transform type [{}]", watchId, type);
|
throw new ElasticsearchParseException("could not parse transform for watch [{}], unknown transform type [{}]", watchId, type);
|
||||||
}
|
}
|
||||||
return factory.parseExecutable(watchId, parser, upgradeTransformSource);
|
return factory.parseExecutable(watchId, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Transform parseTransform(String watchId, String type, XContentParser parser, boolean upgradeSource) throws IOException {
|
public Transform parseTransform(String watchId, String type, XContentParser parser) throws IOException {
|
||||||
TransformFactory factory = factories.get(type);
|
TransformFactory factory = factories.get(type);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new ElasticsearchParseException("could not parse transform for watch [{}], unknown transform type [{}]", watchId, type);
|
throw new ElasticsearchParseException("could not parse transform for watch [{}], unknown transform type [{}]", watchId, type);
|
||||||
}
|
}
|
||||||
return factory.parseTransform(watchId, parser, upgradeSource);
|
return factory.parseTransform(watchId, parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,7 @@ public class ChainTransform implements Transform {
|
|||||||
return builder.endArray();
|
return builder.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChainTransform parse(String watchId, XContentParser parser, TransformRegistry transformRegistry,
|
static ChainTransform parse(String watchId, XContentParser parser, TransformRegistry transformRegistry) throws IOException {
|
||||||
boolean upgradeSource) throws IOException {
|
|
||||||
XContentParser.Token token = parser.currentToken();
|
XContentParser.Token token = parser.currentToken();
|
||||||
if (token != XContentParser.Token.START_ARRAY) {
|
if (token != XContentParser.Token.START_ARRAY) {
|
||||||
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. expected an array of transform objects," +
|
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. expected an array of transform objects," +
|
||||||
@ -88,7 +87,7 @@ public class ChainTransform implements Transform {
|
|||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else {
|
} else {
|
||||||
transforms.add(transformRegistry.parseTransform(watchId, currentFieldName, parser, upgradeSource));
|
transforms.add(transformRegistry.parseTransform(watchId, currentFieldName, parser));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ public final class ChainTransformFactory extends TransformFactory<ChainTransform
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChainTransform parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException {
|
public ChainTransform parseTransform(String watchId, XContentParser parser) throws IOException {
|
||||||
return ChainTransform.parse(watchId, parser, registry, upgradeTransformSource);
|
return ChainTransform.parse(watchId, parser, registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,15 +54,9 @@ public class ScriptTransform implements Transform {
|
|||||||
return script.toXContent(builder, params);
|
return script.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScriptTransform parse(String watchId, XContentParser parser, boolean upgradeSource,
|
public static ScriptTransform parse(String watchId, XContentParser parser) throws IOException {
|
||||||
String defaultLegacyScriptLanguage) throws IOException {
|
|
||||||
try {
|
try {
|
||||||
Script script;
|
Script script = Script.parse(parser, ParseFieldMatcher.STRICT);
|
||||||
if (upgradeSource) {
|
|
||||||
script = Script.parse(parser, ParseFieldMatcher.STRICT, defaultLegacyScriptLanguage);
|
|
||||||
} else {
|
|
||||||
script = Script.parse(parser, ParseFieldMatcher.STRICT);
|
|
||||||
}
|
|
||||||
return new ScriptTransform(script);
|
return new ScriptTransform(script);
|
||||||
} catch (ElasticsearchParseException pe) {
|
} catch (ElasticsearchParseException pe) {
|
||||||
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. failed to parse script", pe, TYPE,
|
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. failed to parse script", pe, TYPE,
|
||||||
|
@ -31,9 +31,8 @@ public class ScriptTransformFactory extends TransformFactory<ScriptTransform, Sc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptTransform parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException {
|
public ScriptTransform parseTransform(String watchId, XContentParser parser) throws IOException {
|
||||||
String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings);
|
return ScriptTransform.parse(watchId, parser);
|
||||||
return ScriptTransform.parse(watchId, parser, upgradeTransformSource, defaultLegacyScriptLanguage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,8 +93,6 @@ public class SearchTransform implements Transform {
|
|||||||
|
|
||||||
public static SearchTransform parse(Logger transformLogger, String watchId,
|
public static SearchTransform parse(Logger transformLogger, String watchId,
|
||||||
XContentParser parser,
|
XContentParser parser,
|
||||||
boolean upgradeTransformSource,
|
|
||||||
String defaultLegacyScriptLanguage,
|
|
||||||
ParseFieldMatcher parseFieldMatcher,
|
ParseFieldMatcher parseFieldMatcher,
|
||||||
SearchRequestParsers searchRequestParsers) throws IOException {
|
SearchRequestParsers searchRequestParsers) throws IOException {
|
||||||
WatcherSearchTemplateRequest request = null;
|
WatcherSearchTemplateRequest request = null;
|
||||||
@ -108,10 +106,8 @@ public class SearchTransform implements Transform {
|
|||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
|
||||||
try {
|
try {
|
||||||
request = WatcherSearchTemplateRequest.fromXContent(
|
request = WatcherSearchTemplateRequest.fromXContent(transformLogger, parser,
|
||||||
transformLogger, parser, ExecutableSearchTransform.DEFAULT_SEARCH_TYPE, upgradeTransformSource,
|
ExecutableSearchTransform.DEFAULT_SEARCH_TYPE, parseFieldMatcher, searchRequestParsers);
|
||||||
defaultLegacyScriptLanguage, parseFieldMatcher, searchRequestParsers
|
|
||||||
);
|
|
||||||
} catch (ElasticsearchParseException srpe) {
|
} catch (ElasticsearchParseException srpe) {
|
||||||
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. failed to parse [{}]", srpe,
|
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. failed to parse [{}]", srpe,
|
||||||
TYPE, watchId, currentFieldName);
|
TYPE, watchId, currentFieldName);
|
||||||
|
@ -52,9 +52,8 @@ public class SearchTransformFactory extends TransformFactory<SearchTransform, Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SearchTransform parseTransform(String watchId, XContentParser parser, boolean upgradeTransformSource) throws IOException {
|
public SearchTransform parseTransform(String watchId, XContentParser parser) throws IOException {
|
||||||
String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings);
|
return SearchTransform.parse(transformLogger, watchId, parser,
|
||||||
return SearchTransform.parse(transformLogger, watchId, parser, upgradeTransformSource, defaultLegacyScriptLanguage,
|
|
||||||
parseFieldMatcher, searchRequestParsers);
|
parseFieldMatcher, searchRequestParsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,11 +301,11 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
|||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TRIGGER)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TRIGGER)) {
|
||||||
trigger = triggerService.parseTrigger(id, parser);
|
trigger = triggerService.parseTrigger(id, parser);
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.INPUT)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.INPUT)) {
|
||||||
input = inputRegistry.parse(id, parser, upgradeWatchSource);
|
input = inputRegistry.parse(id, parser);
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.CONDITION)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.CONDITION)) {
|
||||||
condition = actionRegistry.getConditionRegistry().parseExecutable(id, parser, upgradeWatchSource);
|
condition = actionRegistry.getConditionRegistry().parseExecutable(id, parser);
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TRANSFORM)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TRANSFORM)) {
|
||||||
transform = actionRegistry.getTransformRegistry().parse(id, parser, upgradeWatchSource);
|
transform = actionRegistry.getTransformRegistry().parse(id, parser);
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.THROTTLE_PERIOD)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.THROTTLE_PERIOD)) {
|
||||||
throttlePeriod = timeValueMillis(parser.longValue());
|
throttlePeriod = timeValueMillis(parser.longValue());
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.THROTTLE_PERIOD_HUMAN)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.THROTTLE_PERIOD_HUMAN)) {
|
||||||
@ -317,7 +317,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
|||||||
pe, id, currentFieldName);
|
pe, id, currentFieldName);
|
||||||
}
|
}
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ACTIONS)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ACTIONS)) {
|
||||||
actions = actionRegistry.parseActions(id, parser, upgradeWatchSource);
|
actions = actionRegistry.parseActions(id, parser);
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.METADATA)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.METADATA)) {
|
||||||
metatdata = parser.map();
|
metatdata = parser.map();
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.STATUS)) {
|
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.STATUS)) {
|
||||||
|
@ -53,7 +53,6 @@ import static org.hamcrest.Matchers.is;
|
|||||||
public class ScriptConditionTests extends ESTestCase {
|
public class ScriptConditionTests extends ESTestCase {
|
||||||
|
|
||||||
private ScriptService scriptService;
|
private ScriptService scriptService;
|
||||||
private String defaultScriptLang = ScriptSettings.getLegacyDefaultLang(Settings.EMPTY);
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws IOException {
|
public void init() throws IOException {
|
||||||
@ -118,7 +117,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||||||
|
|
||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ScriptCondition executable = ScriptCondition.parse(scriptService, "_watch", parser, false, defaultScriptLang);
|
ScriptCondition executable = ScriptCondition.parse(scriptService, "_watch", parser);
|
||||||
|
|
||||||
SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 500L, new ShardSearchFailure[0]);
|
SearchResponse response = new SearchResponse(InternalSearchResponse.empty(), "", 3, 3, 500L, new ShardSearchFailure[0]);
|
||||||
WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response));
|
WatchExecutionContext ctx = mockExecutionContext("_name", new Payload.XContent(response));
|
||||||
@ -129,7 +128,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||||||
builder = createConditionContent("return true", null, ScriptType.INLINE);
|
builder = createConditionContent("return true", null, ScriptType.INLINE);
|
||||||
parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
executable = ScriptCondition.parse(scriptService, "_watch", parser, false, defaultScriptLang);
|
executable = ScriptCondition.parse(scriptService, "_watch", parser);
|
||||||
|
|
||||||
ctx = mockExecutionContext("_name", new Payload.XContent(response));
|
ctx = mockExecutionContext("_name", new Payload.XContent(response));
|
||||||
|
|
||||||
@ -142,7 +141,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
try {
|
try {
|
||||||
ScriptCondition.parse(scriptService, "_id", parser, false, defaultScriptLang);
|
ScriptCondition.parse(scriptService, "_id", parser);
|
||||||
fail("expected a condition exception trying to parse an invalid condition XContent");
|
fail("expected a condition exception trying to parse an invalid condition XContent");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(),
|
assertThat(e.getMessage(),
|
||||||
@ -162,11 +161,11 @@ public class ScriptConditionTests extends ESTestCase {
|
|||||||
default:
|
default:
|
||||||
script = "foo = = 1";
|
script = "foo = = 1";
|
||||||
}
|
}
|
||||||
XContentBuilder builder = createConditionContent(script, "groovy", scriptType);
|
XContentBuilder builder = createConditionContent(script, "painless", scriptType);
|
||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
expectThrows(IllegalArgumentException.class,
|
expectThrows(IllegalArgumentException.class,
|
||||||
() -> ScriptCondition.parse(scriptService, "_watch", parser, false, defaultScriptLang));
|
() -> ScriptCondition.parse(scriptService, "_watch", parser));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testScriptConditionParser_badLang() throws Exception {
|
public void testScriptConditionParser_badLang() throws Exception {
|
||||||
@ -175,7 +174,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
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]"));
|
assertThat(exception.getMessage(), containsString("script_lang not supported [not_a_valid_lang]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class ChainInputTests extends ESTestCase {
|
|||||||
// first pass JSON and check for correct inputs
|
// first pass JSON and check for correct inputs
|
||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ChainInput chainInput = chainInputFactory.parseInput("test", parser, false);
|
ChainInput chainInput = chainInputFactory.parseInput("test", parser);
|
||||||
|
|
||||||
assertThat(chainInput.getInputs(), hasSize(2));
|
assertThat(chainInput.getInputs(), hasSize(2));
|
||||||
assertThat(chainInput.getInputs().get(0).v1(), is("first"));
|
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());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ElasticsearchParseException e =
|
ElasticsearchParseException e =
|
||||||
expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser, false));
|
expectThrows(ElasticsearchParseException.class, () -> chainInputFactory.parseInput("test", parser));
|
||||||
assertThat(e.getMessage(),
|
assertThat(e.getMessage(),
|
||||||
containsString("Expected closing JSON object after parsing input [simple] named [first] in watch [test]"));
|
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());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ElasticsearchParseException e =
|
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]"));
|
assertThat(e.getMessage(), containsString("Expected starting JSON object after [first] in watch [test]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ public class HttpInputTests extends ESTestCase {
|
|||||||
BytesReference source = jsonBuilder().value(inputBuilder.build()).bytes();
|
BytesReference source = jsonBuilder().value(inputBuilder.build()).bytes();
|
||||||
XContentParser parser = XContentHelper.createParser(source);
|
XContentParser parser = XContentHelper.createParser(source);
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
HttpInput result = httpParser.parseInput("_id", parser, false);
|
HttpInput result = httpParser.parseInput("_id", parser);
|
||||||
|
|
||||||
assertThat(result.type(), equalTo(HttpInput.TYPE));
|
assertThat(result.type(), equalTo(HttpInput.TYPE));
|
||||||
assertThat(result.getRequest().scheme(), equalTo(scheme != null ? scheme : Scheme.HTTP)); // http is the default
|
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());
|
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
try {
|
try {
|
||||||
httpParser.parseInput("_id", parser, false);
|
httpParser.parseInput("_id", parser);
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), is("unsupported http method [_METHOD]"));
|
assertThat(e.getMessage(), is("unsupported http method [_METHOD]"));
|
||||||
|
@ -46,7 +46,7 @@ public class SimpleInputTests extends ESTestCase {
|
|||||||
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
|
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
|
||||||
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
|
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
|
||||||
xContentParser.nextToken();
|
xContentParser.nextToken();
|
||||||
ExecutableInput input = parser.parseExecutable("_id", xContentParser, false);
|
ExecutableInput input = parser.parseExecutable("_id", xContentParser);
|
||||||
assertEquals(input.type(), SimpleInput.TYPE);
|
assertEquals(input.type(), SimpleInput.TYPE);
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class SimpleInputTests extends ESTestCase {
|
|||||||
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
|
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
|
||||||
xContentParser.nextToken();
|
xContentParser.nextToken();
|
||||||
try {
|
try {
|
||||||
parser.parseInput("_id", xContentParser, false);
|
parser.parseInput("_id", xContentParser);
|
||||||
fail("[simple] input parse should fail with an InputException for an empty json object");
|
fail("[simple] input parse should fail with an InputException for an empty json object");
|
||||||
} catch (ElasticsearchParseException e) {
|
} catch (ElasticsearchParseException e) {
|
||||||
assertThat(e.getMessage(), containsString("expected an object but found [VALUE_STRING] instead"));
|
assertThat(e.getMessage(), containsString("expected an object but found [VALUE_STRING] instead"));
|
||||||
|
@ -123,8 +123,7 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||||||
request.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
request.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||||
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE,
|
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, null, null);
|
||||||
false, null, null, null);
|
|
||||||
|
|
||||||
assertThat(result.getIndices(), arrayContainingInAnyOrder(expectedIndices != null ? expectedIndices : new String[0]));
|
assertThat(result.getIndices(), arrayContainingInAnyOrder(expectedIndices != null ? expectedIndices : new String[0]));
|
||||||
assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes != null ? expectedTypes : 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());
|
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||||
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE,
|
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(logger, parser, DEFAULT_SEARCH_TYPE, null, null);
|
||||||
false, null, null, null);
|
|
||||||
|
|
||||||
assertThat(result.getIndices(), arrayContainingInAnyOrder(indices));
|
assertThat(result.getIndices(), arrayContainingInAnyOrder(indices));
|
||||||
assertThat(result.getTypes(), arrayContainingInAnyOrder(types));
|
assertThat(result.getTypes(), arrayContainingInAnyOrder(types));
|
||||||
|
@ -42,7 +42,7 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase {
|
|||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
||||||
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(
|
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(
|
||||||
logger, parser, randomFrom(SearchType.values()), false, null, null, null);
|
logger, parser, randomFrom(SearchType.values()), null, null);
|
||||||
assertNotNull(result.getTemplate());
|
assertNotNull(result.getTemplate());
|
||||||
assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedScript));
|
assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedScript));
|
||||||
assertThat(result.getTemplate().getLang(), equalTo(expectedLang));
|
assertThat(result.getTemplate().getLang(), equalTo(expectedLang));
|
||||||
@ -91,7 +91,7 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase {
|
|||||||
SearchRequestParsers searchRequestParsers = new SearchModule(Settings.EMPTY, false, Collections.emptyList())
|
SearchRequestParsers searchRequestParsers = new SearchModule(Settings.EMPTY, false, Collections.emptyList())
|
||||||
.getSearchRequestParsers();
|
.getSearchRequestParsers();
|
||||||
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(
|
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(
|
||||||
logger, parser, SearchType.DEFAULT, true, "your_legacy_lang", ParseFieldMatcher.STRICT, searchRequestParsers);
|
logger, parser, SearchType.DEFAULT, ParseFieldMatcher.STRICT, searchRequestParsers);
|
||||||
Map<String, Object> parsedResult = XContentHelper.convertToMap(result.getSearchSource(), true).v2();
|
Map<String, Object> 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:
|
// 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"));
|
assertThat(XContentMapValues.extractValue("query.script.script.lang", parsedResult), equalTo("your_legacy_lang"));
|
||||||
|
@ -150,7 +150,7 @@ public class SearchInputTests extends ESIntegTestCase {
|
|||||||
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, WatcherClientProxy.of(client()),
|
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, WatcherClientProxy.of(client()),
|
||||||
searchParsers, scriptService());
|
searchParsers, scriptService());
|
||||||
|
|
||||||
SearchInput searchInput = factory.parseInput("_id", parser, false);
|
SearchInput searchInput = factory.parseInput("_id", parser);
|
||||||
assertEquals(SearchInput.TYPE, searchInput.type());
|
assertEquals(SearchInput.TYPE, searchInput.type());
|
||||||
assertThat(searchInput.getTimeout(), equalTo(timeout));
|
assertThat(searchInput.getTimeout(), equalTo(timeout));
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||||||
SearchRequestParsers searchRequestParsers = internalCluster().getInstance(SearchRequestParsers.class);
|
SearchRequestParsers searchRequestParsers = internalCluster().getInstance(SearchRequestParsers.class);
|
||||||
SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, WatcherClientProxy.of(client()),
|
SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, WatcherClientProxy.of(client()),
|
||||||
searchRequestParsers, scriptService());
|
searchRequestParsers, scriptService());
|
||||||
ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser, false);
|
ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser);
|
||||||
|
|
||||||
assertThat(executable, notNullValue());
|
assertThat(executable, notNullValue());
|
||||||
assertThat(executable.type(), is(SearchTransform.TYPE));
|
assertThat(executable.type(), is(SearchTransform.TYPE));
|
||||||
|
@ -123,7 +123,7 @@ public class ChainTransformTests extends ESTestCase {
|
|||||||
|
|
||||||
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ExecutableChainTransform executable = transformParser.parseExecutable("_id", parser, false);
|
ExecutableChainTransform executable = transformParser.parseExecutable("_id", parser);
|
||||||
assertThat(executable, notNullValue());
|
assertThat(executable, notNullValue());
|
||||||
assertThat(executable.transform().getTransforms(), notNullValue());
|
assertThat(executable.transform().getTransforms(), notNullValue());
|
||||||
assertThat(executable.transform().getTransforms(), hasSize(4));
|
assertThat(executable.transform().getTransforms(), hasSize(4));
|
||||||
@ -201,7 +201,7 @@ public class ChainTransformTests extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
return new Transform(parser.text());
|
return new Transform(parser.text());
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ public class ChainTransformTests extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
assert parser.currentToken() == XContentParser.Token.START_OBJECT;
|
||||||
XContentParser.Token token = parser.nextToken();
|
XContentParser.Token token = parser.nextToken();
|
||||||
assert token == XContentParser.Token.END_OBJECT;
|
assert token == XContentParser.Token.END_OBJECT;
|
||||||
|
@ -154,7 +154,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||||||
|
|
||||||
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||||
parser.nextToken();
|
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"));
|
Script script = new Script(type, "_lang", "_script", singletonMap("key", "value"));
|
||||||
assertThat(transform.transform().getScript(), equalTo(script));
|
assertThat(transform.transform().getScript(), equalTo(script));
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||||||
|
|
||||||
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||||
parser.nextToken();
|
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")));
|
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());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ScriptTransform scriptTransform = transformFactory.parseTransform("_watch", parser, false);
|
ScriptTransform scriptTransform = transformFactory.parseTransform("_watch", parser);
|
||||||
Exception e = expectThrows(ScriptException.class, () -> transformFactory.createExecutable(scriptTransform));
|
Exception e = expectThrows(ScriptException.class, () -> transformFactory.createExecutable(scriptTransform));
|
||||||
assertThat(e.getMessage(), containsString(errorMessage));
|
assertThat(e.getMessage(), containsString(errorMessage));
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||||||
|
|
||||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
ScriptTransform scriptCondition = transformFactory.parseTransform("_watch", parser, false);
|
ScriptTransform scriptCondition = transformFactory.parseTransform("_watch", parser);
|
||||||
Exception e = expectThrows(IllegalArgumentException.class, () -> transformFactory.createExecutable(scriptCondition));
|
Exception e = expectThrows(IllegalArgumentException.class, () -> transformFactory.createExecutable(scriptCondition));
|
||||||
assertThat(e.getMessage(), containsString("script_lang not supported [not_a_valid_lang]"));
|
assertThat(e.getMessage(), containsString("script_lang not supported [not_a_valid_lang]"));
|
||||||
}
|
}
|
||||||
|
@ -345,10 +345,10 @@ public class WatchTests extends ESTestCase {
|
|||||||
|
|
||||||
// parse in legacy mode:
|
// parse in legacy mode:
|
||||||
watch = watchParser.parse("_id", false, builder.bytes(), true);
|
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();
|
request = ((SearchInput) watch.input().input()).getRequest();
|
||||||
searchRequest = searchTemplateService.toSearchRequest(request);
|
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() {
|
private static Schedule randomSchedule() {
|
||||||
@ -437,13 +437,11 @@ public class WatchTests extends ESTestCase {
|
|||||||
|
|
||||||
private ConditionRegistry conditionRegistry() {
|
private ConditionRegistry conditionRegistry() {
|
||||||
Map<String, ConditionFactory> parsers = new HashMap<>();
|
Map<String, ConditionFactory> parsers = new HashMap<>();
|
||||||
parsers.put(AlwaysCondition.TYPE, (c, id, p, upgrade) -> AlwaysCondition.parse(id, p));
|
parsers.put(AlwaysCondition.TYPE, (c, id, p) -> AlwaysCondition.parse(id, p));
|
||||||
parsers.put(NeverCondition.TYPE, (c, id, p, upgrade) -> NeverCondition.parse(id, p));
|
parsers.put(NeverCondition.TYPE, (c, id, p) -> NeverCondition.parse(id, p));
|
||||||
parsers.put(ArrayCompareCondition.TYPE, (c, id, p, upgrade) -> ArrayCompareCondition.parse(c, id, p));
|
parsers.put(ArrayCompareCondition.TYPE, (c, id, p) -> ArrayCompareCondition.parse(c, id, p));
|
||||||
parsers.put(CompareCondition.TYPE, (c, id, p, upgrade) -> CompareCondition.parse(c, id, p));
|
parsers.put(CompareCondition.TYPE, (c, id, p) -> CompareCondition.parse(c, id, p));
|
||||||
String defaultLegacyScriptLanguage = ScriptSettings.getLegacyDefaultLang(settings);
|
parsers.put(ScriptCondition.TYPE, (c, id, p) -> ScriptCondition.parse(scriptService, id, p));
|
||||||
parsers.put(ScriptCondition.TYPE, (c, id, p, upgrade) -> ScriptCondition.parse(scriptService, id, p, upgrade,
|
|
||||||
defaultLegacyScriptLanguage));
|
|
||||||
return new ConditionRegistry(parsers, new ClockMock());
|
return new ConditionRegistry(parsers, new ClockMock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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'
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<Object[]> 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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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" }
|
|
@ -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" }
|
|
@ -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" }
|
|
@ -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 }
|
|
||||||
|
|
@ -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 }
|
|
Loading…
x
Reference in New Issue
Block a user