|
23 | 23 | import org.elasticsearch.common.xcontent.XContentHelper; |
24 | 24 | import org.elasticsearch.core.Nullable; |
25 | 25 | import org.elasticsearch.core.TimeValue; |
| 26 | +import org.elasticsearch.test.rest.ESRestTestCase; |
26 | 27 | import org.elasticsearch.xcontent.ToXContent; |
27 | 28 | import org.elasticsearch.xcontent.XContentBuilder; |
28 | 29 | import org.elasticsearch.xcontent.XContentType; |
|
58 | 59 | import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; |
59 | 60 | import static org.hamcrest.Matchers.anyOf; |
60 | 61 | import static org.hamcrest.Matchers.equalTo; |
61 | | -import static org.hamcrest.Matchers.is; |
62 | 62 | import static org.junit.Assert.assertThat; |
63 | 63 |
|
64 | 64 | /** |
@@ -403,6 +403,28 @@ public static void updatePolicy(RestClient client, String indexName, String poli |
403 | 403 | assertOK(client.performRequest(changePolicyRequest)); |
404 | 404 | } |
405 | 405 |
|
| 406 | + /** |
| 407 | + * Moves the specified index from the current ILM step to the next step. |
| 408 | + */ |
| 409 | + public static void moveIndexToStep(RestClient client, String indexName, Step.StepKey currentStep, Step.StepKey nextStep) |
| 410 | + throws IOException { |
| 411 | + Request moveToStepRequest = new Request("POST", "_ilm/move/" + indexName); |
| 412 | + moveToStepRequest.setJsonEntity(Strings.format(""" |
| 413 | + { |
| 414 | + "current_step": { |
| 415 | + "phase": "%s", |
| 416 | + "action": "%s", |
| 417 | + "name": "%s" |
| 418 | + }, |
| 419 | + "next_step": { |
| 420 | + "phase": "%s", |
| 421 | + "action": "%s", |
| 422 | + "name": "%s" |
| 423 | + } |
| 424 | + }""", currentStep.phase(), currentStep.action(), currentStep.name(), nextStep.phase(), nextStep.action(), nextStep.name())); |
| 425 | + ESRestTestCase.assertAcknowledged(client.performRequest(moveToStepRequest)); |
| 426 | + } |
| 427 | + |
406 | 428 | @SuppressWarnings("unchecked") |
407 | 429 | public static String getSnapshotState(RestClient client, String snapshot) throws IOException { |
408 | 430 | Response response = client.performRequest(new Request("GET", "/_snapshot/repo/" + snapshot)); |
@@ -485,24 +507,6 @@ public static String waitAndGetShrinkIndexName(RestClient client, String origina |
485 | 507 | return shrunkenIndexName[0]; |
486 | 508 | } |
487 | 509 |
|
488 | | - @SuppressWarnings("unchecked") |
489 | | - public static List<String> getBackingIndices(RestClient client, String dataStreamName) throws IOException { |
490 | | - Response getDataStream = client.performRequest(new Request("GET", "_data_stream/" + dataStreamName)); |
491 | | - Map<String, Object> responseMap; |
492 | | - try (InputStream is = getDataStream.getEntity().getContent()) { |
493 | | - responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); |
494 | | - } |
495 | | - |
496 | | - List<Map<String, Object>> dataStreams = (List<Map<String, Object>>) responseMap.get("data_streams"); |
497 | | - assertThat(dataStreams.size(), is(1)); |
498 | | - Map<String, Object> dataStream = dataStreams.get(0); |
499 | | - assertThat(dataStream.get("name"), is(dataStreamName)); |
500 | | - List<String> indices = ((List<Map<String, Object>>) dataStream.get("indices")).stream() |
501 | | - .map(indexMap -> (String) indexMap.get("index_name")) |
502 | | - .toList(); |
503 | | - return indices; |
504 | | - } |
505 | | - |
506 | 510 | private static void executeDummyClusterStateUpdate(RestClient client) throws IOException { |
507 | 511 | createIndexWithSettings( |
508 | 512 | client, |
|
0 commit comments