|
@@ -97,7 +97,6 @@ import static java.util.Collections.sort;
|
|
|
import static java.util.Collections.unmodifiableList;
|
|
|
import static org.hamcrest.Matchers.anEmptyMap;
|
|
|
import static org.hamcrest.Matchers.anyOf;
|
|
|
-import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.everyItem;
|
|
|
import static org.hamcrest.Matchers.in;
|
|
@@ -572,28 +571,26 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
* 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());
|
|
|
- if (false == "".equals(templates)) {
|
|
|
- for (String template : templates.split("\n")) {
|
|
|
- if (isXPackTemplate(template)) continue;
|
|
|
- if ("".equals(template)) {
|
|
|
- throw new IllegalStateException("empty template in templates list:\n" + templates);
|
|
|
+ try {
|
|
|
+ Request getTemplatesRequest = new Request("GET", "_index_template");
|
|
|
+ Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
|
|
|
+ EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
|
|
|
+ List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
|
|
|
+ .map(ct -> (String) ((Map<?, ?>) ct).get("name"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (String name : names) {
|
|
|
+ if (isXPackTemplate(name)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- logger.info("Clearing template [{}]", template);
|
|
|
try {
|
|
|
- adminClient().performRequest(new Request("DELETE", "_template/" + template));
|
|
|
+ adminClient().performRequest(new Request("DELETE", "_index_template/" + name));
|
|
|
} catch (ResponseException e) {
|
|
|
- // This is fine, it could be a V2 template
|
|
|
- assertThat(e.getMessage(), containsString("index_template [" + template + "] missing"));
|
|
|
- try {
|
|
|
- adminClient().performRequest(new Request("DELETE", "_index_template/" + template));
|
|
|
- } catch (ResponseException e2) {
|
|
|
- // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
|
|
|
- }
|
|
|
+ logger.debug(new ParameterizedMessage("unable to remove index template {}", name), e);
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("ignoring exception removing all composable index templates", e);
|
|
|
+ // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
|
|
|
}
|
|
|
try {
|
|
|
Request compReq = new Request("GET", "_component_template");
|
|
@@ -610,13 +607,26 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|
|
}
|
|
|
adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate));
|
|
|
} catch (ResponseException e) {
|
|
|
- logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
|
|
|
+ logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.info("ignoring exception removing all component templates", e);
|
|
|
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
|
|
|
}
|
|
|
+ Request getLegacyTemplatesRequest = new Request("GET", "_template");
|
|
|
+ Map<String, Object> legacyTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
|
|
|
+ EntityUtils.toString(adminClient().performRequest(getLegacyTemplatesRequest).getEntity()), false);
|
|
|
+ for (String name : legacyTemplates.keySet()) {
|
|
|
+ if (isXPackTemplate(name)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ adminClient().performRequest(new Request("DELETE", "_template/" + name));
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ logger.debug(new ParameterizedMessage("unable to remove index template {}", name), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
logger.debug("Clearing all templates");
|
|
|
adminClient().performRequest(new Request("DELETE", "_template/*"));
|