Add GetRollupCaps API to high level rest client#32880
Add GetRollupCaps API to high level rest client#32880polyfractal merged 20 commits intoelastic:masterfrom
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 :) |
tlrx
left a comment
There was a problem hiding this comment.
I left a first bunch of comments, mostly cosmetics
| } | ||
|
|
||
| /** | ||
| * Asynchronously put a rollup job into the cluster |
| import java.util.Optional; | ||
|
|
||
| public class GetRollupCapsRequest implements Validatable, ToXContentObject { | ||
| private String indexPattern; |
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.
You don't need this, this is the default implementation
|
|
||
| public class GetRollupCapsResponse implements ToXContentObject { | ||
|
|
||
| private Map<String, RollableIndexCaps> jobs = Collections.emptyMap(); |
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(); | ||
|
|
||
|
|
...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
|
|
||
| } | ||
|
|
||
|
|
|
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. |
| RollupRequestConverters::getRollupCaps, | ||
| options, | ||
| GetRollupCapsResponse::fromXContent, | ||
| Collections.emptySet()); |
There was a problem hiding this comment.
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.
whats up this file? is it meant to be added?
| return request; | ||
| } | ||
|
|
||
| static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { |
| return false; | ||
| } | ||
| GetRollupCapsResponse other = (GetRollupCapsResponse) obj; | ||
| return Objects.equals(jobs, other.jobs); |
|
|
||
| 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.
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.
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.
(also note iirc it's mainly there to make testing from yaml rest tests easier)
There was a problem hiding this comment.
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.
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 { |
|
|
||
| ["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.
You'll have to use Nik's improvement here - it avoids to copy paste the execution snippets for the HLRC doc.
| public RollableIndexCaps(String indexName, List<RollupJobCaps> caps) { | ||
| this.indexName = indexName; | ||
| this.jobCaps = new ArrayList<>(); | ||
| this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) |
There was a problem hiding this comment.
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 |
tlrx
left a comment
There was a problem hiding this comment.
LGTM, left minor comments. If CI is happy I'm happy
| } | ||
|
|
||
| RollupFieldCaps that = (RollupFieldCaps) other; | ||
| return Objects.deepEquals(this.aggs, that.aggs); |
| } | ||
|
|
||
| RollableIndexCaps that = (RollableIndexCaps) other; | ||
| return Objects.deepEquals(this.jobCaps, that.jobCaps) |
|
|
||
| return Objects.equals(this.jobCaps, that.jobCaps) | ||
| && Objects.equals(this.indexName, that.indexName); | ||
| return Objects.deepEquals(this.jobCaps, that.jobCaps) |
|
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