|
@@ -539,6 +539,15 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns whether to preserve searchable snapshots indices. Defaults to not
|
|
|
+ * preserving them. Only runs at all if xpack is installed on the cluster
|
|
|
+ * being tested.
|
|
|
+ */
|
|
|
+ protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns whether to wait to make absolutely certain that all snapshots
|
|
|
* have been deleted.
|
|
@@ -560,6 +569,11 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
deleteAllSLMPolicies();
|
|
|
}
|
|
|
|
|
|
+ // Clean up searchable snapshots indices before deleting snapshots and repositories
|
|
|
+ if (hasXPack() && nodeVersions.first().onOrAfter(Version.V_7_8_0) && preserveSearchableSnapshotsIndicesUponCompletion() == false) {
|
|
|
+ wipeSearchableSnapshotsIndices();
|
|
|
+ }
|
|
|
+
|
|
|
SetOnce<Map<String, List<Map<?,?>>>> inProgressSnapshots = new SetOnce<>();
|
|
|
if (waitForAllSnapshotsWiped()) {
|
|
|
AtomicReference<Map<String, List<Map<?,?>>>> snapshots = new AtomicReference<>();
|
|
@@ -787,6 +801,22 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected void wipeSearchableSnapshotsIndices() throws IOException {
|
|
|
+ // retrieves all indices with a type of store equals to "snapshot"
|
|
|
+ final Request request = new Request("GET", "_cluster/state/metadata");
|
|
|
+ request.addParameter("filter_path", "metadata.indices.*.settings.index.store.snapshot");
|
|
|
+
|
|
|
+ final Response response = adminClient().performRequest(request);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, ?> indices = (Map<String, ?>) XContentMapValues.extractValue("metadata.indices", entityAsMap(response));
|
|
|
+ if (indices != null) {
|
|
|
+ for (String index : indices.keySet()) {
|
|
|
+ assertAcked("Failed to delete searchable snapshot index [" + index + ']',
|
|
|
+ adminClient().performRequest(new Request("DELETE", index)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
|
|
|
* start empty. There isn't an API to delete all snapshots. There is an API to delete all snapshot repositories but that leaves all of
|