Skip to content
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

Merged
merged 20 commits into from
Oct 18, 2018

Conversation

polyfractal
Copy link
Contributor

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

@hub-cap
Copy link
Contributor

hub-cap commented Aug 27, 2018

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 request implements Validatable & generic response class in the high level rest client's org.elasticsearch.client.nameOfYourClient. Example: o.e.client.watcher, o.e.client.cluster. Please revert any work you did to modify the existing request/response in x-pack or server.

@tlrx
Copy link
Member

tlrx commented Sep 21, 2018

@polyfractal Is it ready to review?

@polyfractal
Copy link
Contributor Author

@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 :)

@polyfractal
Copy link
Contributor Author

@tlrx Ok, think this is ready for a look now. Sorry for the delay, was fighting tests :)

Copy link
Member

@tlrx tlrx left a 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
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be final too

}

@Override
public Optional<ValidationException> validate() {
Copy link
Member

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be final

public void testGetRollupCaps() throws Exception {
RestHighLevelClient client = highLevelClient();


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line


}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra lines

@polyfractal
Copy link
Contributor Author

Tidied up the various style issues, and applied similar corrections to some of the other classes :)

@hub-cap
Copy link
Contributor

hub-cap commented Oct 2, 2018

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.

Copy link
Contributor

@hub-cap hub-cap left a 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());
Copy link
Contributor

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]]
Copy link
Contributor

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?

Copy link
Contributor

@hub-cap hub-cap left a 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!

Copy link
Member

@tlrx tlrx left a 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 {
Copy link
Member

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);
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

Copy link
Member

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));
Copy link
Member

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

deleteRollupJobs();
waitForPendingRollupTasks();
}
private void deleteRollupJobs() throws Exception {
Copy link
Member

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]
Copy link
Member

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)
Copy link
Member

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?

@rjernst rjernst removed the review label Oct 10, 2018
@polyfractal
Copy link
Contributor Author

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 /java-rest/high-level/<plugin>/. But it appears that PutJob is under /java-rest/high-level/x-pack/rollup/... I'm assuming that was from before the recent HLRC restructuring. In any case, it seems like the x-pack version should be deleted and moved to the other location to follow how other plugins are doing it (ML, etc)

@hub-cap
Copy link
Contributor

hub-cap commented Oct 15, 2018

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, :shipit:

@tlrx
Copy link
Member

tlrx commented Oct 16, 2018

@polyfractal Once docs and the few style issues fixed I'll be happy to review this one more time

@polyfractal
Copy link
Contributor Author

Jenkins test this please

Copy link
Member

@tlrx tlrx left a 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);
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@polyfractal polyfractal merged commit 45546e7 into elastic:master Oct 18, 2018
@tlrx
Copy link
Member

tlrx commented Oct 19, 2018

Thanks @polyfractal 🎉

polyfractal added a commit to polyfractal/elasticsearch that referenced this pull request Oct 19, 2018
Adds GetRollupCaps API to the HLRC, and tweaks some of the
Caps objects to be immutable.  Also various style tweaks
polyfractal added a commit that referenced this pull request Oct 19, 2018
Adds GetRollupCaps API to the HLRC, and tweaks some of the
Caps objects to be immutable.  Also various style tweaks
kcm pushed a commit that referenced this pull request Oct 30, 2018
Adds GetRollupCaps API to the HLRC, and tweaks some of the
Caps objects to be immutable.  Also various style tweaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants