use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClient method master.
/**
* Returns current master of the ES cluster
*/
public Master master() {
try {
Request r = new Request("GET", "/_cat/master");
r.addParameter("format", "json");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
JsonObject object = array.get(0).asObject();
return new Master(object.get("host").asString(), object.get("id").asString(), object.get("ip").asString(), object.get("node").asString());
}
} catch (IOException e) {
throw new JetException("Could not get ES cluster master", e);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClientTest method response.
private Response response(String json) throws IOException {
Response response = mock(Response.class, RETURNS_DEEP_STUBS);
when(response.getEntity().getContent()).thenReturn(new FileInputStream("src/test/resources/mock_es_responses/" + json));
return response;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClientTest method shouldRetryOnShards.
@Test
public void shouldRetryOnShards() throws IOException {
ElasticCatClient catClient = new ElasticCatClient(restClient, 5);
Response nodesResponse = response("es2node_nodes.json");
Response shardsResponse = response("es2node_shards.json");
when(restClient.performRequest(any())).thenThrow(new IOException("Could not connect")).thenReturn(nodesResponse, shardsResponse);
List<Shard> shards = catClient.shards("my-index");
assertThat(shards).extracting(Shard::getHttpAddress).containsOnly("127.0.0.1:9200", "127.0.0.1:9201");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClientTest method shards.
@Test
public void shards() throws IOException {
ElasticCatClient catClient = new ElasticCatClient(restClient, 5);
Response nodesResponse = response("es2node_nodes.json");
Response shardsResponse = response("es2node_shards.json");
when(restClient.performRequest(any())).thenReturn(nodesResponse, shardsResponse);
List<Shard> shards = catClient.shards("my-index");
assertThat(shards).extracting(Shard::getHttpAddress).containsOnly("127.0.0.1:9200", "127.0.0.1:9201");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project sonarqube by SonarSource.
the class EsClient method clusterStats.
// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
public ClusterStatsResponse clusterStats() {
return execute(() -> {
Request request = new Request("GET", "/_cluster/stats");
Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
return ClusterStatsResponse.toClusterStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
});
}
Aggregations