-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: ML Adding get datafeed stats API #34271
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
Merged
benwtrent
merged 6 commits into
elastic:master
from
benwtrent:feature/hlrc-ml-datafeed-stats
Oct 4, 2018
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a8fb9c5
HLRC: ML Adding get datafeed stats API
benwtrent c27df74
Merge branch 'master' into feature/hlrc-ml-datafeed-stats
benwtrent 8702de3
addressing PR comments
benwtrent 57c7f14
fixing field exclusion filter
benwtrent db8fef9
removing unnecessary whitespace
benwtrent d45dd6b
Merge branch 'master' into feature/hlrc-ml-datafeed-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 hidden or 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 hidden or 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
147 changes: 147 additions & 0 deletions
147
...nt/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetDatafeedStatsRequest.java
This file contains hidden or 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,147 @@ | ||
/* | ||
* 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.datafeed.DatafeedConfig; | ||
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.ToXContent; | ||
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.datafeed.DatafeedStats} by their respective datafeedIds | ||
* | ||
* {@code _all} explicitly gets all the datafeeds' statistics in the cluster | ||
* An empty request (no {@code datafeedId}s) implicitly gets all the datafeeds' statistics in the cluster | ||
*/ | ||
public class GetDatafeedStatsRequest extends ActionRequest implements ToXContentObject { | ||
|
||
public static final ParseField ALLOW_NO_DATAFEEDS = new ParseField("allow_no_datafeeds"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetDatafeedStatsRequest, Void> PARSER = new ConstructingObjectParser<>( | ||
"get_datafeed_stats_request", a -> new GetDatafeedStatsRequest((List<String>) a[0])); | ||
|
||
static { | ||
PARSER.declareField(ConstructingObjectParser.constructorArg(), | ||
p -> Arrays.asList(Strings.commaDelimitedListToStringArray(p.text())), | ||
DatafeedConfig.ID, ObjectParser.ValueType.STRING_ARRAY); | ||
PARSER.declareBoolean(GetDatafeedStatsRequest::setAllowNoDatafeeds, ALLOW_NO_DATAFEEDS); | ||
} | ||
|
||
private static final String ALL_DATAFEEDS = "_all"; | ||
|
||
private final List<String> datafeedIds; | ||
private Boolean allowNoDatafeeds; | ||
|
||
/** | ||
* Explicitly gets all datafeeds statistics | ||
* | ||
* @return a {@link GetDatafeedStatsRequest} for all existing datafeeds | ||
*/ | ||
public static GetDatafeedStatsRequest getAllDatafeedStatsRequest(){ | ||
return new GetDatafeedStatsRequest(ALL_DATAFEEDS); | ||
} | ||
|
||
GetDatafeedStatsRequest(List<String> datafeedIds) { | ||
if (datafeedIds.stream().anyMatch(Objects::isNull)) { | ||
throw new NullPointerException("datafeedIds must not contain null values"); | ||
} | ||
this.datafeedIds = new ArrayList<>(datafeedIds); | ||
} | ||
|
||
/** | ||
* Get the specified Datafeed's statistics via their unique datafeedIds | ||
* | ||
* @param datafeedIds must be non-null and each datafeedId must be non-null | ||
*/ | ||
public GetDatafeedStatsRequest(String... datafeedIds) { | ||
this(Arrays.asList(datafeedIds)); | ||
} | ||
|
||
/** | ||
* All the datafeedIds for which to get statistics | ||
*/ | ||
public List<String> getDatafeedIds() { | ||
return datafeedIds; | ||
} | ||
|
||
public Boolean isAllowNoDatafeeds() { | ||
return this.allowNoDatafeeds; | ||
} | ||
|
||
/** | ||
* Whether to ignore if a wildcard expression matches no datafeeds. | ||
* | ||
* This includes {@code _all} string or when no datafeeds have been specified | ||
* | ||
* @param allowNoDatafeeds When {@code true} ignore if wildcard or {@code _all} matches no datafeeds. Defaults to {@code true} | ||
*/ | ||
public void setAllowNoDatafeeds(boolean allowNoDatafeeds) { | ||
this.allowNoDatafeeds = allowNoDatafeeds; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(datafeedIds, allowNoDatafeeds); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
GetDatafeedStatsRequest that = (GetDatafeedStatsRequest) other; | ||
return Objects.equals(datafeedIds, that.datafeedIds) && | ||
Objects.equals(allowNoDatafeeds, that.allowNoDatafeeds); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(DatafeedConfig.ID.getPreferredName(), Strings.collectionToCommaDelimitedString(datafeedIds)); | ||
if (allowNoDatafeeds != null) { | ||
builder.field(ALLOW_NO_DATAFEEDS.getPreferredName(), allowNoDatafeeds); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
...t/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetDatafeedStatsResponse.java
This file contains hidden or 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,89 @@ | ||
/* | ||
* 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.client.ml.datafeed.DatafeedStats; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
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 DatafeedStats} objects and the total count found | ||
*/ | ||
public class GetDatafeedStatsResponse extends AbstractResultResponse<DatafeedStats> { | ||
|
||
public static final ParseField RESULTS_FIELD = new ParseField("datafeeds"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetDatafeedStatsResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("get_datafeed_stats_response", | ||
true, | ||
a -> new GetDatafeedStatsResponse((List<DatafeedStats>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), DatafeedStats.PARSER, RESULTS_FIELD); | ||
PARSER.declareLong(constructorArg(), COUNT); | ||
} | ||
|
||
GetDatafeedStatsResponse(List<DatafeedStats> results, long count) { | ||
super(RESULTS_FIELD, results, count); | ||
} | ||
|
||
/** | ||
* The collection of {@link DatafeedStats} objects found in the query | ||
*/ | ||
public List<DatafeedStats> datafeedStats() { | ||
return results; | ||
} | ||
|
||
public static GetDatafeedStatsResponse 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; | ||
} | ||
|
||
GetDatafeedStatsResponse other = (GetDatafeedStatsResponse) obj; | ||
return Objects.equals(results, other.results) && count == other.count; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/datafeed/DatafeedState.java
This file contains hidden or 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,42 @@ | ||
/* | ||
* 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.datafeed; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Datafeed State POJO | ||
*/ | ||
public enum DatafeedState { | ||
|
||
STARTED, STOPPED, STARTING, STOPPING; | ||
|
||
public static final ParseField STATE = new ParseField("state"); | ||
|
||
public static DatafeedState fromString(String name) { | ||
return valueOf(name.trim().toUpperCase(Locale.ROOT)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
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.
Can
hashCode()
be moved into the parent classAbstractResultResponse
?Not an issue for this PR, just wondering