Skip to content

copy LifecyclePolicy to protocol.xpack #32915

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 5 commits into from
Aug 20, 2018

Conversation

talevy
Copy link
Contributor

@talevy talevy commented Aug 16, 2018

This is the final PR for copying over the necessary components for
clients to parse/render LifecyclePolicy. Changes include:

  • move of named-x-content server objects away from client
  • move validation into the client copy of LifecyclePolicy
  • move LifecycleAction into an interface with getName

@talevy talevy added WIP :Data Management/ILM+SLM Index and Snapshot lifecycle management labels Aug 16, 2018
@talevy talevy force-pushed the ilm-protocol-policy branch 3 times, most recently from 6420f6d to 8550d71 Compare August 16, 2018 17:23
This is the final PR for copying over the necessary components for
clients to parse/render LifecyclePolicy. Changes include:

- move of named-x-content server objects away from client
- move validation into the client copy of LifecyclePolicy
- move LifecycleAction into an interface with `getName`
@talevy talevy force-pushed the ilm-protocol-policy branch from 8550d71 to a6bb033 Compare August 16, 2018 21:11
@talevy talevy requested review from colings86 and dakrone August 16, 2018 21:11
@talevy talevy removed the WIP label Aug 16, 2018
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 a few comments but nothing major, otherwise LGTM


static void validate(Collection<Phase> phases) {
Set<String> allowedPhases = Sets.newHashSet("hot", "warm", "cold", "delete");
Map<String, Set<String>> allowedActions = new HashMap<>(allowedPhases.size());
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 to rebuild this map every time we validate, can this be a static var and initialized in a static block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call


/**
* @return a {@link Map} of the {@link LifecycleAction}s to run when during
* his {@link Phase}.
Copy link
Member

Choose a reason for hiding this comment

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

his -> 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.

this happened somewhere else as well :(


private String name;
private Map<String, LifecycleAction> actions;
private TimeValue after;
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 can all be final?

@talevy
Copy link
Contributor Author

talevy commented Aug 16, 2018

thanks @dakrone! I've updated to reflect your great recommendations!

Copy link
Contributor

@colings86 colings86 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 some comments but it looks good

new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that I previously said these were no longer needed to be registered here but I'm actually wondering now if the actions and LifecycleType need to be registered here for the transport client? I think because the Action class will still reference these and the transport client uses the action objects rather than the client objects we might need to keep them registered 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.

I am going to revert this change and we can address the correct place for these in a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, on second thought... doesn't the transport client talk to ES using the wire protocol? why would it need the xcontent bits?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. Lets leave this as is then

private TimeValue after;
private final String name;
private final Map<String, LifecycleAction> actions;
private final TimeValue after;
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch.

/**
* @return the name of this action
*/
String getName();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we call this getType() instead? Elsewhere in the codebase we often use name for user specified things and type for types of implementation where the name is fixed. NamedWriteable breaks that a bit for me which bothers me but I think thats the only major exception and isn't user facing

Copy link
Contributor Author

@talevy talevy Aug 17, 2018

Choose a reason for hiding this comment

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

Why do you think that type is more appropriate here? The only reason this method exists is for the ability for Phase to leverage its name when looking up NamedXContent. Since this would further diverge the terminology away from our Named- naming world, I feel like calling it type here wouldn't fix much. Also, we have these actions being supported by specific LifecycleTypes (yet another type), that I think there is further confusion to be had there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that being said, I agree that it is unfortunate there is no strong consistency here. For posterity, I'll link to the equivalent info from the Ingest world which uses getType:

@Override
public String getType() {
return TYPE;
}

return Strings.toString(this, true, true);
}

static void validate(Collection<Phase> phases) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make this private? It shouldn't be too hard to test this method via 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.

for sure! I'll just get rid of this method entirely

public LifecyclePolicy(String name, Map<String, Phase> phases) {
this.name = name;
this.phases = phases;
validate(phases.values());
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: I tend to like validation to be first

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 push up!

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

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

LGTM

@talevy talevy merged commit 5ce082c into elastic:index-lifecycle Aug 20, 2018
@talevy talevy deleted the ilm-protocol-policy branch August 20, 2018 15:32
@talevy
Copy link
Contributor Author

talevy commented Aug 20, 2018

thanks for the review @colings86 and @dakrone!

talevy added a commit that referenced this pull request Aug 20, 2018
This is the final PR for copying over the necessary components for
clients to parse/render LifecyclePolicy. Changes include:

- move of named-x-content server objects away from client
- move validation into the client copy of LifecyclePolicy
- move LifecycleAction into an interface with `getName`
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants