@@ -31,8 +31,13 @@ public class TimeseriesLifecycleType implements LifecycleType {
31
31
public static final TimeseriesLifecycleType INSTANCE = new TimeseriesLifecycleType ();
32
32
33
33
public static final String TYPE = "timeseries" ;
34
- static final List <String > VALID_PHASES = Arrays .asList ("hot" , "warm" , "cold" , "delete" );
35
- static final List <String > ORDERED_VALID_HOT_ACTIONS = Arrays .asList (SetPriorityAction .NAME , UnfollowAction .NAME , RolloverAction .NAME );
34
+ static final String HOT_PHASE = "hot" ;
35
+ static final String WARM_PHASE = "warm" ;
36
+ static final String COLD_PHASE = "cold" ;
37
+ static final String DELETE_PHASE = "delete" ;
38
+ static final List <String > VALID_PHASES = Arrays .asList (HOT_PHASE , WARM_PHASE , COLD_PHASE , DELETE_PHASE );
39
+ static final List <String > ORDERED_VALID_HOT_ACTIONS = Arrays .asList (SetPriorityAction .NAME , UnfollowAction .NAME , RolloverAction .NAME ,
40
+ ForceMergeAction .NAME );
36
41
static final List <String > ORDERED_VALID_WARM_ACTIONS = Arrays .asList (SetPriorityAction .NAME , UnfollowAction .NAME , ReadOnlyAction .NAME ,
37
42
AllocateAction .NAME , ShrinkAction .NAME , ForceMergeAction .NAME );
38
43
static final List <String > ORDERED_VALID_COLD_ACTIONS = Arrays .asList (SetPriorityAction .NAME , UnfollowAction .NAME , AllocateAction .NAME ,
@@ -45,10 +50,10 @@ public class TimeseriesLifecycleType implements LifecycleType {
45
50
private static Map <String , Set <String >> ALLOWED_ACTIONS = new HashMap <>();
46
51
47
52
static {
48
- ALLOWED_ACTIONS .put ("hot" , VALID_HOT_ACTIONS );
49
- ALLOWED_ACTIONS .put ("warm" , VALID_WARM_ACTIONS );
50
- ALLOWED_ACTIONS .put ("cold" , VALID_COLD_ACTIONS );
51
- ALLOWED_ACTIONS .put ("delete" , VALID_DELETE_ACTIONS );
53
+ ALLOWED_ACTIONS .put (HOT_PHASE , VALID_HOT_ACTIONS );
54
+ ALLOWED_ACTIONS .put (WARM_PHASE , VALID_WARM_ACTIONS );
55
+ ALLOWED_ACTIONS .put (COLD_PHASE , VALID_COLD_ACTIONS );
56
+ ALLOWED_ACTIONS .put (DELETE_PHASE , VALID_DELETE_ACTIONS );
52
57
}
53
58
54
59
private TimeseriesLifecycleType () {
@@ -126,16 +131,16 @@ public String getPreviousPhaseName(String currentPhaseName, Map<String, Phase> p
126
131
public List <LifecycleAction > getOrderedActions (Phase phase ) {
127
132
Map <String , LifecycleAction > actions = phase .getActions ();
128
133
switch (phase .getName ()) {
129
- case "hot" :
134
+ case HOT_PHASE :
130
135
return ORDERED_VALID_HOT_ACTIONS .stream ().map (a -> actions .getOrDefault (a , null ))
131
136
.filter (Objects ::nonNull ).collect (Collectors .toList ());
132
- case "warm" :
137
+ case WARM_PHASE :
133
138
return ORDERED_VALID_WARM_ACTIONS .stream () .map (a -> actions .getOrDefault (a , null ))
134
139
.filter (Objects ::nonNull ).collect (Collectors .toList ());
135
- case "cold" :
140
+ case COLD_PHASE :
136
141
return ORDERED_VALID_COLD_ACTIONS .stream ().map (a -> actions .getOrDefault (a , null ))
137
142
.filter (Objects ::nonNull ).collect (Collectors .toList ());
138
- case "delete" :
143
+ case DELETE_PHASE :
139
144
return ORDERED_VALID_DELETE_ACTIONS .stream ().map (a -> actions .getOrDefault (a , null ))
140
145
.filter (Objects ::nonNull ).collect (Collectors .toList ());
141
146
default :
@@ -147,20 +152,20 @@ public List<LifecycleAction> getOrderedActions(Phase phase) {
147
152
public String getNextActionName (String currentActionName , Phase phase ) {
148
153
List <String > orderedActionNames ;
149
154
switch (phase .getName ()) {
150
- case "hot" :
155
+ case HOT_PHASE :
151
156
orderedActionNames = ORDERED_VALID_HOT_ACTIONS ;
152
157
break ;
153
- case "warm" :
158
+ case WARM_PHASE :
154
159
orderedActionNames = ORDERED_VALID_WARM_ACTIONS ;
155
160
break ;
156
- case "cold" :
161
+ case COLD_PHASE :
157
162
orderedActionNames = ORDERED_VALID_COLD_ACTIONS ;
158
163
break ;
159
- case "delete" :
164
+ case DELETE_PHASE :
160
165
orderedActionNames = ORDERED_VALID_DELETE_ACTIONS ;
161
166
break ;
162
167
default :
163
- throw new IllegalArgumentException ("lifecycle type[" + TYPE + "] does not support phase[" + phase .getName () + "]" );
168
+ throw new IllegalArgumentException ("lifecycle type [" + TYPE + "] does not support phase [" + phase .getName () + "]" );
164
169
}
165
170
166
171
int index = orderedActionNames .indexOf (currentActionName );
@@ -195,5 +200,19 @@ public void validate(Collection<Phase> phases) {
195
200
}
196
201
});
197
202
});
203
+
204
+ // Check for forcemerge in 'hot' without a rollover action
205
+ if (phases .stream ()
206
+ // Is there a hot phase
207
+ .filter (phase -> HOT_PHASE .equals (phase .getName ()))
208
+ // That contains the 'forcemerge' action
209
+ .filter (phase -> phase .getActions ().containsKey (ForceMergeAction .NAME ))
210
+ // But does *not* contain the 'rollover' action?
211
+ .anyMatch (phase -> phase .getActions ().containsKey (RolloverAction .NAME ) == false )) {
212
+ // If there is, throw an exception
213
+ throw new IllegalArgumentException ("the [" + ForceMergeAction .NAME +
214
+ "] action may not be used in the [" + HOT_PHASE +
215
+ "] phase without an accompanying [" + RolloverAction .NAME + "] action" );
216
+ }
198
217
}
199
218
}
0 commit comments