From b2af6cc1f2e46e2637e0a55987bae970976a0015 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 18 Mar 2021 10:49:57 +0100 Subject: [PATCH] Made small modifications to ESRestTestCase. (#70537) Backporting #70531 to the 7.x branch. * Don't try to invoke delete component/index templates APIs if there are no templates to delete. * Don't delete deprecation templates by marking these as xpack templates. Relates to #69973 --- .../test/rest/ESRestTestCase.java | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index 68dea5c502be9..2ab7906d650b1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -614,20 +614,23 @@ private void wipeCluster() throws Exception { .map(ct -> (String) ((Map) ct).get("name")) .filter(name -> isXPackTemplate(name) == false) .collect(Collectors.toList()); - // Ideally we would want to check the version of the elected master node and - // send the delete request directly to that node. - if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) { - try { - adminClient().performRequest(new Request("DELETE", "_index_template/" + String.join(",", names))); - } catch (ResponseException e) { - logger.warn(new ParameterizedMessage("unable to remove multiple composable index templates {}", names), e); - } - } else { - for (String name : names) { + if (names.isEmpty() == false) { + // Ideally we would want to check the version of the elected master node and + // send the delete request directly to that node. + if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) { try { - adminClient().performRequest(new Request("DELETE", "_index_template/" + name)); + adminClient().performRequest(new Request("DELETE", "_index_template/" + String.join(",", names))); } catch (ResponseException e) { - logger.warn(new ParameterizedMessage("unable to remove composable index template {}", name), e); + logger.warn( + new ParameterizedMessage("unable to remove multiple composable index templates {}", names), e); + } + } else { + for (String name : names) { + try { + adminClient().performRequest(new Request("DELETE", "_index_template/" + name)); + } catch (ResponseException e) { + logger.warn(new ParameterizedMessage("unable to remove composable index template {}", name), e); + } } } } @@ -644,23 +647,27 @@ private void wipeCluster() throws Exception { .map(ct -> (String) ((Map) ct).get("name")) .filter(name -> isXPackTemplate(name) == false) .collect(Collectors.toList()); - // Ideally we would want to check the version of the elected master node and - // send the delete request directly to that node. - if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) { - try { - adminClient().performRequest(new Request("DELETE", "_component_template/" + String.join(",", names))); - } catch (ResponseException e) { - logger.warn(new ParameterizedMessage("unable to remove multiple component templates {}", names), e); - } - }else { - for (String componentTemplate : names) { + if (names.isEmpty() == false) { + // Ideally we would want to check the version of the elected master node and + // send the delete request directly to that node. + if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) { try { - adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate)); - } catch (ResponseException e) { - logger.warn(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e); + adminClient().performRequest(new Request("DELETE", "_component_template/" + String.join(",", names))); + } catch (ResponseException e) { + logger.warn(new ParameterizedMessage("unable to remove multiple component templates {}", names), e); + } + } else { + for (String componentTemplate : names) { + try { + adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate)); + } catch (ResponseException e) { + logger.warn( + new ParameterizedMessage("unable to remove component template {}", componentTemplate), e); + } + } } } - }} catch (Exception e) { + } catch (Exception e) { logger.debug("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 } @@ -1436,13 +1443,15 @@ protected static boolean isXPackTemplate(String name) { if (name.startsWith(".transform-")) { return true; } + if (name.startsWith(".deprecation-")) { + return true; + } switch (name) { case ".watches": case "security_audit_log": case ".slm-history": case ".async-search": case "saml-service-provider": - case "ilm-history": case "logs": case "logs-settings": case "logs-mappings": @@ -1453,7 +1462,7 @@ protected static boolean isXPackTemplate(String name) { case "synthetics-settings": case "synthetics-mappings": case ".snapshot-blob-cache": - case ".deprecation-indexing-template": + case "ilm-history": case "logstash-index-template": case "security-index-template": return true;