diff --git a/client-sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java b/client-sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java index 4af9d205589..cc3abdfec7e 100644 --- a/client-sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java +++ b/client-sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java @@ -38,9 +38,9 @@ import java.util.List; import java.util.Map; /** - * Class responsible for sniffing the http hosts from elasticsearch through the nodes info api and returning them back + * Class responsible for sniffing the http hosts from elasticsearch through the nodes info api and returning them back. + * Compatible with elasticsearch 5.x and 2.x. */ -//TODO This could potentially be using _cat/nodes which wouldn't require jackson as a dependency, but we'd have bw comp problems with 2.x public class HostsSniffer { private static final Log logger = LogFactory.getLog(HostsSniffer.class); diff --git a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java index 88f0480f92a..57705c1b832 100644 --- a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java +++ b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java @@ -97,8 +97,7 @@ public class HostsSnifferTests extends LuceneTestCase { } catch(ElasticsearchResponseException e) { ElasticsearchResponse response = e.getElasticsearchResponse(); if (sniffResponse.isFailure) { - assertThat(e.getMessage(), containsString("GET http://localhost:" + httpServer.getAddress().getPort() + - "/_nodes/http?timeout=" + sniffRequestTimeout)); + assertThat(e.getMessage(), containsString("GET " + httpHost + "/_nodes/http?timeout=" + sniffRequestTimeout + "ms")); assertThat(e.getMessage(), containsString(Integer.toString(sniffResponse.nodesInfoResponseCode))); assertThat(response.getHost(), equalTo(httpHost)); assertThat(response.getStatusLine().getStatusCode(), equalTo(sniffResponse.nodesInfoResponseCode)); @@ -185,20 +184,22 @@ public class HostsSnifferTests extends LuceneTestCase { } generator.writeEndObject(); } - String[] roles = {"master", "data", "ingest"}; - int numRoles = RandomInts.randomIntBetween(random(), 0, 3); - Set nodeRoles = new HashSet<>(numRoles); - for (int j = 0; j < numRoles; j++) { - String role; - do { - role = RandomPicks.randomFrom(random(), roles); - } while(nodeRoles.add(role) == false); + if (random().nextBoolean()) { + String[] roles = {"master", "data", "ingest"}; + int numRoles = RandomInts.randomIntBetween(random(), 0, 3); + Set nodeRoles = new HashSet<>(numRoles); + for (int j = 0; j < numRoles; j++) { + String role; + do { + role = RandomPicks.randomFrom(random(), roles); + } while(nodeRoles.add(role) == false); + } + generator.writeArrayFieldStart("roles"); + for (String nodeRole : nodeRoles) { + generator.writeString(nodeRole); + } + generator.writeEndArray(); } - generator.writeArrayFieldStart("roles"); - for (String nodeRole : nodeRoles) { - generator.writeString(nodeRole); - } - generator.writeEndArray(); int numAttributes = RandomInts.randomIntBetween(random(), 0, 3); Map attributes = new HashMap<>(numAttributes); for (int j = 0; j < numAttributes; j++) {