Skip to content

HLRC: Add ILM Status to HLRC #33283

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

Merged
merged 8 commits into from
Sep 5, 2018

Conversation

jakelandis
Copy link
Contributor

Adds support for the Index Lifecycle Management Status to the Java
High-Level Rest Client.

Relates to #33100


Notes to reviewer(s):

  • I don't think there should be anything controversial here, and probably don't need 5 reviewers ... just wasn't sure who to tag.
  • the naming conventions were chosen to match the start/stopILM.
  • Using a TimedRequest instead of a StatusILMRequest... not sure the preference here, but it kinda matches the AcknowledgedResponse in terms of not creating typed request/response when not needed.

Adds support for the Index Lifecycle Management Status to the Java
High-Level Rest Client.

Relates to elastic#33100
@jakelandis jakelandis added >enhancement :Data Management/ILM+SLM Index and Snapshot lifecycle management labels Aug 30, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Member

@dakrone dakrone 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 comments renaming these methods/classes, I'm in favor of:

  • LifecycleManagementStatusResponse
  • lifecycleManagementStatus(...)

* @param request the request with user defined timeouts.
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public StatusILMResponse StatusILM(TimedRequest request, RequestOptions options) 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 think these should be LifecycleManagementStatusResponse, rather than using the ILM in method/class names

Also, the method name is StatusILM and we don't capitalize any of our method names

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, the method name is StatusILM and we don't capitalize any of our method names

oops didn't meant to capitalize the method name. (kinda surprised that check style didn't catch that). will fix.

I think these should be LifecycleManagementStatusResponse, rather than using the ILM in method/class names

I tend to agree, but was matching the start/stopILM here: https://github.com/elastic/elasticsearch/tree/index-lifecycle/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle

Should I rename those too ?

* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void StatusILMAsync(TimedRequest request, RequestOptions options,
Copy link
Member

Choose a reason for hiding this comment

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

Same here about naming and capitalization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops ... IDE find and replace gone wild. will fix.

}
}

// generated
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 we need these generated comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove them. FWIW, I generally put these in here as a way to signal nothing special here, so no tests, and if changes are made need to re-generate.

Copy link
Contributor

@gwbrown gwbrown left a comment

Choose a reason for hiding this comment

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

Left some comments.

* @param request the request with user defined timeouts.
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public StatusILMResponse StatusILM(TimedRequest request, RequestOptions options) throws IOException {
Copy link
Contributor

@gwbrown gwbrown Aug 30, 2018

Choose a reason for hiding this comment

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

Method names should start with a lowercase letter, so this should be statusILM.

Or maybe getILMStatus? statusILM doesn't make much sense seeing it for the first time - there's no verb there.

Lee beat me to it and left better feedback, see his comment instead.

* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void StatusILMAsync(TimedRequest request, RequestOptions options,
Copy link
Contributor

Choose a reason for hiding this comment

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

As above re: method names.

/**
* Enum representing the different modes that Index Lifecycle Service can operate in.
*/
public enum OperationMode {
Copy link
Contributor

Choose a reason for hiding this comment

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

#33250 moves the existing OperationMode class into o.e.client.indexlifecycle - you may want to wait until that gets merged (should be later today) and use that one instead of having this as an inner class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! ... will wait till that gets merged and update accordingly.

Response statusResponse = client().performRequest(statusReq);
String statusResponseString = EntityUtils.toString(statusResponse.getEntity());
assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString);
TimedRequest statusRequest = new TimedRequest();
Copy link
Contributor

Choose a reason for hiding this comment

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

While I get the logic behind why you did it this way, I think generic classes make more sense for responses than requests. As a user of the HLRC, this feels really strange - even if GetILMStatusRequest would be an extra class that doesn't really add anything, I think having separate classes for each request type is the way to go. I could be wrong though, I'd like to hear others' input on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a strong opinion beyond consistency in the API.

Perhaps we should allow a no-arg method in the client that creates the request for them. However, that also creates inconsistency (unless you create a bunch of new methods).

I'd like to hear others' input on this.

..same

Copy link
Contributor

Choose a reason for hiding this comment

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

@hub-cap Could you weigh in on this?


public class StatusILMResponseTests extends ESTestCase {

public void testClientServerStatuses() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the shared class would let you get rid of this test, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will wait for #33250 to use shared class.

* Fixed incorrect method uppercase
* Renamed statsILM -> lifecycleManagementStatus
* removed "generated" comments
@jakelandis
Copy link
Contributor Author

jakelandis commented Aug 30, 2018

Changes pushed:

  • Fixed incorrect method uppercase
  • Renamed statsILM -> lifecycleManagementStatus
  • removed "generated" comments

TODO (this PR):

TODO (not in this PR):

  • rename stopILM and startILM ? [2]
  • enforce basic method naming via checkstyle (edit: this is a rabbit hole not worth going down)

@hub-cap [1]
Is there a preferred design for how to model empty requests (no parameters) for the API ?
a) Use a generic TimedRequest (like this PR currently)
b) create an empty typed Request (e.g. public class MyThingRequest extends TimedRequest{ //empty } ) (as @gwbrown advocates)
c) introduce no arg methods in the *Client's that under the covers uses a TimedRequest (e.g. MyThingResponse getMyThing(){ //doit })
d) other ?

@colings86 [2]
Any objections if I move the start/stopILM HLRC API's to the newer format and change the name to match the @dakrone's naming suggestion ? (different PR from this one)

@gwbrown
Copy link
Contributor

gwbrown commented Aug 30, 2018

@jakelandis #33250 has been merged into index-lifecycle and backported to index-lifecycle-6.x, so you should be good to go for switching over to the existing OperationMode class.

@@ -1241,6 +1241,18 @@ static Request stopILM(StopILMRequest stopILMRequest) {
return request;
}

static Request statusILM(TimedRequest ilmStatusRequest){
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this lifecycleManagementStatus to match the method in the client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks missed this one. done.

@gwbrown
Copy link
Contributor

gwbrown commented Sep 4, 2018

LGTM, pending @hub-cap's input on specialized vs generic requests.

@hub-cap
Copy link
Contributor

hub-cap commented Sep 4, 2018

If we create a request and we ever want to add things to it, then it will not require a breaking contract change. It also gives us a chance to rename TimedRequest if its scope changes one day. It might even be worth making it abstract to ensure we dont use it this way. what do yall think?

@jakelandis
Copy link
Contributor Author

@hub-cap - good point. I will add the specific the request to this PR and change TimedRequest to abstract.

@jakelandis
Copy link
Contributor Author

@dakrone @gwbrown - mind taking another look all suggestions are implemented.

Copy link
Member

@dakrone dakrone 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 3 comments but they are very minor, otherwise LGTM

"operation_mode", a -> new LifecycleManagementStatusResponse((String) a[0]));

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField("operation_mode"));
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the ParseField into a class private var and then use it in the parser (so we don't accidentally typo/change it in the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved "operation_mode" to a static final string (not exactly the ask, but i believe same outcome)

}

//package private for testing
LifecycleManagementStatusResponse(String operationMode) {
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 should take an OperationMode to push the conversion into the caller, rather than doing it in the constructor (it seems cleaner to me that way).

This is just my personal preference though, so up to you if you want to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leaving as-is

static OperationMode fromString(String string) {
return EnumSet.allOf(OperationMode.class).stream()
.filter(e -> string.equalsIgnoreCase(e.name())).findFirst()
.orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ENGLISH, "%s is not a valid operation_mode", string)));
Copy link
Member

Choose a reason for hiding this comment

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

We use Locale.ROOT for as many things as we can, rather than the English locale here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jakelandis
Copy link
Contributor Author

Thanks for the reviews! will merge once CI turns green.

@jakelandis
Copy link
Contributor Author

jenkins test this please

@jakelandis jakelandis merged commit 8b8ff2b into elastic:index-lifecycle Sep 5, 2018
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 5, 2018
Adds support for the Index Lifecycle Management Status to the Java
High-Level Rest Client.

Relates to elastic#33100
jakelandis added a commit that referenced this pull request Sep 6, 2018
Adds support for the Index Lifecycle Management Status to the Java
High-Level Rest Client.

Relates to #33100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/ILM+SLM Index and Snapshot lifecycle management >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants