Skip to content

Commit a080f07

Browse files
nik9000kcm
authored andcommitted
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
1 parent e420b78 commit a080f07

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
2727
import org.apache.http.ssl.SSLContexts;
2828
import org.apache.http.util.EntityUtils;
29+
import org.elasticsearch.Version;
2930
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
3031
import org.elasticsearch.client.Request;
3132
import org.elasticsearch.client.Response;
@@ -73,6 +74,7 @@
7374
import java.util.List;
7475
import java.util.Map;
7576
import java.util.Set;
77+
import java.util.TreeSet;
7678
import java.util.concurrent.TimeUnit;
7779
import java.util.function.Predicate;
7880

@@ -105,25 +107,13 @@ public static Map<String, Object> entityAsMap(Response response) throws IOExcept
105107
}
106108

107109
/**
108-
* Does the cluster being tested have xpack installed?
110+
* Does any node in the cluster being tested have x-pack installed?
109111
*/
110112
public static boolean hasXPack() throws IOException {
111-
RestClient client = adminClient();
112-
if (client == null) {
113+
if (hasXPack == null) {
113114
throw new IllegalStateException("must be called inside of a rest test case test");
114115
}
115-
Map<?, ?> response = entityAsMap(client.performRequest(new Request("GET", "_nodes/plugins")));
116-
Map<?, ?> nodes = (Map<?, ?>) response.get("nodes");
117-
for (Map.Entry<?, ?> node : nodes.entrySet()) {
118-
Map<?, ?> nodeInfo = (Map<?, ?>) node.getValue();
119-
for (Object module: (List<?>) nodeInfo.get("modules")) {
120-
Map<?, ?> moduleInfo = (Map<?, ?>) module;
121-
if (moduleInfo.get("name").toString().startsWith("x-pack-")) {
122-
return true;
123-
}
124-
}
125-
}
126-
return false;
116+
return hasXPack;
127117
}
128118

129119
private static List<HttpHost> clusterHosts;
@@ -136,12 +126,16 @@ public static boolean hasXPack() throws IOException {
136126
* completes
137127
*/
138128
private static RestClient adminClient;
129+
private static Boolean hasXPack;
130+
private static TreeSet<Version> nodeVersions;
139131

140132
@Before
141133
public void initClient() throws IOException {
142134
if (client == null) {
143135
assert adminClient == null;
144136
assert clusterHosts == null;
137+
assert hasXPack == null;
138+
assert nodeVersions == null;
145139
String cluster = System.getProperty("tests.rest.cluster");
146140
if (cluster == null) {
147141
throw new RuntimeException("Must specify [tests.rest.cluster] system property with a comma delimited list of [host:port] "
@@ -162,10 +156,27 @@ public void initClient() throws IOException {
162156
logger.info("initializing REST clients against {}", clusterHosts);
163157
client = buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()]));
164158
adminClient = buildClient(restAdminSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()]));
159+
160+
hasXPack = false;
161+
nodeVersions = new TreeSet<>();
162+
Map<?, ?> response = entityAsMap(adminClient.performRequest(new Request("GET", "_nodes/plugins")));
163+
Map<?, ?> nodes = (Map<?, ?>) response.get("nodes");
164+
for (Map.Entry<?, ?> node : nodes.entrySet()) {
165+
Map<?, ?> nodeInfo = (Map<?, ?>) node.getValue();
166+
nodeVersions.add(Version.fromString(nodeInfo.get("version").toString()));
167+
for (Object module: (List<?>) nodeInfo.get("modules")) {
168+
Map<?, ?> moduleInfo = (Map<?, ?>) module;
169+
if (moduleInfo.get("name").toString().startsWith("x-pack-")) {
170+
hasXPack = true;
171+
}
172+
}
173+
}
165174
}
166175
assert client != null;
167176
assert adminClient != null;
168177
assert clusterHosts != null;
178+
assert hasXPack != null;
179+
assert nodeVersions != null;
169180
}
170181

171182
/**
@@ -195,6 +206,8 @@ public static void closeClients() throws IOException {
195206
clusterHosts = null;
196207
client = null;
197208
adminClient = null;
209+
hasXPack = null;
210+
nodeVersions = null;
198211
}
199212
}
200213

@@ -335,8 +348,6 @@ protected boolean preserveRollupJobsUponCompletion() {
335348
}
336349

337350
private void wipeCluster() throws Exception {
338-
boolean hasXPack = hasXPack();
339-
340351
if (preserveIndicesUponCompletion() == false) {
341352
// wipe indices
342353
try {

0 commit comments

Comments
 (0)