-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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: Add ML get categories API #33465
Merged
edsavage
merged 6 commits into
elastic:master
from
edsavage:add-ml-get-categories-api-to-hlrc
Sep 11, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2986afc
HLRC: Add ML get categories API
edsavage 2eb8440
HLRC: ML get categories API - Java style fixes
edsavage 2911be3
HLRC: ML get categories API - Java style fixes
edsavage 02dba5b
Address review comments
edsavage 6162894
Optimization of integration test
edsavage 95f335b
Merge branch 'master' into add-ml-get-categories-api-to-hlrc
edsavage 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
128 changes: 128 additions & 0 deletions
128
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetCategoriesRequest.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,128 @@ | ||
/* | ||
* 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.client.ml.job.util.PageParams; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A request to retrieve categories of a given job | ||
*/ | ||
public class GetCategoriesRequest extends ActionRequest implements ToXContentObject { | ||
|
||
|
||
public static final ParseField CATEGORY_ID = new ParseField("category_id"); | ||
|
||
public static final ConstructingObjectParser<GetCategoriesRequest, Void> PARSER = new ConstructingObjectParser<>( | ||
"get_categories_request", a -> new GetCategoriesRequest((String) a[0])); | ||
|
||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), Job.ID); | ||
PARSER.declareLong(GetCategoriesRequest::setCategoryId, CATEGORY_ID); | ||
PARSER.declareObject(GetCategoriesRequest::setPageParams, PageParams.PARSER, PageParams.PAGE); | ||
} | ||
|
||
private final String jobId; | ||
private Long categoryId; | ||
private PageParams pageParams; | ||
|
||
/** | ||
* Constructs a request to retrieve category information from a given job | ||
* @param jobId id of the job from which to retrieve results | ||
*/ | ||
public GetCategoriesRequest(String jobId) { | ||
this.jobId = Objects.requireNonNull(jobId); | ||
} | ||
|
||
public String getJobId() { | ||
return jobId; | ||
} | ||
|
||
public PageParams getPageParams() { | ||
return pageParams; | ||
} | ||
|
||
public Long getCategoryId() { | ||
return categoryId; | ||
} | ||
|
||
/** | ||
* Sets the category id | ||
* @param categoryId the category id | ||
*/ | ||
public void setCategoryId(Long categoryId) { | ||
this.categoryId = categoryId; | ||
} | ||
|
||
/** | ||
* Sets the paging parameters | ||
* @param pageParams the paging parameters | ||
*/ | ||
public void setPageParams(PageParams pageParams) { | ||
this.pageParams = pageParams; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(Job.ID.getPreferredName(), jobId); | ||
if (categoryId != null) { | ||
builder.field(CATEGORY_ID.getPreferredName(), categoryId); | ||
} | ||
if (pageParams != null) { | ||
builder.field(PageParams.PAGE.getPreferredName(), pageParams); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetCategoriesRequest request = (GetCategoriesRequest) obj; | ||
return Objects.equals(jobId, request.jobId) | ||
&& Objects.equals(categoryId, request.categoryId) | ||
&& Objects.equals(pageParams, request.pageParams); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobId, categoryId, pageParams); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetCategoriesResponse.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,79 @@ | ||
/* | ||
* 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.job.results.CategoryDefinition; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A response containing the requested categories | ||
*/ | ||
public class GetCategoriesResponse extends AbstractResultResponse<CategoryDefinition> { | ||
|
||
public static final ParseField CATEGORIES = new ParseField("categories"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetCategoriesResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("get_categories_response", true, | ||
a -> new GetCategoriesResponse((List<CategoryDefinition>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), CategoryDefinition.PARSER, CATEGORIES); | ||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), COUNT); | ||
} | ||
|
||
public static GetCategoriesResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
GetCategoriesResponse(List<CategoryDefinition> categories, long count) { | ||
super(CATEGORIES, categories, count); | ||
} | ||
|
||
/** | ||
* The retrieved categories | ||
* @return the retrieved categories | ||
*/ | ||
public List<CategoryDefinition> categories() { | ||
return results; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(count, results); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetCategoriesResponse other = (GetCategoriesResponse) obj; | ||
return count == other.count && Objects.equals(results, other.results); | ||
} | ||
} |
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
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.
I know some methods add the
@throws
and others don't. I think we should still add the@throws
entry even if it is a checked exception.I have not been consistent about this myself either :(.
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.
@dimitris-athanasiou may have a different opinion around this ^, So I will defer to him.
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.
You're right @benwtrent, we've been dropping the
@throws
clause in some of the methods in the client. We'll need to revisit and add them. I'll make a note to do that.