use of 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.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.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClient method shards.
/**
* Returns list of shards for given indexes
*
* Only STARTED shards are returned.
*
* @param indices indexes to return shards for (wildcard format accepted)
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public List<Shard> shards(String... indices) {
Map<String, String> idToAddress = nodes().stream().collect(toMap(Node::getId, Node::getHttpAddress));
try {
Request r = new Request("GET", "/_cat/shards/" + String.join(",", indices));
r.addParameter("format", "json");
r.addParameter("h", "id,index,shard,prirep,docs,state,ip,node");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Shard> shards = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Shard> shard = convertToShard(value, idToAddress);
shard.ifPresent(shards::add);
}
LOG.log(FINE, "Shards " + shards);
return shards;
}
} catch (IOException e) {
throw new JetException("Could not get ES shards", e);
}
}
use of 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.elasticsearch.client.Response in project yyl_example by Relucent.
the class ElasticsearchTest method catApi.
// 查看API信息
private static void catApi(RestClient client) throws Exception {
Request request = new Request("GET", "_cat");
Response response = client.performRequest(request);
System.out.println(EntityUtils.toString(response.getEntity()));
}
Aggregations