final Iterable<String> hostList = Splitter.on(',').omitEmptyStrings().trimResults().split(hosts);
// if no elasticsearch running
for (String host : hostList) {
// guess that Elasticsearch http is listening on port 9200
final HostAndPort hostAndPort = HostAndPort.fromString(host);
LOG.info("Checking Elasticsearch HTTP API at http://{}:9200/", hostAndPort.getHostText());
try {
// Try the HTTP API endpoint
final ListenableFuture<Response> future = httpClient.prepareGet("http://" + hostAndPort.getHostText() + ":9200/_nodes").execute();
final Response response = future.get();
final JsonNode resultTree = new ObjectMapper().readTree(response.getResponseBody());
final String clusterName = resultTree.get("cluster_name").textValue();
final JsonNode nodesList = resultTree.get("nodes");
final Iterator<String> nodes = nodesList.fieldNames();
while (nodes.hasNext()) {
final String id = nodes.next();
final Version clusterVersion = Version.fromString(nodesList.get(id).get("version").textValue());
if (!configuration.isEsDisableVersionCheck()) {
checkClusterVersion(clusterVersion);
}
}
checkClusterName(clusterName);
} catch (IOException ioException) {
LOG.error("Could not connect to Elasticsearch.", ioException);
} catch (InterruptedException ignore) {
} catch (ExecutionException e1) {
// could not find any server on that address
LOG.error("Could not connect to Elasticsearch at http://" + hostAndPort.getHostText() + ":9200/, is it running?",
e1.getCause());
}
}
}