Commit Graph

405 Commits

Author SHA1 Message Date
Brian Murphy 6e0cabac62 [LOGGING] Log an error message when we fail to parse a `Watch` or `WatchRecord`
If we failed to parse a `Watch` or `WatchRecord` at startup we currently get stuck as this behaviour is undefined.
This commit just adds some logging so we can tell that this is what happened.

Original commit: elastic/x-pack-elasticsearch@aa6d95c172
2015-04-16 14:38:33 -04:00
Martijn van Groningen 6309d2b5d3 changed the order in which the interval services are stopped when watcher stops.
Original commit: elastic/x-pack-elasticsearch@8092a76aa4
2015-04-15 09:05:06 +02:00
uboness 13573d6c6d Cleanup and Refactoring of the actions
* Split the action into two constructs: `Action` and `ExecutableAction`. The former holds all the action configuration, the latter can execute the action based on that configuration (an executable action holds an action)
 - This the code clearer to understand and maintain.
 - This also enabled to pull some common implementation code into the `ExecutableAction` and by that reduce the implementation details of each executable to the minimum required.

* Also, extracted teh `Action.Parser` to its own top level class, and renamed it to - `ActionFactory`. The main thing that the parser does is: 1) delegate to the parsing to the `Action` class, 2) construct & wire up the `ExecutableAction`.

* Cleaned up and aligned the log messages across all actions. Introduced
 - introduced parameterized exceptions (now the exception messages are constructed exactly like that log messages - using `{}` params)
 - Introduced the notion of `Wid` - Watch (execution) ID`. Now the `WatchExecutionContext` and the `WatchRecord` hold this construct as their ID (instead of an opaque string). The Wid has a well defined structure where it's prefixed with the watch id. This is very helpful to provide context to parsing the different constructs (actions in our case) as when parsing error occurs we can point directly to the place were we found the error (ie. watch id, record id and action id).

* With the introduction of `Action`, we no longer need the `SourceBuilder` for actions. Instead, we have `Action.Builder` that help you build actions. This is much more intuitive from the client perspective.

Original commit: elastic/x-pack-elasticsearch@df22da4e1f
2015-04-14 17:16:47 -07:00
Brian Murphy 8c87cb0728 Add test for invalid license.
This change adds a new test class that runs the REST tests with the license disabled.
It checks the error message to make sure that all api access is blocked from all the apis we normally test.

Fixes elastic/elasticsearch#193

Original commit: elastic/x-pack-elasticsearch@a70de9b7a7
2015-04-14 13:57:55 -04:00
Brian Murphy 9b1d8fd3e6 Fix NPE in EmailTemplate
EmailTemplate was passing replyTo to all calls to templatesToAddressList

Original commit: elastic/x-pack-elasticsearch@5ecc05e3f7
2015-04-13 12:30:57 -04:00
Brian Murphy 05dbbbdc48 Fix silent failure to parse valid script condition.
`
{
  "script" : "<script>"
}
`
Should be a valid script condition. This was silently failing to parse creating invalid watches in the system that could not be executed or interacted with except via DELETE.
Added a test for this as well.

Fixes elastic/elasticsearch#191

Original commit: elastic/x-pack-elasticsearch@25ed27bf2e
2015-04-13 11:59:41 -04:00
uboness 76ac647610 Cleanup of templates
- Introduced `TemplateEngine` and its only implementation `MustacheTemplateEngine`
- Change `Template` to only hold the template config.. the rendering is now done by the engine
- Introduced `EmailTemplate` that can render itself to an `Email` (given an engine and model)
- Renamed `TemplatedHttpRequest` to `HttpRequestTemplate` and it has a `render` method that given a model and an engine it creates an `HttpRequest` construct.
 - also fixed a bug where when the http request is build, the configured scheme wasn't set.
- cleaned up `HttpRequest` - made it immutable and now we use a builder to build it.
 - also fixed a bug in `HttpRequest` where the xcontent didn't render the scheme
- Got rid of all old template implementations... also, parsing a template is now simply `Template.parse(...)` (no need for a special `TemplateParser`.
- While at it, change the action builder to only deal with actions and not know anything about the action id. The id is now passed to the watch builder directly when adding an action

Original commit: elastic/x-pack-elasticsearch@1a7acc5868
2015-04-12 21:50:41 +02:00
Brian Murphy 5a8287e3db [TEST] Change from IntervalSchedule to CronSchedule.
Original commit: elastic/x-pack-elasticsearch@039a64477a
2015-04-10 20:08:11 -04:00
Brian Murphy 053abfa8fb Force timewarp mode on ManualExecutionTests
Original commit: elastic/x-pack-elasticsearch@cc3d33a53b
2015-04-10 19:47:13 -04:00
Brian Murphy e94f62b298 Make sure watcher is started before running the test.
Original commit: elastic/x-pack-elasticsearch@c1d081fd10
2015-04-10 19:23:32 -04:00
Brian Murphy b70bdb2b89 Fix error message when email fails to send.
Closes elastic/elasticsearch#195

Original commit: elastic/x-pack-elasticsearch@7256a32505
2015-04-10 19:05:18 -04:00
Brian Murphy 3e9c109079 This commit contains a major refactoring to some of the core constructs in watcher.
- What used to be the `HistoryService` is not named `ExecutionService`. In fact, it always was an execution context and was simply named wrong and place in the wrog place in the code.

- A new `execution` package was created, to contain all execution related contsructs which includes the new `ExecutionService`, `WatchExecutionContext`, `WatchExecutor`, `InternalWatchExecutor`.

- The `WatchExecutionContext` role in the execution process was extended to also enable it to "control" the execution. "control" in the sence that it can now provide default results to some of the contructs (for example, it can provide a default input and by that skip the execution of the input). Also, it enables simulating actions (more bellow).

- There are two implementations now of the `WatchExecutionContext`. A `TriggeredExecutionContext` which is used when the trigger service triggers the execution of a watch. And `ManualExecutionContext` enabling to manually execute a watch. The latter, can be configured such that different phases in the normal executions of the watch can be skipped. This is great for simulating a watch execution, that is, executing a watch without actually fully executing the actions (e.g. create the emails that the email action would have normally send, but without actually sending it). Both of these new context implementations also sit in the new `execution` package.

- With the changes described above, the actions now consult the execution context before actually performing their tasks. If the execution context indicates that the action should run in a "simulated" mode, the action will semi execute and return a `Simulated` result. Each action type defines what is "simulated mode" for it. For example, the email action creates the email and renders all its templats but doesn't actually send it, the returned `Email.Simulated` result will contain the email that would have been sent if it was running under normal conditions (non-simulated mode). The `index` action, doesn't actually indexes anything (just creating the index request that would have been executed), and the `webhook` action only creates the HTTP request but doesn't actually send it.

- A new `execute` API was introduced that utilizes all of the above and enables to manually execute registered watches. The API provides all the tools to control what actions are simulated and enables skipping the execution of the watch `input` and `condition`. By default it also skip the recording of the execution in the watch history (though this can be enabled if desired). This API is exposed both by the Java `WatcherClient` and via a dedicated REST endpoint. (documentation around this new API was added as well)

Closes elastic/elasticsearch#149

Original commit: elastic/x-pack-elasticsearch@ee8fe0490a
2015-04-10 18:02:48 -04:00
uboness 7676347bb4 Merge pull request elastic/elasticsearch#206 from mrsolo/fix/spelling
Fixed minor spelling errors in exception messages

Original commit: elastic/x-pack-elasticsearch@ba9be34f23
2015-04-10 21:09:15 +02:00
Bill Hwang 8242e25cde Fixed minor spelling errors in exception messages
Original commit: elastic/x-pack-elasticsearch@7b9294e320
2015-04-10 11:58:33 -07:00
uboness 303616b415 [temp-fix] disabled timewarp mode for WatchCrudTests
something seems to be broken... either in the integration test infra or somewhere else.. .investigation required

Original commit: elastic/x-pack-elasticsearch@c27bc41ef4
2015-04-10 15:17:24 +02:00
uboness 92c8565af1 Fixed NPE when GETing a watch that doesn't exist
- Added watch CRUD tests + cleanup
- Changed and aligned terminology across the board. No more "watch name".. from now on we'll refer to it as "watch id" (aligned with the public APIs). Also the templates now refer to `"{{ctx.watch_id}}"` (instead of `"{{ctx.watch_name}}"`)
- cleaned up the Response constructs (removed dependency on index/delete/get responses)

Fixes elastic/elasticsearch#202

Original commit: elastic/x-pack-elasticsearch@3296a69128
2015-04-10 10:54:19 +02:00
uboness cfc8b81cea [tool] Added a `croneval` command line tool
Super useful when dealing with the `cron` schedule. It enables to:

1. validate a cron expression. If the cron expression is incorrect it will try to output a descriptive/guiding error message
2. show future times in which the cron expression will be triggered (based on the current time)

When deployed, once can access this tool from ES_HOME by `bin/watcher/croneval`

Also updated the docs

Original commit: elastic/x-pack-elasticsearch@2666c32a69
2015-04-09 10:00:27 +02:00
Brian Murphy b2586bc7c1 ShieldException -> WatcherException
ParseException should extend WatcherException not ShieldException.

Original commit: elastic/x-pack-elasticsearch@340f5b6125
2015-04-08 17:59:53 -04:00
Martijn van Groningen 7981075f05 small cleanup
Original commit: elastic/x-pack-elasticsearch@90c60d2cbe
2015-04-08 08:45:36 +02:00
Brian Murphy 2127373bb2 Fix LicenseIntegrationTest rebase fail
Original commit: elastic/x-pack-elasticsearch@e4e1d56cd8
2015-04-07 20:07:21 -04:00
Brian Murphy 31fbbcfc9a Add support for testing all REST endpoints.
This change adds support for testing all watcher REST endpoints.
It also updates the api docs to be current with the latest code.
Change GetWatchResponse to only have the information in needs
GetWatchResponse used to contain a GetResponse this is not needed. Now it just contains the needed fields.

Closes elastic/elasticsearch#35

Original commit: elastic/x-pack-elasticsearch@905c5da318
2015-04-07 19:47:04 -04:00
uboness 4b4c08af16 Fixed NoMasterNodeTests with disabled license failure
Original commit: elastic/x-pack-elasticsearch@ffd4fbea2c
2015-04-08 01:37:21 +02:00
uboness 4fcbbea14f Added license integration
- When the license is disabled, all actions of all watches are throttled, and all watcher APIs are blocked.
- before license expiry we're logging warning messages to the standard log file.
- Added a check on startup verifying the installed license plugin confirms to the min compatibility requirement of watcher
- Added a check on startup verifying the installed shield plugin (if one is installed) confirms to the min compatibility requirement of watcher
- Fixed a bug in simple input deserialization where it expected a `payload` field that should be there.
- Fixed a bug in `WatcherServiceResponse` where the acknowledged state wasn't de/serialized

Closes elastic/elasticsearch#30

Original commit: elastic/x-pack-elasticsearch@35dcaf4feb
2015-04-08 00:17:16 +02:00
Martijn van Groningen 0f43a5933f Test: fix timing issues in testConditionSearchWithSource() and testConditionSearchWithIndexedTemplate() tests.
Original commit: elastic/x-pack-elasticsearch@79e5859dcf
2015-04-07 20:04:28 +02:00
Martijn van Groningen 4c6d2e7b39 Build: removed -XX:MaxPermSize option from pom.xml
Support for this option has been removed in Java 8 and the build works without it with Java 7 too.

Original commit: elastic/x-pack-elasticsearch@b1ba8893f2
2015-04-07 13:41:51 +02:00
uboness 8d71337be5 Added a "logging" action
Mainly useful for testing & debugging, but might be even useful as an actual action in production.

(for now, we won't document it)

Original commit: elastic/x-pack-elasticsearch@726049cece
2015-04-07 03:29:14 +02:00
uboness f9004eed31 changed the actions format and added the notion of an action id
- actions are not identified by a unique id. The actions in a "watch" definition are now keyed (instead of an array)
- the `ActionWrapper` is now a construct that holds: and action, the id of the action and optionally a transform
- the `webhook` action is now structured based on the templated http request it holds (no need for extra `request` element there`
- the `webhook` reponse holds the http response (not the `status` and `body` directly)
- the action builders now accept an `id` when created
- introduced `WatchSourceBuilders` for quickly access various source builders
- introduced `Template.SourceBuilder` to help building a template
- changed templated http request builder to accept template source builders (instead of templates directly)
- changed `HttpResponse` to accept the body as a `ByteReference` in the ctor (this construct used to be in an inconsistent state holding an input stream that could have already been read)

Original commit: elastic/x-pack-elasticsearch@296350b6a8
2015-04-07 00:18:02 +02:00
uboness 46e27cf517 Small fixes
- Introduced `SearchRequestParseException`
- fixed typo

Original commit: elastic/x-pack-elasticsearch@618208036e
2015-04-06 19:18:14 +02:00
uboness be5fefc6dd Enhanced search request de/serialization
- now enables defining `types` (for document types)
- enables defining `types` and `indices` as comma-delimited strings (not just string arrays)
- aligned the parsing in `WatcherUtils` with the way we're parsing xcontent across the board (e.g. using `ParseField`)
- Added additional unit test to test deserialization

Original commit: elastic/x-pack-elasticsearch@5491b85f75
2015-04-06 14:57:11 +02:00
uboness a1cda57863 Enable the script transform return any value
This commit enables the script transform return any value. If the value is of type `Map` we'll just use it as the payload itself. Otherwise (any other value type) we'll take that value and put it in a map under the `"_value"` key, and that map will be the new payload.

This will simplify writing scripts (as it doesn't require the script to build a map)

Original commit: elastic/x-pack-elasticsearch@73fab7dc2b
2015-04-06 14:53:26 +02:00
Martijn van Groningen e9d2a38d3a Test: Now that automatic refresh interval has been increased to 5m we need to invoke api refreshes from tests.
Original commit: elastic/x-pack-elasticsearch@71a12c3365
2015-04-03 10:41:26 +02:00
Martijn van Groningen d522156e40 Now that automatic refresh interval has been increased to 5m we need to invoke api refreshes from tests.
Original commit: elastic/x-pack-elasticsearch@5106e6e21b
2015-04-03 10:26:38 +02:00
Martijn van Groningen 500b86577e Changed refresh interval for .watch .watch_history* indices from 1 second to 5 minutes.
Closes elastic/elasticsearch#151

Original commit: elastic/x-pack-elasticsearch@5147d635c2
2015-04-03 09:52:04 +02:00
Brian Murphy f12ead6a4c Change SearchTypes to be `QUERY_THEN_FETCH`
This closes elastic/elasticsearch#165

Original commit: elastic/x-pack-elasticsearch@b7642cf33d
2015-04-02 19:15:09 -04:00
Brian Murphy b85c0ca1a7 Fix null pointer in writing email action.
This commit fixes two issues.
1. The actual emails that were being sent after getting the defaults applied were not being returned as part of EmailSent
2. There was a possible NPE when writing an `Email` if from or to was null.

Closes elastic/elasticsearch#147

Original commit: elastic/x-pack-elasticsearch@0468280090
2015-04-02 18:09:33 -04:00
Brian Murphy 27f6239fe9 Add HttpRequest support to webhook action.
Also add docs for HttpRequest support in webhook action

Closes elastic/elasticsearch#156

Original commit: elastic/x-pack-elasticsearch@3e1e3dbe95
2015-04-02 15:08:56 -04:00
Martijn van Groningen feb745763b Added a `scheme` option to the `http` input that supports the values http or https.
Closes elastic/elasticsearch#174

Original commit: elastic/x-pack-elasticsearch@9ad7665b66
2015-04-02 16:56:34 +02:00
Martijn van Groningen a778f1978d improved benchmark
Original commit: elastic/x-pack-elasticsearch@70b2a8a042
2015-04-02 14:43:15 +02:00
Martijn van Groningen 17bc9442e1 test: run without shield integration
Original commit: elastic/x-pack-elasticsearch@dea9889523
2015-04-01 23:37:11 +02:00
Brian Murphy 5e57389c11 Add webhook and index actions tests.
This commit adds tests for the webhook and index actions.
Also adds docs for the webhook and index actions and fixes url escaping of webhook action urls.

Original commit: elastic/x-pack-elasticsearch@b70435b198
2015-04-01 16:18:37 -04:00
Martijn van Groningen 9bb38fa4e1 Test: make sure index `test` exists
Original commit: elastic/x-pack-elasticsearch@4c4b7af85d
2015-04-01 21:37:08 +02:00
Martijn van Groningen 46f75d8fa1 Test: add AWI#enableShield() to decide if shield should run and let AWI#shieldEnabled() return whether shield is running in the test cluster
Original commit: elastic/x-pack-elasticsearch@698900d002
2015-04-01 20:47:39 +02:00
Martijn van Groningen 54380478e5 Test: also run shield with http input integration test
Original commit: elastic/x-pack-elasticsearch@6c2dbc75e1
2015-04-01 19:25:23 +02:00
Martijn van Groningen 3a37ebca41 Test: make sure a refresh has ran.
Original commit: elastic/x-pack-elasticsearch@db9a8c417c
2015-04-01 17:45:36 +02:00
Martijn van Groningen efb6ae8e1f Added `extract` option to filter keys out of the `search` and `http` input.
Via the `extract` option an array of keys can be defined that will be extracted from the input response in a streaming manner and used as payload instead of the entire input response.

http example:

```json
{
  "input" : {
    "http" : {
      "request" : {
         "host" : "host.domain",
         "port" : 9200,
         "path" : "/idx/_search"
      },
      "extract" : ["hits.hits.total", "aggregations.my_agg"]
    }
  }
  ...
}
```

search example:

```json
{
  "input" : {
    "search" : {
      "request" : {
         "indices" : [ "idx" ],
          "body" : {
             "query" : { "match_all" : {} }
          }
       },
       "extract" : ["hits.hits.total", "aggregations.my_agg"]
    }
  }
  ...
}
```

Closes elastic/elasticsearch#167

Original commit: elastic/x-pack-elasticsearch@437c35698b
2015-04-01 13:12:12 +02:00
Brian Murphy 3a09914b67 Add support for rest tests
This commit adds support for rest tests using the same yaml and json formatting as for core elasticsearch.
Also added is support for shield in the rest tests.

Original commit: elastic/x-pack-elasticsearch@bbeb9c0fc9
2015-03-31 17:25:48 -04:00
Martijn van Groningen baf0901b3a test: adjusted find available port loop
Original commit: elastic/x-pack-elasticsearch@ae44c570c0
2015-03-30 20:50:14 +02:00
Brian Murphy 06efbf1481 Actually the test and don't call start twice on the same server.
Original commit: elastic/x-pack-elasticsearch@3b994ef9e7
2015-03-30 14:40:05 -04:00
Brian Murphy 72d2f5174e Fix HttpClientTest
If port 9200 isn't available inc the port and try again until we reach 9300.

Original commit: elastic/x-pack-elasticsearch@90ca05544f
2015-03-30 14:22:26 -04:00
Martijn van Groningen e00bb69982 Added http input.
The http input allows to let any http interface be the input for a watch.
The http input can be configured with the following options:
* `method` - Optional http method. (default to GET)
* `host` - The host of the http service.
* `port` - The port of the http service.
* `path` - The url path.
* `params` - Optional url query string options.
* `header` - Optional http header.
* `auth` - Optional authentication http heads.
* `body` - Optional body

The response of the http request is expected to be valid json.

Closes elastic/elasticsearch#157

Original commit: elastic/x-pack-elasticsearch@0b1f122615
2015-03-30 18:32:06 +02:00