use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request 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.Request 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));
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project sonarqube by SonarSource.
the class EsClient method indicesStats.
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
public IndicesStatsResponse indicesStats(String... indices) {
return execute(() -> {
Request request = new Request("GET", "/" + (indices.length > 0 ? (String.join(",", indices) + "/") : "") + "_stats");
request.addParameter("level", "shards");
Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
return IndicesStatsResponse.toIndicesStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
}, () -> computeDetailsAsString(indices));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.
the class ElasticsearchIOTestCommon method testMaxParallelRequestsPerWindow.
void testMaxParallelRequestsPerWindow() throws Exception {
List<Document> data = ElasticsearchIOTestUtils.createDocuments(numDocs, ElasticsearchIOTestUtils.InjectionMode.DO_NOT_INJECT_INVALID_DOCS).stream().map(doc -> Document.create().withInputDoc(doc).withTimestamp(Instant.now())).collect(Collectors.toList());
Write write = ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration).withMaxParallelRequestsPerWindow(1);
PCollection<KV<Integer, Iterable<Document>>> batches = pipeline.apply(Create.of(data)).apply(StatefulBatching.fromSpec(write.getBulkIO()));
PCollection<Integer> keyValues = batches.apply(MapElements.into(integers()).via((SerializableFunction<KV<Integer, Iterable<Document>>, Integer>) KV::getKey));
// Number of unique keys produced should be number of maxParallelRequestsPerWindow * numWindows
// There is only 1 request (key) per window, and 1 (global) window ie. one key total where
// key value is 0
PAssert.that(keyValues).containsInAnyOrder(0);
PAssert.that(batches).satisfies(new AssertThatHasExpectedContents(0, data));
pipeline.run();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project beam by apache.
the class ElasticsearchIOTestCommon method testDefaultRetryPredicate.
/**
* Test that the default predicate correctly parses chosen error code.
*/
void testDefaultRetryPredicate(RestClient restClient) throws IOException {
HttpEntity entity1 = new NStringEntity(BAD_REQUEST, ContentType.APPLICATION_JSON);
Request request = new Request("POST", "/_bulk");
request.addParameters(Collections.emptyMap());
request.setEntity(entity1);
Response response1 = restClient.performRequest(request);
assertTrue(CUSTOM_RETRY_PREDICATE.test(response1.getEntity()));
HttpEntity entity2 = new NStringEntity(OK_REQUEST, ContentType.APPLICATION_JSON);
request.setEntity(entity2);
Response response2 = restClient.performRequest(request);
assertFalse(DEFAULT_RETRY_PREDICATE.test(response2.getEntity()));
}
Aggregations