remove TODO around using /_cat/nodes rather than /_nodes, test compatibility with 2.x
_cat/nodes returns the http address only in 5.x. Would be nice to use as we could drop the jackson dependency, but we care more about being compatible with 2.x. Not compatible with previous versions as the format of returned http addresses have changed since 2.0. Also fixed test bug that caused sporadic failures.
This commit is contained in:
parent
2cf04c0877
commit
791db1fb48
|
@ -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);
|
||||
|
|
|
@ -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<String> 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<String> 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<String, String> attributes = new HashMap<>(numAttributes);
|
||||
for (int j = 0; j < numAttributes; j++) {
|
||||
|
|
Loading…
Reference in New Issue