-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HLRC: ML Close Job #32943
HLRC: ML Close Job #32943
Conversation
HLRC: Adding ML Close Job API
Pinging @elastic/ml-core |
Pinging @elastic/es-core-infra |
return new CloseJobRequest(ALL_JOBS); | ||
} | ||
|
||
public CloseJobRequest(String jobId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we add a constructor that takes a List<String>
and make jobIds
final? As the job IDs is the required part of the request, I think replacing the setter with a constructor guides the user better towards making a valid request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, even better, we can have a single constructor that takes (String... jobIds)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that, I just tested and doing a close with an empty string is a valid request, it just does not do anything. This could indeed cause confusion and possibly latent bugs in a consumer's code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. I'll revisit the documentation after any changes that could result from the review.
Request request = new Request(HttpPost.METHOD_NAME, endpoint); | ||
|
||
RequestConverters.Params params = new RequestConverters.Params(request); | ||
params.putParam("force", Boolean.toString(closeJobRequest.isForce())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The need to pass these as params instead of serializing the request revealed a bug: we do not support sending these params as the request body for the close job API. It'd be nice to fix that. Then this converter can follow suit with all the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Cool, I will create a Github issue for that. It did seem kind of strange as this was the odd API endpoint out :).
@@ -166,4 +168,42 @@ public void openJobAsync(OpenJobRequest request, RequestOptions options, ActionL | |||
listener, | |||
Collections.emptySet()); | |||
} | |||
|
|||
/** | |||
* Closes Machine Learning Jobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Merge this into the next sentence? Something like Closes one or more Machine Learning jobs...
* | ||
* A closed job cannot receive data or perform analysis operations, but you can still explore and navigate results. | ||
* | ||
* @param request request containing jobIds and additional optional options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use jobIds
here. We refer to it as job_id
in the open job doc. Perhaps rephrase like request containing the
job_id for each job to close and additional optional options
. Hm, typing optional options
also felt funny. Perhaps remove optional
from both?
} | ||
|
||
/** | ||
* Closes Machine Learning Jobs asynchronously, notifies listener on completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comments as above.
|
||
public class CloseJobRequest extends ActionRequest { | ||
|
||
public static final String ALL_JOBS = "_all"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this private?
private List<String> jobIds = new ArrayList<>(); | ||
private TimeValue timeout; | ||
private boolean force; | ||
private boolean allowNoJobs = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make Boolean
and only serialize when not null. Also remove setting the default. The idea here is that by doing so we inherit the defaults of the backend without having to duplicate them in the client.
this.allowNoJobs = allowNoJobs; | ||
} | ||
|
||
public String getCommaDelimitedJobIdString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this really belongs in the request converter. It is the request logic that requires this bit of processing so we could simply call this utility method in the request conversion.
CloseJobRequest that = (CloseJobRequest) other; | ||
return Objects.equals(jobIds, that.jobIds) && | ||
Objects.equals(timeout, that.timeout) && | ||
allowNoJobs == that.allowNoJobs && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Objects.equals
for all once changed to potentially null references.
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CloseJobRequestTests extends ESTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be testing serialization here by extending AbstractXContentTestCase
. Unfortunately, that means we need to also write a parser for the request but it's worth it.
[[java-rest-high-x-pack-ml-close-job-request]] | ||
==== Close Job Request | ||
|
||
An `CloseJobRequest` object gets created with an existing non-null `jobId`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An
-> A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just left one more comment.
throw new NullPointerException("[jobId] must not be null"); | ||
} | ||
this.jobIds = new ArrayList<>(jobIds); | ||
CloseJobRequest(List<String> jobIds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As what we're actually storing is the list, I would make this constructor the leaf one. Then the varargs one can just call this(Arrays.asList(jobIds))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…e-types * elastic/master: (89 commits) Fix assertion in AbstractSimpleTransportTestCase (elastic#32991) [DOC] Splits role mapping APIs into separate pages (elastic#32797) HLRC: ML Close Job (elastic#32943) Generalize remote license checker (elastic#32971) Trim translog when safe commit advanced (elastic#32967) Fix an inaccuracy in the dynamic templates documentation. (elastic#32890) Logging: Use settings when building daemon threads (elastic#32751) All Translog inner closes should happen after tragedy exception is set (elastic#32674) HLREST: AwaitsFix ML Test Pass DiscoveryNode to initiateChannel (elastic#32958) Add mzn and dz to unsupported locales (elastic#32957) Use settings from the context in BootstrapChecks (elastic#32908) Update docs for node specifications (elastic#30468) HLRC: Forbid all Elasticsearch logging infra (elastic#32784) Only configure publishing if it's applied externally (elastic#32351) Fixes libs:dissect when in eclipse Protect ScriptedMetricIT test cases against failures on 0-doc shards (elastic#32959) (elastic#32968) [Kerberos] Add documentation for Kerberos realm (elastic#32662) Watcher: Properly find next valid date in cron expressions (elastic#32734) Fix some small issues in the getting started docs (elastic#30346) ...
* HLRC: Adding ML Close Job API HLRC: Adding ML Close Job API * reconciling request converters * Adding serialization tests and addressing PR comments * Changing constructor order
Adds the ML Close Job API to the HLRC.
Relates to #29827