-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
Conversation
6420f6d
to
8550d71
Compare
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`
8550d71
to
a6bb033
Compare
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
his -> this
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
thanks @dakrone! I've updated to reflect your great recommendations! |
There was a problem hiding this 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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough
There was a problem hiding this comment.
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
:
elasticsearch/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessor.java
Lines 86 to 89 in cf74898
@Override | |
public String getType() { | |
return TYPE; | |
} |
return Strings.toString(this, true, true); | ||
} | ||
|
||
static void validate(Collection<Phase> phases) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will push up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thanks for the review @colings86 and @dakrone! |
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`
This is the final PR for copying over the necessary components for
clients to parse/render LifecyclePolicy. Changes include:
getName