26
26
import org .apache .http .nio .conn .ssl .SSLIOSessionStrategy ;
27
27
import org .apache .http .ssl .SSLContexts ;
28
28
import org .apache .http .util .EntityUtils ;
29
+ import org .elasticsearch .Version ;
29
30
import org .elasticsearch .action .admin .cluster .node .tasks .list .ListTasksAction ;
30
31
import org .elasticsearch .client .Request ;
31
32
import org .elasticsearch .client .Response ;
73
74
import java .util .List ;
74
75
import java .util .Map ;
75
76
import java .util .Set ;
77
+ import java .util .TreeSet ;
76
78
import java .util .concurrent .TimeUnit ;
77
79
import java .util .function .Predicate ;
78
80
@@ -105,25 +107,13 @@ public static Map<String, Object> entityAsMap(Response response) throws IOExcept
105
107
}
106
108
107
109
/**
108
- * Does the cluster being tested have xpack installed?
110
+ * Does any node in the cluster being tested have x-pack installed?
109
111
*/
110
112
public static boolean hasXPack () throws IOException {
111
- RestClient client = adminClient ();
112
- if (client == null ) {
113
+ if (hasXPack == null ) {
113
114
throw new IllegalStateException ("must be called inside of a rest test case test" );
114
115
}
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 ;
127
117
}
128
118
129
119
private static List <HttpHost > clusterHosts ;
@@ -136,12 +126,16 @@ public static boolean hasXPack() throws IOException {
136
126
* completes
137
127
*/
138
128
private static RestClient adminClient ;
129
+ private static Boolean hasXPack ;
130
+ private static TreeSet <Version > nodeVersions ;
139
131
140
132
@ Before
141
133
public void initClient () throws IOException {
142
134
if (client == null ) {
143
135
assert adminClient == null ;
144
136
assert clusterHosts == null ;
137
+ assert hasXPack == null ;
138
+ assert nodeVersions == null ;
145
139
String cluster = System .getProperty ("tests.rest.cluster" );
146
140
if (cluster == null ) {
147
141
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 {
162
156
logger .info ("initializing REST clients against {}" , clusterHosts );
163
157
client = buildClient (restClientSettings (), clusterHosts .toArray (new HttpHost [clusterHosts .size ()]));
164
158
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
+ }
165
174
}
166
175
assert client != null ;
167
176
assert adminClient != null ;
168
177
assert clusterHosts != null ;
178
+ assert hasXPack != null ;
179
+ assert nodeVersions != null ;
169
180
}
170
181
171
182
/**
@@ -195,6 +206,8 @@ public static void closeClients() throws IOException {
195
206
clusterHosts = null ;
196
207
client = null ;
197
208
adminClient = null ;
209
+ hasXPack = null ;
210
+ nodeVersions = null ;
198
211
}
199
212
}
200
213
@@ -335,8 +348,6 @@ protected boolean preserveRollupJobsUponCompletion() {
335
348
}
336
349
337
350
private void wipeCluster () throws Exception {
338
- boolean hasXPack = hasXPack ();
339
-
340
351
if (preserveIndicesUponCompletion () == false ) {
341
352
// wipe indices
342
353
try {
0 commit comments