|
@@ -282,7 +282,8 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
/**
|
|
|
* Returns whether to preserve the state of the cluster upon completion of this test. Defaults to false. If true, overrides the value of
|
|
|
* {@link #preserveIndicesUponCompletion()}, {@link #preserveTemplatesUponCompletion()}, {@link #preserveReposUponCompletion()},
|
|
|
- * {@link #preserveSnapshotsUponCompletion()}, and {@link #preserveRollupJobsUponCompletion()}.
|
|
|
+ * {@link #preserveSnapshotsUponCompletion()},{@link #preserveRollupJobsUponCompletion()},
|
|
|
+ * and {@link #preserveILMPoliciesUponCompletion()}.
|
|
|
*
|
|
|
* @return true if the state of the cluster should be preserved
|
|
|
*/
|
|
@@ -347,6 +348,15 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns whether to preserve ILM Policies of this test. Defaults to not
|
|
|
+ * preserviing them. Only runs at all if xpack is installed on the cluster
|
|
|
+ * being tested.
|
|
|
+ */
|
|
|
+ protected boolean preserveILMPoliciesUponCompletion() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private void wipeCluster() throws Exception {
|
|
|
if (preserveIndicesUponCompletion() == false) {
|
|
|
// wipe indices
|
|
@@ -399,6 +409,10 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
wipeRollupJobs();
|
|
|
waitForPendingRollupTasks();
|
|
|
}
|
|
|
+
|
|
|
+ if (hasXPack && false == preserveILMPoliciesUponCompletion()) {
|
|
|
+ deleteAllPolicies();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -509,6 +523,29 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith("xpack/rollup/job") == false);
|
|
|
}
|
|
|
|
|
|
+ private static void deleteAllPolicies() throws IOException {
|
|
|
+ Map<String, Object> policies;
|
|
|
+
|
|
|
+ try {
|
|
|
+ Response response = adminClient().performRequest(new Request("GET", "/_ilm"));
|
|
|
+ policies = entityAsMap(response);
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ if (RestStatus.BAD_REQUEST.getStatus() == e.getResponse().getStatusLine().getStatusCode()) {
|
|
|
+ // If bad request returned, ILM is not enabled.
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (policies == null || policies.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String policyName : policies.keySet()) {
|
|
|
+ adminClient().performRequest(new Request("DELETE", "/_ilm/" + policyName));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Logs a message if there are still running tasks. The reasoning is that any tasks still running are state the is trying to bleed into
|
|
|
* other tests.
|