Skip to content

Commit c46fb14

Browse files
committed
Searchable snapshot cleanup WIP
1 parent 66d1a8e commit c46fb14

File tree

2 files changed

+91
-254
lines changed

2 files changed

+91
-254
lines changed

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.concurrent.TimeUnit;
5151

5252
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
53+
import static org.elasticsearch.test.ESTestCase.assertThat;
5354
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLengthBetween;
5455
import static org.elasticsearch.test.ESTestCase.randomBoolean;
5556
import static org.elasticsearch.test.ESTestCase.waitUntil;
@@ -59,8 +60,6 @@
5960
import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
6061
import static org.hamcrest.Matchers.anyOf;
6162
import static org.hamcrest.Matchers.equalTo;
62-
import static org.hamcrest.Matchers.is;
63-
import static org.junit.Assert.assertThat;
6463

6564
/**
6665
* This class provides the operational REST functions needed to control an ILM time series lifecycle.
@@ -80,7 +79,7 @@ public static Step.StepKey getStepKeyForIndex(RestClient client, String indexNam
8079
return getStepKey(indexResponse);
8180
}
8281

83-
private static Step.StepKey getStepKey(Map<String, Object> explainIndexResponse) {
82+
public static Step.StepKey getStepKey(Map<String, Object> explainIndexResponse) {
8483
String phase = (String) explainIndexResponse.get("phase");
8584
String action = (String) explainIndexResponse.get("action");
8685
String step = (String) explainIndexResponse.get("step");
@@ -105,14 +104,26 @@ public static Map<String, Map<String, Object>> explain(RestClient client, String
105104
explainRequest.addParameter("only_managed", Boolean.toString(onlyManaged));
106105
explainRequest.setOptions(consumeWarningsOptions);
107106
Response response = client.performRequest(explainRequest);
108-
Map<String, Object> responseMap;
109-
try (InputStream is = response.getEntity().getContent()) {
110-
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
111-
}
107+
ObjectPath objectPath = ObjectPath.createFromResponse(response);
108+
return objectPath.evaluate("indices");
109+
}
112110

113-
@SuppressWarnings("unchecked")
114-
Map<String, Map<String, Object>> indexResponse = ((Map<String, Map<String, Object>>) responseMap.get("indices"));
115-
return indexResponse;
111+
/**
112+
* Waits until the specified index is at the specified ILM step. If any of phase, action, or step is null, that part is ignored.
113+
*/
114+
public static void awaitStepKey(RestClient client, String indexName, String phase, String action, String step) throws Exception {
115+
ESRestTestCase.assertBusy(() -> {
116+
final Step.StepKey stepKey = getStepKeyForIndex(client, indexName);
117+
if (phase != null) {
118+
assertThat(stepKey.phase(), equalTo(phase));
119+
}
120+
if (action != null) {
121+
assertThat(stepKey.action(), equalTo(action));
122+
}
123+
if (step != null) {
124+
assertThat(stepKey.name(), equalTo(step));
125+
}
126+
});
116127
}
117128

118129
public static void indexDocument(RestClient client, String indexAbstractionName) throws IOException {
@@ -501,24 +512,6 @@ public static String waitAndGetShrinkIndexName(RestClient client, String origina
501512
return shrunkenIndexName[0];
502513
}
503514

504-
@SuppressWarnings("unchecked")
505-
public static List<String> getBackingIndices(RestClient client, String dataStreamName) throws IOException {
506-
Response getDataStream = client.performRequest(new Request("GET", "_data_stream/" + dataStreamName));
507-
Map<String, Object> responseMap;
508-
try (InputStream is = getDataStream.getEntity().getContent()) {
509-
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
510-
}
511-
512-
List<Map<String, Object>> dataStreams = (List<Map<String, Object>>) responseMap.get("data_streams");
513-
assertThat(dataStreams.size(), is(1));
514-
Map<String, Object> dataStream = dataStreams.get(0);
515-
assertThat(dataStream.get("name"), is(dataStreamName));
516-
List<String> indices = ((List<Map<String, Object>>) dataStream.get("indices")).stream()
517-
.map(indexMap -> (String) indexMap.get("index_name"))
518-
.toList();
519-
return indices;
520-
}
521-
522515
private static void executeDummyClusterStateUpdate(RestClient client) throws IOException {
523516
createIndexWithSettings(
524517
client,

0 commit comments

Comments
 (0)