Search in sources :

Example 61 with Request

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);
}
Also used : ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 62 with Request

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();
    }
}
Also used : ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest) NodesStats(org.graylog2.system.stats.elasticsearch.NodesStats) LoggerFactory(org.slf4j.LoggerFactory) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) ClusterGetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse) ClusterHealthStatus(org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus) HealthStatus(org.graylog2.indexer.indices.HealthStatus) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ClusterStats(org.graylog2.system.stats.elasticsearch.ClusterStats) TimeValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue) Locale(java.util.Locale) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) ClusterHealth(org.graylog2.rest.models.system.indexer.responses.ClusterHealth) JsonNode(com.fasterxml.jackson.databind.JsonNode) Duration(com.github.joschi.jadconfig.util.Duration) Named(javax.inject.Named) JsonNodeType(com.fasterxml.jackson.databind.node.JsonNodeType) ClusterAllocationDiskSettingsFactory(org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettingsFactory) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) Logger(org.slf4j.Logger) CatApi(org.graylog.storage.elasticsearch7.cat.CatApi) Collection(java.util.Collection) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) PendingTasksStats(org.graylog2.indexer.cluster.PendingTasksStats) IndicesStats(org.graylog2.system.stats.elasticsearch.IndicesStats) Set(java.util.Set) ClusterAllocationDiskSettings(org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettings) NodeFileDescriptorStats(org.graylog2.indexer.cluster.health.NodeFileDescriptorStats) Ints(com.google.common.primitives.Ints) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) Collectors(java.util.stream.Collectors) ShardStats(org.graylog2.system.stats.elasticsearch.ShardStats) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Optional(java.util.Optional) ClusterAdapter(org.graylog2.indexer.cluster.ClusterAdapter) NodeResponse(org.graylog.storage.elasticsearch7.cat.NodeResponse) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Example 63 with Request

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;
}
Also used : Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)

Example 64 with 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);
}
Also used : Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 65 with Request

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);
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) GetIndexTemplatesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexTemplatesResponse) IndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest) WriteRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.WriteRequest) CloseIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CloseIndexRequest) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest) GetIndexTemplatesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexTemplatesRequest) RefreshRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) BulkIndexRequest(org.graylog.testing.elasticsearch.BulkIndexRequest) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) DeleteIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest) UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

Request (org.elasticsearch.client.Request)55 Response (org.elasticsearch.client.Response)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 IOException (java.io.IOException)12 HttpEntity (org.apache.http.HttpEntity)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 StringEntity (org.apache.http.entity.StringEntity)7 RestClient (org.elasticsearch.client.RestClient)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 ContentType (org.apache.http.entity.ContentType)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 UncheckedIOException (java.io.UncheckedIOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4