execute-watch.asciidoc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --
  2. :api: execute-watch
  3. :request: ExecuteWatchRequest
  4. :response: ExecuteWatchResponse
  5. --
  6. [role="xpack"]
  7. [id="{upid}-{api}"]
  8. === Execute watch API
  9. The execute watch API allows clients to immediately execute a watch, either one
  10. that has been previously added via the {ref}/watcher-api-put-watch.html[create
  11. or update watch API] or inline as part of the request.
  12. [id="{upid}-{api}-request-by-id"]
  13. ==== Execute by id
  14. Submit the following request to execute a previously added watch:
  15. ["source","java",subs="attributes,callouts,macros"]
  16. ---------------------------------------------------
  17. include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id]
  18. ---------------------------------------------------
  19. <1> Alternative input for the watch to use in json format
  20. <2> Set the mode for action "action1" to SIMULATE
  21. <3> Record this execution in watcher history
  22. <4> Execute the watch regardless of the watch's condition
  23. <5> Set the trigger data for the watch in json format
  24. <6> Enable debug mode
  25. [id="{upid}-{api}-response-by-id"]
  26. ==== Execute by id response
  27. The returned `Response` contains details of the execution:
  28. ["source","java",subs="attributes,callouts,macros"]
  29. ---------------------------------------------------
  30. include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-response]
  31. ---------------------------------------------------
  32. <1> The record ID for this execution
  33. <2> The execution response as a java `Map`
  34. <3> Extract information from the response map using `ObjectPath`
  35. [id="{upid}-{api}-response-by-id-async"]
  36. ==== Asynchronous execution by id
  37. This request can be executed asynchronously:
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-async]
  41. --------------------------------------------------
  42. <1> The `ExecuteWatchRequest` to execute and the `ActionListener` to use when
  43. the execution completes
  44. The asynchronous method does not block and returns immediately. Once it is
  45. completed the `ActionListener` is called back using the `onResponse` method
  46. if the execution successfully completed or using the `onFailure` method if
  47. it failed.
  48. A typical listener for `ExecuteWatchResponse` looks like:
  49. ["source","java",subs="attributes,callouts,macros"]
  50. --------------------------------------------------
  51. include-tagged::{doc-tests-file}[x-pack-execute-watch-by-id-execute-listener]
  52. --------------------------------------------------
  53. <1> Called when the execution is successfully completed. The response is
  54. provided as an argument
  55. <2> Called in case of failure. The raised exception is provided as an argument
  56. [id="{upid}-{api}-request-inline"]
  57. ==== Execute inline
  58. Submit the following request to execute a watch defined as part of the request:
  59. ["source","java",subs="attributes,callouts,macros"]
  60. ---------------------------------------------------
  61. include-tagged::{doc-tests-file}[x-pack-execute-watch-inline]
  62. ---------------------------------------------------
  63. <1> Alternative input for the watch to use in json format
  64. <2> Set the mode for action "action1" to SIMULATE
  65. <3> Execute the watch regardless of the watch's condition
  66. <4> Set the trigger data for the watch in json format
  67. <5> Enable debug mode
  68. Note that inline watches cannot be recorded.
  69. The response format and asynchronous execution methods are the same as for the
  70. Execute Watch by ID API.