@@ -63,165 +63,158 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
6363 );
6464 }
6565
66- public void testGetIndexLifecycleExplainResponse () throws IOException {
67- {
68- // only errors index
69- LifecycleExecutionState .Builder errorStepState = LifecycleExecutionState .builder ()
70- .setPhase ("hot" )
71- .setAction ("rollover" )
72- .setStep (ErrorStep .NAME )
73- .setPhaseDefinition (PHASE_DEFINITION );
74- String indexInErrorStep = "index_in_error" ;
75- IndexMetadata indexMetadata = IndexMetadata .builder (indexInErrorStep )
76- .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
77- .numberOfShards (randomIntBetween (1 , 5 ))
78- .numberOfReplicas (randomIntBetween (0 , 5 ))
79- .putCustom (ILM_CUSTOM_METADATA_KEY , errorStepState .build ().asMap ())
80- .build ();
81- ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
82- .put (indexMetadata , true )
83- .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
84- .build ();
85-
86- IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
87- indexInErrorStep ,
88- project ,
89- true ,
90- true ,
91- REGISTRY ,
92- randomBoolean ()
93- );
94- assertThat (onlyErrorsResponse , notNullValue ());
95- assertThat (onlyErrorsResponse .getIndex (), is (indexInErrorStep ));
96- assertThat (onlyErrorsResponse .getStep (), is (ErrorStep .NAME ));
97- }
66+ public void testGetIndexLifecycleExplainResponse_onlyErrors () throws IOException {
67+ LifecycleExecutionState .Builder errorStepState = LifecycleExecutionState .builder ()
68+ .setPhase ("hot" )
69+ .setAction ("rollover" )
70+ .setStep (ErrorStep .NAME )
71+ .setPhaseDefinition (PHASE_DEFINITION );
72+ String indexInErrorStep = "index_in_error" ;
73+ IndexMetadata indexMetadata = IndexMetadata .builder (indexInErrorStep )
74+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
75+ .numberOfShards (randomIntBetween (1 , 5 ))
76+ .numberOfReplicas (randomIntBetween (0 , 5 ))
77+ .putCustom (ILM_CUSTOM_METADATA_KEY , errorStepState .build ().asMap ())
78+ .build ();
79+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
80+ .put (indexMetadata , true )
81+ .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
82+ .build ();
83+
84+ IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
85+ indexInErrorStep ,
86+ project ,
87+ true ,
88+ true ,
89+ REGISTRY ,
90+ randomBoolean ()
91+ );
92+ assertThat (onlyErrorsResponse , notNullValue ());
93+ assertThat (onlyErrorsResponse .getIndex (), is (indexInErrorStep ));
94+ assertThat (onlyErrorsResponse .getStep (), is (ErrorStep .NAME ));
95+ }
9896
99- {
100- // only managed index
101- LifecycleExecutionState .Builder checkRolloverReadyStepState = LifecycleExecutionState .builder ()
102- .setPhase ("hot" )
103- .setAction ("rollover" )
104- .setStep (WaitForRolloverReadyStep .NAME )
105- .setPhaseDefinition (PHASE_DEFINITION );
106-
107- String indexInCheckRolloverStep = "index_in_check_rollover" ;
108- IndexMetadata indexMetadata = IndexMetadata .builder (indexInCheckRolloverStep )
109- .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
110- .numberOfShards (randomIntBetween (1 , 5 ))
111- .numberOfReplicas (randomIntBetween (0 , 5 ))
112- .putCustom (ILM_CUSTOM_METADATA_KEY , checkRolloverReadyStepState .build ().asMap ())
113- .build ();
114- ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
115- .put (indexMetadata , true )
116- .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
117- .build ();
118-
119- IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
120- indexInCheckRolloverStep ,
121- project ,
122- true ,
123- true ,
124- REGISTRY ,
125- randomBoolean ()
126- );
127- assertThat (onlyErrorsResponse , nullValue ());
128-
129- IndexLifecycleExplainResponse allManagedResponse = getIndexLifecycleExplainResponse (
130- indexInCheckRolloverStep ,
131- project ,
132- false ,
133- true ,
134- REGISTRY ,
135- randomBoolean ()
136- );
137- assertThat (allManagedResponse , notNullValue ());
138- assertThat (allManagedResponse .getIndex (), is (indexInCheckRolloverStep ));
139- assertThat (allManagedResponse .getStep (), is (WaitForRolloverReadyStep .NAME ));
140- }
97+ public void testGetIndexLifecycleExplainResponse_onlyManagedIndex () throws IOException {
98+ LifecycleExecutionState .Builder checkRolloverReadyStepState = LifecycleExecutionState .builder ()
99+ .setPhase ("hot" )
100+ .setAction ("rollover" )
101+ .setStep (WaitForRolloverReadyStep .NAME )
102+ .setPhaseDefinition (PHASE_DEFINITION );
103+
104+ String indexInCheckRolloverStep = "index_in_check_rollover" ;
105+ IndexMetadata indexMetadata = IndexMetadata .builder (indexInCheckRolloverStep )
106+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
107+ .numberOfShards (randomIntBetween (1 , 5 ))
108+ .numberOfReplicas (randomIntBetween (0 , 5 ))
109+ .putCustom (ILM_CUSTOM_METADATA_KEY , checkRolloverReadyStepState .build ().asMap ())
110+ .build ();
111+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
112+ .put (indexMetadata , true )
113+ .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
114+ .build ();
115+
116+ IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
117+ indexInCheckRolloverStep ,
118+ project ,
119+ true ,
120+ true ,
121+ REGISTRY ,
122+ randomBoolean ()
123+ );
124+ assertThat (onlyErrorsResponse , nullValue ());
125+
126+ IndexLifecycleExplainResponse allManagedResponse = getIndexLifecycleExplainResponse (
127+ indexInCheckRolloverStep ,
128+ project ,
129+ false ,
130+ true ,
131+ REGISTRY ,
132+ randomBoolean ()
133+ );
134+ assertThat (allManagedResponse , notNullValue ());
135+ assertThat (allManagedResponse .getIndex (), is (indexInCheckRolloverStep ));
136+ assertThat (allManagedResponse .getStep (), is (WaitForRolloverReadyStep .NAME ));
137+ }
141138
142- {
143- // index with missing policy
144- IndexLifecycleService indexLifecycleService = mock (IndexLifecycleService .class );
145- when (indexLifecycleService .policyExists ("random-policy" )).thenReturn (false );
146-
147- String indexWithMissingPolicy = "index_with_missing_policy" ;
148- IndexMetadata indexMetadata = IndexMetadata .builder (indexWithMissingPolicy )
149- .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , "random-policy" ))
150- .numberOfShards (randomIntBetween (1 , 5 ))
151- .numberOfReplicas (randomIntBetween (0 , 5 ))
152- .build ();
153- ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
154- .put (indexMetadata , true )
155- .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
156- .build ();
157-
158- IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
159- indexWithMissingPolicy ,
160- project ,
161- true ,
162- true ,
163- REGISTRY ,
164- randomBoolean ()
165- );
166- assertThat (onlyErrorsResponse , notNullValue ());
167- assertThat (onlyErrorsResponse .getPolicyName (), is ("random-policy" ));
168- assertThat (onlyErrorsResponse .getStep (), is (ErrorStep .NAME ));
169- }
139+ public void testGetIndexLifecycleExplainResponse_indexWithMissingPolicy () throws IOException {
140+ IndexLifecycleService indexLifecycleService = mock (IndexLifecycleService .class );
141+ when (indexLifecycleService .policyExists ("random-policy" )).thenReturn (false );
142+
143+ String indexWithMissingPolicy = "index_with_missing_policy" ;
144+ IndexMetadata indexMetadata = IndexMetadata .builder (indexWithMissingPolicy )
145+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , "random-policy" ))
146+ .numberOfShards (randomIntBetween (1 , 5 ))
147+ .numberOfReplicas (randomIntBetween (0 , 5 ))
148+ .build ();
149+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
150+ .put (indexMetadata , true )
151+ .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
152+ .build ();
153+
154+ IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse (
155+ indexWithMissingPolicy ,
156+ project ,
157+ true ,
158+ true ,
159+ REGISTRY ,
160+ randomBoolean ()
161+ );
162+ assertThat (onlyErrorsResponse , notNullValue ());
163+ assertThat (onlyErrorsResponse .getPolicyName (), is ("random-policy" ));
164+ assertThat (onlyErrorsResponse .getStep (), is (ErrorStep .NAME ));
165+ }
170166
171- {
172- // not managed index
173- IndexMetadata indexMetadata = IndexMetadata .builder ("index" )
174- .settings (settings (IndexVersion .current ()))
175- .numberOfShards (randomIntBetween (1 , 5 ))
176- .numberOfReplicas (randomIntBetween (0 , 5 ))
177- .build ();
178- ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
179- .put (indexMetadata , true )
180- .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
181- .build ();
182-
183- IndexLifecycleExplainResponse onlyManaged = getIndexLifecycleExplainResponse (
184- "index" ,
185- project ,
186- false ,
187- true ,
188- REGISTRY ,
189- randomBoolean ()
190- );
191- assertThat (onlyManaged , nullValue ());
192- }
167+ public void testGetIndexLifecycleExplainResponse_notManagedIndex () throws IOException {
168+ IndexMetadata indexMetadata = IndexMetadata .builder ("index" )
169+ .settings (settings (IndexVersion .current ()))
170+ .numberOfShards (randomIntBetween (1 , 5 ))
171+ .numberOfReplicas (randomIntBetween (0 , 5 ))
172+ .build ();
173+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
174+ .put (indexMetadata , true )
175+ .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
176+ .build ();
177+
178+ IndexLifecycleExplainResponse onlyManaged = getIndexLifecycleExplainResponse (
179+ "index" ,
180+ project ,
181+ false ,
182+ true ,
183+ REGISTRY ,
184+ randomBoolean ()
185+ );
186+ assertThat (onlyManaged , nullValue ());
187+ }
193188
194- {
195- // validate addition of default condition with `rolloverOnlyIfHasDocuments` true
196- LifecycleExecutionState .Builder checkRolloverReadyStepState = LifecycleExecutionState .builder ()
197- .setPhase ("hot" )
198- .setAction ("rollover" )
199- .setStep (WaitForRolloverReadyStep .NAME )
200- .setPhaseDefinition (PHASE_DEFINITION );
201- String indexInCheckRolloverStep = "index_in_check_rollover" ;
202- IndexMetadata indexMetadata = IndexMetadata .builder (indexInCheckRolloverStep )
203- .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
204- .numberOfShards (randomIntBetween (1 , 5 ))
205- .numberOfReplicas (randomIntBetween (0 , 5 ))
206- .putCustom (ILM_CUSTOM_METADATA_KEY , checkRolloverReadyStepState .build ().asMap ())
207- .build ();
208- ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
209- .put (indexMetadata , true )
210- .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
211- .build ();
212-
213- IndexLifecycleExplainResponse response = getIndexLifecycleExplainResponse (
214- indexInCheckRolloverStep ,
215- project ,
216- false ,
217- true ,
218- REGISTRY ,
219- true
220- );
221- var rolloverAction = ((RolloverAction ) response .getPhaseExecutionInfo ().getPhase ().getActions ().get (RolloverAction .NAME ));
222- assertThat (rolloverAction , notNullValue ());
223- assertThat (rolloverAction .getConditions ().getMinDocs (), is (1L ));
224- }
189+ public void testGetIndexLifecycleExplainResponse_rolloverOnlyIfHasDocuments_addsCondition () throws IOException {
190+ LifecycleExecutionState .Builder checkRolloverReadyStepState = LifecycleExecutionState .builder ()
191+ .setPhase ("hot" )
192+ .setAction ("rollover" )
193+ .setStep (WaitForRolloverReadyStep .NAME )
194+ .setPhaseDefinition (PHASE_DEFINITION );
195+ String indexInCheckRolloverStep = "index_in_check_rollover" ;
196+ IndexMetadata indexMetadata = IndexMetadata .builder (indexInCheckRolloverStep )
197+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , POLICY_NAME ))
198+ .numberOfShards (randomIntBetween (1 , 5 ))
199+ .numberOfReplicas (randomIntBetween (0 , 5 ))
200+ .putCustom (ILM_CUSTOM_METADATA_KEY , checkRolloverReadyStepState .build ().asMap ())
201+ .build ();
202+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ())
203+ .put (indexMetadata , true )
204+ .putCustom (IndexLifecycleMetadata .TYPE , createIndexLifecycleMetadata ())
205+ .build ();
206+
207+ IndexLifecycleExplainResponse response = getIndexLifecycleExplainResponse (
208+ indexInCheckRolloverStep ,
209+ project ,
210+ false ,
211+ true ,
212+ REGISTRY ,
213+ true
214+ );
215+ var rolloverAction = ((RolloverAction ) response .getPhaseExecutionInfo ().getPhase ().getActions ().get (RolloverAction .NAME ));
216+ assertThat (rolloverAction , notNullValue ());
217+ assertThat (rolloverAction .getConditions ().getMinDocs (), is (1L ));
225218 }
226219
227220 private static IndexLifecycleMetadata createIndexLifecycleMetadata () {
0 commit comments