-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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: Adding ML Job stats #33183
Merged
benwtrent
merged 19 commits into
elastic:master
from
benwtrent:feature/ml-hlrc-job-stats
Sep 1, 2018
Merged
HLRC: Adding ML Job stats #33183
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e2d0daa
HLRC: Adding pojos for get job stats
benwtrent cefe9d3
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent 8a7feb4
HLRC: Adding job stats pojos
benwtrent f55e01e
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent cc602fe
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent de52ab2
HLRC: ML job stats
benwtrent 54d56a7
Merge branch 'master' into feature/ml-hlrc-job-stats-2
benwtrent c8d3f5a
Minor syntax changes and adding license headers
benwtrent da0c1bd
minor comment change
benwtrent 5254cc1
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent 55f543d
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent 79dd816
Moving to client package, minor changes
benwtrent 9f2bc9e
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent a6512a4
Addressing PR comments
benwtrent 2c9e231
removing bad sleep
benwtrent b761884
addressing minor comment around test methods
benwtrent a45fbec
adding toplevel random fields for tests
benwtrent fdf2aa0
addressing minor review comments
benwtrent 401223b
Merge branch 'master' into feature/ml-hlrc-job-stats
benwtrent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetJobsStatsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.client.ml.job.config.Job; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
|
||
/** | ||
* Request object to get {@link org.elasticsearch.client.ml.job.stats.JobStats} by their respective jobIds | ||
* | ||
* `_all` explicitly gets all the jobs' statistics in the cluster | ||
* An empty request (no `jobId`s) implicitly gets all the jobs' statistics in the cluster | ||
*/ | ||
public class GetJobsStatsRequest extends ActionRequest implements ToXContentObject { | ||
|
||
public static final ParseField ALLOW_NO_JOBS = new ParseField("allow_no_jobs"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetJobsStatsRequest, Void> PARSER = new ConstructingObjectParser<>( | ||
"get_jobs_stats_request", a -> new GetJobsStatsRequest((List<String>) a[0])); | ||
|
||
static { | ||
PARSER.declareField(ConstructingObjectParser.constructorArg(), | ||
p -> Arrays.asList(Strings.commaDelimitedListToStringArray(p.text())), | ||
Job.ID, ObjectParser.ValueType.STRING_ARRAY); | ||
PARSER.declareBoolean(GetJobsStatsRequest::setAllowNoJobs, ALLOW_NO_JOBS); | ||
} | ||
|
||
private static final String ALL_JOBS = "_all"; | ||
|
||
private final List<String> jobIds; | ||
private Boolean allowNoJobs; | ||
|
||
/** | ||
* Explicitly gets all jobs statistics | ||
* | ||
* @return a {@link GetJobsStatsRequest} for all existing jobs | ||
*/ | ||
public static GetJobsStatsRequest getAllJobsStatsRequest(){ | ||
return new GetJobsStatsRequest(ALL_JOBS); | ||
} | ||
|
||
GetJobsStatsRequest(List<String> jobIds) { | ||
if (jobIds.stream().anyMatch(Objects::isNull)) { | ||
throw new NullPointerException("jobIds must not contain null values"); | ||
} | ||
this.jobIds = new ArrayList<>(jobIds); | ||
} | ||
|
||
/** | ||
* Get the specified Job's statistics via their unique jobIds | ||
* | ||
* @param jobIds must be non-null and each jobId must be non-null | ||
*/ | ||
public GetJobsStatsRequest(String... jobIds) { | ||
this(Arrays.asList(jobIds)); | ||
} | ||
|
||
/** | ||
* All the jobIds for which to get statistics | ||
*/ | ||
public List<String> getJobIds() { | ||
return jobIds; | ||
} | ||
|
||
public Boolean isAllowNoJobs() { | ||
return this.allowNoJobs; | ||
} | ||
|
||
/** | ||
* Whether to ignore if a wildcard expression matches no jobs. | ||
* | ||
* This includes `_all` string or when no jobs have been specified | ||
* | ||
* @param allowNoJobs When {@code true} ignore if wildcard or `_all` matches no jobs. Defaults to {@code true} | ||
*/ | ||
public void setAllowNoJobs(boolean allowNoJobs) { | ||
this.allowNoJobs = allowNoJobs; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobIds, allowNoJobs); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
GetJobsStatsRequest that = (GetJobsStatsRequest) other; | ||
return Objects.equals(jobIds, that.jobIds) && | ||
Objects.equals(allowNoJobs, that.allowNoJobs); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(Job.ID.getPreferredName(), Strings.collectionToCommaDelimitedString(jobIds)); | ||
if (allowNoJobs != null) { | ||
builder.field(ALLOW_NO_JOBS.getPreferredName(), allowNoJobs); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetJobsStatsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.client.ml.job.stats.JobStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
/** | ||
* Contains a {@link List} of the found {@link JobStats} objects and the total count found | ||
*/ | ||
public class GetJobsStatsResponse extends AbstractResultResponse<JobStats> { | ||
|
||
public static final ParseField RESULTS_FIELD = new ParseField("jobs"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetJobsStatsResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("jobs_stats_response", true, | ||
a -> new GetJobsStatsResponse((List<JobStats>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), JobStats.PARSER, RESULTS_FIELD); | ||
PARSER.declareLong(constructorArg(), COUNT); | ||
} | ||
|
||
GetJobsStatsResponse(List<JobStats> jobStats, long count) { | ||
super(RESULTS_FIELD, jobStats, count); | ||
} | ||
|
||
/** | ||
* The collection of {@link JobStats} objects found in the query | ||
*/ | ||
public List<JobStats> jobStats() { | ||
return results; | ||
} | ||
|
||
public static GetJobsStatsResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(results, count); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
GetJobsStatsResponse other = (GetJobsStatsResponse) obj; | ||
return Objects.equals(results, other.results) && count == other.count; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 name of this and the
GetJobRequest
needs to be consistent. Not sure if plural or singular is best. Potentially should also be consistent with the results (where I've been using plural). @droberts195 Any preference?