-
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
Add GetRollupCaps API to high level rest client #32880
Add GetRollupCaps API to high level rest client #32880
Conversation
…//github.com/tlrx/elasticsearch into tlrx-add-create-rollup-job-api-to-high-level-client
hi @polyfractal, We decided to split the request and response from the ones used in server/x-pack, so they do not overlap. Please update your PR such that you create new |
@polyfractal Is it ready to review? |
@tlrx sorry, not quite yet. After pushing I realized the client versions of the clases still extend Writeable when they don't need too. Removed those and need to refactor a few tests because of it. I'm off today but will finish it up first thing on Monday :) |
No need to extend ActionRequest, Writeable, etc
Also pulls in the rollup cleaning from elastic#33921
@tlrx Ok, think this is ready for a look now. Sorry for the delay, was fighting tests :) |
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 left a first bunch of comments, mostly cosmetics
} | ||
|
||
/** | ||
* Asynchronously put a rollup job into the cluster |
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: doc not up to date
import java.util.Optional; | ||
|
||
public class GetRollupCapsRequest implements Validatable, ToXContentObject { | ||
private String indexPattern; |
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 be final too
client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { |
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 don't need this, this is the default implementation
|
||
public class GetRollupCapsResponse implements ToXContentObject { | ||
|
||
private Map<String, RollableIndexCaps> jobs = Collections.emptyMap(); |
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.
Could be final
client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java
Show resolved
Hide resolved
public void testGetRollupCaps() throws Exception { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
|
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.
extra line
...t-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java
Show resolved
Hide resolved
...t-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java
Show resolved
Hide resolved
|
||
} | ||
|
||
|
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.
extra lines
Tidied up the various style issues, and applied similar corrections to some of the other classes :) |
this PR is way too big for me to review. if @tlrx is happy, then im happy. Im just going to check the high level rest items and skip all the pojos. next time it would be rad to separate all the pojos from the hlrc work. |
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.
based on the size of this, it might make sense to break it up into > 1 PR. I cant approve it as is, because its too much to review. If @tlrx is happy, then thats good enuf for me!
RollupRequestConverters::getRollupCaps, | ||
options, | ||
GetRollupCapsResponse::fromXContent, | ||
Collections.emptySet()); |
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.
any reason these two methods have drastically different indentation? one of them is a newline every param and the Async below is just 2 lines.
@@ -0,0 +1,172 @@ | |||
[[java-rest-high-x-pack-rollup-put-job]] |
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.
whats up this file? is it meant to be added?
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.
based on the size of this, it might make sense to break it up into > 1 PR. I cant approve it as is, because its too much to review. If @tlrx is happy, then thats good enuf for me!
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 - I left some minor comments that can be addressed without another review
There still two important things: the Put Rollup documentation that does not belong to this PR and a doc change to make it compatible with #34125
@@ -42,4 +44,16 @@ static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOEx | |||
request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); | |||
return request; | |||
} | |||
|
|||
static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { |
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.
getRollupCapsRequest can be final
return false; | ||
} | ||
GetRollupCapsResponse other = (GetRollupCapsResponse) obj; | ||
return Objects.equals(jobs, other.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.
Oh right sorry
|
||
RollableIndexCaps(final String indexName, final List<RollupJobCaps> caps) { | ||
this.indexName = indexName; | ||
this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) |
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.
Is it sorted for XContent rendering purpose? If so maybe it could be done in the toXContent() method instead of the constructor?
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.
It is... but isn't it better to sort once in the ctor instead of each time toXContent is called? Since jobcaps is final and unmodifiable, we know it will only happen once and won't ever become unsorted.
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.
(also note iirc it's mainly there to make testing from yaml rest tests easier)
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.
Ok, let's keep the sorting in the ctor. I wanted to avoid the sort to be done each time the object is instantiated but this is a HLRC specific object so it will be done just one time
} | ||
} | ||
} | ||
return new GetRollupCapsResponse(Collections.unmodifiableMap(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.
I don't think you need to make it unmodifiable here if it's done in the constructor
...t-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java
Show resolved
Hide resolved
...t-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java
Show resolved
Hide resolved
deleteRollupJobs(); | ||
waitForPendingRollupTasks(); | ||
} | ||
private void deleteRollupJobs() throws Exception { |
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: missing new line
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-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.
You'll have to use Nik's improvement here - it avoids to copy paste the execution snippets for the HLRC doc.
this.indexName = indexName; | ||
this.jobCaps = new ArrayList<>(); | ||
this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) |
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.
Do we need to sort here or maybe it can be done in the ToXContent() method?
Will continue the style fixes, and see if it can be split into >1 PR... I suspect that's going to be hard. The current structure of the client means we have to do a lot of semi-duplication, and a lot of moving things around, just to make the client bits work. E.g. all the request/response objects need to be sorta duplicated, minus the bits that are only used internal to the server. In the case of the Caps API, that's a lot of objects since it's a deeply-nested response object. Plus their associated response parsers, which aren't used on the Server side. There are some smaller changes I could probably make to Rollup in isolation (some changes to make a few objects immutable) but honestly I don't think that will help much. Re: docs... I meant to move the PutRollupJob docs, not sure why it copied instead. The organization of the docs appears to be under |
RE docs: it should not have an x-pack folder RE splitting, dont worry about it. if @tlrx is happy, so am I. The high points of the HLRC are ok, and assuming you fix the docs as he pointed out, |
@polyfractal Once docs and the few style issues fixed I'll be happy to review this one more time |
Jenkins test this please |
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, left minor comments. If CI is happy I'm happy
} | ||
|
||
RollupFieldCaps that = (RollupFieldCaps) other; | ||
return Objects.deepEquals(this.aggs, that.aggs); |
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 can use Objects.equals() here
} | ||
|
||
RollableIndexCaps that = (RollableIndexCaps) other; | ||
return Objects.deepEquals(this.jobCaps, that.jobCaps) |
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 can use Objects.equals() here
@@ -80,8 +81,8 @@ public boolean equals(Object other) { | |||
|
|||
RollableIndexCaps that = (RollableIndexCaps) other; | |||
|
|||
return Objects.equals(this.jobCaps, that.jobCaps) | |||
&& Objects.equals(this.indexName, that.indexName); | |||
return Objects.deepEquals(this.jobCaps, that.jobCaps) |
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 can use Objects.equals() here
Thanks @polyfractal 🎉 |
Adds GetRollupCaps API to the HLRC, and tweaks some of the Caps objects to be immutable. Also various style tweaks
Adds GetRollupCaps API to the HLRC, and tweaks some of the Caps objects to be immutable. Also various style tweaks
This is based on @tlrx's branch in #32703, so a review should probably hold off until that PR is merged so that this diff is a little cleaner.
The GetRollupIndexCaps API uses basically the same serialization of objects with a slightly different endpoint, but this PR was getting big enough already so I'll do that one in a followup.
Related #29827