use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method pendingTasks.
@Override
public PendingTasksStats pendingTasks() {
final Request request = new Request("GET", "/_cluster/pending_tasks");
final JsonNode response = jsonApi.perform(request, "Couldn't read Elasticsearch pending cluster tasks");
final JsonNode pendingClusterTasks = response.path("tasks");
final int pendingTasksSize = pendingClusterTasks.size();
final List<Long> pendingTasksTimeInQueue = Lists.newArrayListWithCapacity(pendingTasksSize);
for (JsonNode jsonElement : pendingClusterTasks) {
if (jsonElement.has("time_in_queue_millis")) {
pendingTasksTimeInQueue.add(jsonElement.get("time_in_queue_millis").asLong());
}
}
return PendingTasksStats.create(pendingTasksSize, pendingTasksTimeInQueue);
}
use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterHealth.
private Optional<ClusterHealthResponse> clusterHealth(Collection<String> indices) {
final String[] indicesAry = indices.toArray(new String[0]);
if (!indices.isEmpty() && !indicesExist(indicesAry)) {
return Optional.empty();
}
final ClusterHealthRequest request = new ClusterHealthRequest(indicesAry).timeout(TimeValue.timeValueSeconds(Ints.saturatedCast(requestTimeout.toSeconds()))).indicesOptions(IndicesOptions.lenientExpand());
try {
return Optional.of(client.execute((c, requestOptions) -> c.cluster().health(request, requestOptions)));
} catch (ElasticsearchException e) {
if (LOG.isDebugEnabled()) {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"), e);
} else {
LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"));
}
return Optional.empty();
}
}
use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class CatApi method request.
private Request request(@SuppressWarnings("SameParameterValue") String method, String endpoint) {
final Request request = new Request(method, "/_cat/" + endpoint);
request.addParameter("format", "json");
return request;
}
use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class CatApi method requestIndices.
private JsonNode requestIndices(String indexName, String errorMessage) {
final Request request = request("GET", "indices/" + indexName);
request.addParameter("h", "index,status");
request.addParameter("expand_wildcards", "all");
request.addParameter("s", "index,status");
return perform(request, new TypeReference<JsonNode>() {
}, errorMessage);
}
use of org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClientES7 method existingIndices.
private String[] existingIndices() {
final Request request = new Request("GET", "/_cat/indices");
request.addParameter("format", "json");
request.addParameter("h", "index");
final JsonNode jsonResponse = client.execute((c, requestOptions) -> {
request.setOptions(requestOptions);
final Response response = c.getLowLevelClient().performRequest(request);
return objectMapper.readTree(response.getEntity().getContent());
});
return Streams.stream(jsonResponse.elements()).map(index -> index.path("index").asText()).distinct().toArray(String[]::new);
}
Aggregations