close-job.asciidoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [[java-rest-high-x-pack-ml-close-job]]
  2. === Close Job API
  3. The Close Job API provides the ability to close {ml} jobs in the cluster.
  4. It accepts a `CloseJobRequest` object and responds
  5. with a `CloseJobResponse` object.
  6. [[java-rest-high-x-pack-ml-close-job-request]]
  7. ==== Close Job Request
  8. A `CloseJobRequest` object gets created with an existing non-null `jobId`.
  9. ["source","java",subs="attributes,callouts,macros"]
  10. --------------------------------------------------
  11. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-close-job-request]
  12. --------------------------------------------------
  13. <1> Constructing a new request referencing existing job IDs
  14. <2> Optionally used to close a failed job, or to forcefully close a job
  15. which has not responded to its initial close request.
  16. <3> Optionally set to ignore if a wildcard expression matches no jobs.
  17. (This includes `_all` string or when no jobs have been specified)
  18. <4> Optionally setting the `timeout` value for how long the
  19. execution should wait for the job to be closed.
  20. [[java-rest-high-x-pack-ml-close-job-execution]]
  21. ==== Execution
  22. The request can be executed through the `MachineLearningClient` contained
  23. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  24. ["source","java",subs="attributes,callouts,macros"]
  25. --------------------------------------------------
  26. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-close-job-execute]
  27. --------------------------------------------------
  28. <1> `isClosed()` from the `CloseJobResponse` indicates if the job was successfully
  29. closed or not.
  30. [[java-rest-high-x-pack-ml-close-job-execution-async]]
  31. ==== Asynchronous Execution
  32. The request can also be executed asynchronously:
  33. ["source","java",subs="attributes,callouts,macros"]
  34. --------------------------------------------------
  35. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-close-job-execute-async]
  36. --------------------------------------------------
  37. <1> The `CloseJobRequest` to execute and the `ActionListener` to use when
  38. the execution completes
  39. The method does not block and returns immediately. The passed `ActionListener` is used
  40. to notify the caller of completion. A typical `ActionListener` for `CloseJobResponse` may
  41. look like
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-close-job-listener]
  45. --------------------------------------------------
  46. <1> `onResponse` is called back when the action is completed successfully
  47. <2> `onFailure` is called back when some unexpected error occurs