Watcher: Create module to test with painless scripting language
Also changed some documentation to use painless instead of groovy to get people used to it. Original commit: elastic/x-pack-elasticsearch@92a007cc0d
This commit is contained in:
parent
8aa48ffaff
commit
99cff6f3b9
|
@ -0,0 +1,15 @@
|
|||
apply plugin: 'elasticsearch.rest-test'
|
||||
|
||||
dependencies {
|
||||
testCompile project(path: ':x-plugins:elasticsearch:x-pack', configuration: 'runtime')
|
||||
testCompile project(path: ':modules:lang-painless', configuration: 'runtime')
|
||||
}
|
||||
|
||||
integTest {
|
||||
cluster {
|
||||
plugin 'x-pack', project(':x-plugins:elasticsearch:x-pack')
|
||||
setting 'script.inline', 'true'
|
||||
setting 'xpack.security.enabled', 'false'
|
||||
setting 'xpack.monitoring.enabled', 'false'
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.elasticsearch.test.rest.RestTestCandidate;
|
||||
import org.elasticsearch.test.rest.parser.RestTestParseException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class WatcherRestTestCase extends ESRestTestCase {
|
||||
|
||||
public WatcherRestTestCase(@Name("yaml") RestTestCandidate testCandidate) {
|
||||
super(testCandidate);
|
||||
}
|
||||
|
||||
@ParametersFactory
|
||||
public static Iterable<Object[]> parameters() throws IOException, RestTestParseException {
|
||||
return ESRestTestCase.createParameters(0, 1);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void startWatcher() throws Exception {
|
||||
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
||||
URL url = getClusterUrls()[0];
|
||||
HttpPut request = new HttpPut(new URI("http", null, url.getHost(), url.getPort(), "/_watcher/_start", null, null));
|
||||
client.execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopWatcher() throws Exception {
|
||||
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
||||
URL url = getClusterUrls()[0];
|
||||
HttpPut request = new HttpPut(new URI("http", null, url.getHost(), url.getPort(), "/_watcher/_stop", null, null));
|
||||
client.execute(request);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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.RestTestCandidate;
|
||||
|
||||
/** Runs rest tests against external cluster */
|
||||
public class WatcherWithPainlessIT extends WatcherRestTestCase {
|
||||
|
||||
public WatcherWithPainlessIT(RestTestCandidate testCandidate) {
|
||||
super(testCandidate);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
---
|
||||
"Test execute watch api":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
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" : "input.ctx.payload.hits.total > 1",
|
||||
"lang" : "painless"
|
||||
}
|
||||
},
|
||||
"actions" : {
|
||||
"email_admin" : {
|
||||
"email" : {
|
||||
"to" : "someone@domain.host.com",
|
||||
"subject" : "404 recently encountered"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
- match: { _id: "my_exe_watch" }
|
||||
|
||||
- do:
|
||||
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" }
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
"Test execute watch api with minimal body":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
watcher.put_watch:
|
||||
id: "my_logging_watch"
|
||||
body: >
|
||||
{
|
||||
"trigger" : {
|
||||
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
|
||||
},
|
||||
"input" : {
|
||||
"simple" : {
|
||||
"count" : 1
|
||||
}
|
||||
},
|
||||
"condition" : {
|
||||
"script" : {
|
||||
"inline" : "input.ctx.payload.count == 1",
|
||||
"lang" : "painless"
|
||||
}
|
||||
},
|
||||
"actions" : {
|
||||
"logging" : {
|
||||
"logging" : {
|
||||
"text" : "foobar"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
- match: { _id: "my_logging_watch" }
|
||||
|
||||
- do:
|
||||
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" }
|
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
"Test execute watch api with an inline watch":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
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" : "input.ctx.payload.hits.total > 1",
|
||||
"lang" : "painless"
|
||||
}
|
||||
},
|
||||
"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" }
|
Loading…
Reference in New Issue