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

Rest HL client: Add get license action #32438

Merged
merged 11 commits into from
Aug 6, 2018

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Jul 27, 2018

WIP: @nik9000, @hub-cap I have implemented it in the license-as-a-string
style that we discussed before, but just want to make sure that we are still
ok with it for this one, before polishing it off. Could you take a look when you
have a chance?

Continues to use String instead of a more complex License class to
hold the license text similarly to put license.

Relates #29827

Continues to use String instead of a more complex License class to
hold the license text similarly to put license.

Relates elastic#29827
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.

I would like @nik9000 opinion here. I feel like not using a License class client side (and opting for a String instead) ended up making this code look less nice. And it puts a 1off (convertResponseToJson) in the client as well, which feels wrong. But id be happy to be told that im mistaken (spoiler alert, i usually am mistaken)!

@@ -1069,6 +1077,39 @@ static boolean convertExistsResponse(Response response) {
return response.getStatusLine().getStatusCode() == 200;
}

/** Converts an eniter response into a json sting
Copy link
Contributor

Choose a reason for hiding this comment

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

entire

* This is useful for responses that we don't parse on the client side, but instead work as string
* such as in case of the license JSON
*/
static String convertResponseToJson(Response response) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing this makes me wonder why we dont just return a License client side class instead of doing magic to turn the response into a string. I will let @nik9000 comment as well tho.

Copy link
Member

Choose a reason for hiding this comment

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

I was happy with the put license API using the license json because I figured most people don't edit their license. It is just a big blob of json they get from somewhere and stick into wherever it needs to go. I mean, I'd have been happy with using the License object from x-pack:plugin:core but it has so much stuff in it! There is like a file watcher in there. All kinds of stuff that has no business being in a client at all. I feel like it'd be nice to get fields like max_nodes and expiry back in the client but License.java will take a lot of work to move. So I kind of figured it wasn't worth doing. I kind of wonder how much license administration folks will do with the java client, but :shrug:.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this? I can move convertResponseToJson into LicenseClient, rename public String license() into public String getLicenseDefinition() and we will leave it like this for now. If we realize at some point that we actually want License as License, we can always implement a client-side version of the License class and add public License getLicense() method that will return it. This way we don't really paint ourselves into a corner and make progress.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with that. Though I still think you might be ok with EntityUtils.toString so you don't really need the helper at all.

this.license = license;
}

public String license() {
Copy link
Member

Choose a reason for hiding this comment

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

I'd be getLicense

* This is useful for responses that we don't parse on the client side, but instead work as string
* such as in case of the license JSON
*/
static String convertResponseToJson(Response response) 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.

I was happy with the put license API using the license json because I figured most people don't edit their license. It is just a big blob of json they get from somewhere and stick into wherever it needs to go. I mean, I'd have been happy with using the License object from x-pack:plugin:core but it has so much stuff in it! There is like a file watcher in there. All kinds of stuff that has no business being in a client at all. I feel like it'd be nice to get fields like max_nodes and expiry back in the client but License.java will take a lot of work to move. So I kind of figured it wasn't worth doing. I kind of wonder how much license administration folks will do with the java client, but :shrug:.

parser.nextToken();
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
return Strings.toString(builder);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be ok for us to do EntityUtils.toString and leave it at that? Do we need to parse the response? If we make the request with the json content-type header we can be fairly sure it'll come back json. Right?

@imotov imotov removed the WIP label Aug 1, 2018
@imotov
Copy link
Contributor Author

imotov commented Aug 1, 2018

@hub-cap, @nik9000 I have updated the PR as per our discussion. Could you take another look when you have a chance?

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM.

}


/** Converts an entire response into a json sting
Copy link
Member

Choose a reason for hiding this comment

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

I think this belongs one line below.

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.

:shipit:

@hub-cap
Copy link
Contributor

hub-cap commented Aug 3, 2018

I have just committed #32596 which changes the location of the xpack clients. Its very likely your tests wont compile now that the xpack portion of client.xpack().yourCommercialClient() is removed.

@imotov
Copy link
Contributor Author

imotov commented Aug 3, 2018

@hub-cap thanks for letting me know! I typically run precommit after merging in master for stale PRs, but since this PR was pretty fresh, I might have just pushed it since the change didn't cause any conflicts.

I am waiting for #32613 to clear and will merge this PR in afterwards.

@imotov imotov merged commit e641fcc into elastic:master Aug 6, 2018
imotov added a commit that referenced this pull request Aug 6, 2018
Continues to use String instead of a more complex License class to
hold the license text similarly to put license.

Relates #29827
@imotov imotov deleted the issue-29827-get-license-hl-rest branch May 1, 2020 22:16
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.

4 participants