open-job.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [[java-rest-high-x-pack-ml-open-job]]
  2. === Open Job API
  3. The Open Job API provides the ability to open {ml} jobs in the cluster.
  4. It accepts a `OpenJobRequest` object and responds
  5. with a `OpenJobResponse` object.
  6. [[java-rest-high-x-pack-ml-open-job-request]]
  7. ==== Open Job Request
  8. An `OpenJobRequest` 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-open-job-request]
  12. --------------------------------------------------
  13. <1> Constructing a new request referencing an existing `jobId`
  14. <2> Optionally setting the `timeout` value for how long the
  15. execution should wait for the job to be opened.
  16. [[java-rest-high-x-pack-ml-open-job-execution]]
  17. ==== Execution
  18. The request can be executed through the `MachineLearningClient` contained
  19. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-open-job-execute]
  23. --------------------------------------------------
  24. <1> `isOpened()` from the `OpenJobResponse` indicates if the job was successfully
  25. opened or not.
  26. [[java-rest-high-x-pack-ml-open-job-execution-async]]
  27. ==== Asynchronous Execution
  28. The request can also be executed asynchronously:
  29. ["source","java",subs="attributes,callouts,macros"]
  30. --------------------------------------------------
  31. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-open-job-execute-async]
  32. --------------------------------------------------
  33. <1> The `OpenJobRequest` to execute and the `ActionListener` to use when
  34. the execution completes
  35. The method does not block and returns immediately. The passed `ActionListener` is used
  36. to notify the caller of completion. A typical `ActionListener` for `OpenJobResponse` may
  37. look like
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-open-job-listener]
  41. --------------------------------------------------
  42. <1> `onResponse` is called back when the action is completed successfully
  43. <2> `onFailure` is called back when some unexpected error occurs