|
37 | 37 | import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; |
38 | 38 | import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType; |
39 | 39 | import org.elasticsearch.xpack.core.indexlifecycle.MockAction; |
| 40 | +import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; |
40 | 41 | import org.elasticsearch.xpack.core.indexlifecycle.Phase; |
41 | 42 | import org.elasticsearch.xpack.core.indexlifecycle.PhaseExecutionInfo; |
42 | 43 | import org.elasticsearch.xpack.core.indexlifecycle.Step; |
| 44 | +import org.elasticsearch.xpack.core.indexlifecycle.StopILMRequest; |
43 | 45 | import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep; |
44 | 46 | import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction; |
45 | 47 | import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; |
| 48 | +import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; |
46 | 49 | import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; |
| 50 | +import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; |
47 | 51 | import org.junit.Before; |
48 | 52 |
|
49 | 53 | import java.io.IOException; |
@@ -364,6 +368,39 @@ public void testMasterFailover() throws Exception { |
364 | 368 | }); |
365 | 369 | } |
366 | 370 |
|
| 371 | + public void testCreatePolicyWhenStopped() throws Exception { |
| 372 | + // start master node |
| 373 | + logger.info("Starting server1"); |
| 374 | + final String server_1 = internalCluster().startNode(); |
| 375 | + final String node1 = getLocalNodeId(server_1); |
| 376 | + |
| 377 | + assertAcked(client().execute(StopILMAction.INSTANCE, new StopILMRequest()).get()); |
| 378 | + assertBusy(() -> assertThat( |
| 379 | + client().execute(GetStatusAction.INSTANCE, new GetStatusAction.Request()).get().getMode(), |
| 380 | + equalTo(OperationMode.STOPPED))); |
| 381 | + |
| 382 | + logger.info("Creating lifecycle [test_lifecycle]"); |
| 383 | + PutLifecycleAction.Request putLifecycleRequest = new PutLifecycleAction.Request(lifecyclePolicy); |
| 384 | + long lowerBoundModifiedDate = Instant.now().toEpochMilli(); |
| 385 | + PutLifecycleAction.Response putLifecycleResponse = client().execute(PutLifecycleAction.INSTANCE, putLifecycleRequest).get(); |
| 386 | + assertAcked(putLifecycleResponse); |
| 387 | + long upperBoundModifiedDate = Instant.now().toEpochMilli(); |
| 388 | + |
| 389 | + // assert version and modified_date |
| 390 | + GetLifecycleAction.Response getLifecycleResponse = client().execute(GetLifecycleAction.INSTANCE, |
| 391 | + new GetLifecycleAction.Request()).get(); |
| 392 | + assertThat(getLifecycleResponse.getPolicies().size(), equalTo(1)); |
| 393 | + GetLifecycleAction.LifecyclePolicyResponseItem responseItem = getLifecycleResponse.getPolicies().get(0); |
| 394 | + assertThat(responseItem.getLifecyclePolicy(), equalTo(lifecyclePolicy)); |
| 395 | + assertThat(responseItem.getVersion(), equalTo(1L)); |
| 396 | + long actualModifiedDate = Instant.parse(responseItem.getModifiedDate()).toEpochMilli(); |
| 397 | + assertThat(actualModifiedDate, |
| 398 | + is(both(greaterThanOrEqualTo(lowerBoundModifiedDate)).and(lessThanOrEqualTo(upperBoundModifiedDate)))); |
| 399 | + // assert ILM is still stopped |
| 400 | + GetStatusAction.Response statusResponse = client().execute(GetStatusAction.INSTANCE, new GetStatusAction.Request()).get(); |
| 401 | + assertThat(statusResponse.getMode(), equalTo(OperationMode.STOPPED)); |
| 402 | + } |
| 403 | + |
367 | 404 | public void testPollIntervalUpdate() throws Exception { |
368 | 405 | TimeValue pollInterval = TimeValue.timeValueSeconds(randomLongBetween(1, 5)); |
369 | 406 | final String server_1 = internalCluster().startMasterOnlyNode( |
|
0 commit comments