From 59df6e868902330412107c6640dc2fdb4c511365 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 25 Oct 2018 14:02:30 -0400 Subject: [PATCH] Test: Lookup node versions on rest test start (#34657) This is a forward port of a change made to clean up backwards compatibility for the rollup cleanups. It makes the version of each node available very early on in test execution. The 6.x version of the change used those versions to control the cleanup backwards compatibility but that isn't needed in this branch. But having the versions around *is* useful. So this makes them available. Closes #34629 --- .../test/rest/ESRestTestCase.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 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 72299dab912..a540af459a1 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 @@ -26,6 +26,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.Version; import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; @@ -73,6 +74,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -105,25 +107,13 @@ public abstract class ESRestTestCase extends ESTestCase { } /** - * Does the cluster being tested have xpack installed? + * Does any node in the cluster being tested have x-pack installed? */ public static boolean hasXPack() throws IOException { - RestClient client = adminClient(); - if (client == null) { + if (hasXPack == null) { throw new IllegalStateException("must be called inside of a rest test case test"); } - Map response = entityAsMap(client.performRequest(new Request("GET", "_nodes/plugins"))); - Map nodes = (Map) response.get("nodes"); - for (Map.Entry node : nodes.entrySet()) { - Map nodeInfo = (Map) node.getValue(); - for (Object module: (List) nodeInfo.get("modules")) { - Map moduleInfo = (Map) module; - if (moduleInfo.get("name").toString().startsWith("x-pack-")) { - return true; - } - } - } - return false; + return hasXPack; } private static List clusterHosts; @@ -136,12 +126,16 @@ public abstract class ESRestTestCase extends ESTestCase { * completes */ private static RestClient adminClient; + private static Boolean hasXPack; + private static TreeSet nodeVersions; @Before public void initClient() throws IOException { if (client == null) { assert adminClient == null; assert clusterHosts == null; + assert hasXPack == null; + assert nodeVersions == null; String cluster = System.getProperty("tests.rest.cluster"); if (cluster == null) { throw new RuntimeException("Must specify [tests.rest.cluster] system property with a comma delimited list of [host:port] " @@ -162,10 +156,27 @@ public abstract class ESRestTestCase extends ESTestCase { logger.info("initializing REST clients against {}", clusterHosts); client = buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()])); adminClient = buildClient(restAdminSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()])); + + hasXPack = false; + nodeVersions = new TreeSet<>(); + Map response = entityAsMap(adminClient.performRequest(new Request("GET", "_nodes/plugins"))); + Map nodes = (Map) response.get("nodes"); + for (Map.Entry node : nodes.entrySet()) { + Map nodeInfo = (Map) node.getValue(); + nodeVersions.add(Version.fromString(nodeInfo.get("version").toString())); + for (Object module: (List) nodeInfo.get("modules")) { + Map moduleInfo = (Map) module; + if (moduleInfo.get("name").toString().startsWith("x-pack-")) { + hasXPack = true; + } + } + } } assert client != null; assert adminClient != null; assert clusterHosts != null; + assert hasXPack != null; + assert nodeVersions != null; } /** @@ -195,6 +206,8 @@ public abstract class ESRestTestCase extends ESTestCase { clusterHosts = null; client = null; adminClient = null; + hasXPack = null; + nodeVersions = null; } } @@ -335,8 +348,6 @@ public abstract class ESRestTestCase extends ESTestCase { } private void wipeCluster() throws Exception { - boolean hasXPack = hasXPack(); - if (preserveIndicesUponCompletion() == false) { // wipe indices try {