copy LifecyclePolicy to protocol.xpack#32915
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
dakrone
left a comment
There was a problem hiding this comment.
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.
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?
|
|
||
| /** | ||
| * @return a {@link Map} of the {@link LifecycleAction}s to run when during | ||
| * his {@link Phase}. |
There was a problem hiding this comment.
this happened somewhere else as well :(
|
|
||
| private String name; | ||
| private Map<String, LifecycleAction> actions; | ||
| private TimeValue after; |
There was a problem hiding this comment.
I think these can all be final?
|
thanks @dakrone! I've updated to reflect your great recommendations! |
colings86
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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; |
| /** | ||
| * @return the name of this action | ||
| */ | ||
| String getName(); |
There was a problem hiding this comment.
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.
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.
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:
| return Strings.toString(this, true, true); | ||
| } | ||
|
|
||
| static void validate(Collection<Phase> phases) { |
There was a problem hiding this comment.
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.
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.
super nit: I tend to like validation to be first
|
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