Skip to content

Test: Do not remove xpack templates when cleaning #31642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 5, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.http.message.BasicHeader;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
Expand Down Expand Up @@ -258,7 +259,7 @@ private void wipeCluster() throws IOException {
if (preserveIndicesUponCompletion() == false) {
// wipe indices
try {
adminClient().performRequest("DELETE", "*");
adminClient().performRequest(new Request("DELETE", "*"));
} catch (ResponseException e) {
// 404 here just means we had no indexes
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
Expand All @@ -269,7 +270,23 @@ private void wipeCluster() throws IOException {

// wipe index templates
if (preserveTemplatesUponCompletion() == false) {
adminClient().performRequest("DELETE", "_template/*");
if (hasXPack()) {
/*
* Delete only templates that xpack doesn't automatically
* recreate. Deleting them doesn't hurt anything, but it
* slows down the test because xpack will just recreate
* them.
*/
Request request = new Request("GET", "_cat/templates");
request.addParameter("h", "name");
String templates = EntityUtils.toString(adminClient().performRequest(request).getEntity());
for (String template : templates.split("\n")) {
if (isXPackTemplate(template)) continue;
adminClient().performRequest(new Request("DELETE", "_template/" + template));
}
} else {
adminClient().performRequest(new Request("DELETE", "_template/*"));
}
}

wipeSnapshots();
Expand Down Expand Up @@ -577,4 +594,31 @@ protected static Map<String, Object> getAsMap(final String endpoint) throws IOEx
assertNotNull(responseEntity);
return responseEntity;
}

/**
* Is this template one that is automatically created by xpack? Deleting
* these templates doesn't hurt anything but it makes the tests run more
* slowly because it then has to wait for the templates to be recreated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems kind of odd for a true/false isXXX method :) It cares not about a delete.

*/
private static boolean isXPackTemplate(String name) {
if (name.startsWith(".monitoring-")) {
return true;
}
if (name.startsWith(".watch-history-")) {
return true;
}
if (name.startsWith(".ml-")) {
return true;
}
switch (name) {
case ".triggered_watches":
case ".watches":
case "logstash-index-template":
case "security_audit_log":
return true;
default:
return false;
}
}

}