Search in sources :

Example 76 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method clusterHealthRequest.

@Override
public void clusterHealthRequest(String timeout) throws IOException {
    Request clusterHealthRequest = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + "_cluster" + REQUEST_SEPARATOR + "health");
    clusterHealthRequest.addParameter("wait_for_status", "yellow");
    clusterHealthRequest.addParameter("timeout", timeout);
    final Response response = delegate.performRequest(clusterHealthRequest);
    try (final InputStream inputStream = response.getEntity().getContent()) {
        final Map<String, Object> values = mapReader.readValue(inputStream);
        if (!values.containsKey("timed_out")) {
            throw new IOException("Unexpected response for Elasticsearch cluster health request");
        } else if (!Objects.equals(values.get("timed_out"), false)) {
            throw new IOException("Elasticsearch timeout waiting for yellow status");
        }
    }
}
Also used : RestBulkItemResponse(org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse) Response(org.elasticsearch.client.Response) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request) IOException(java.io.IOException)

Example 77 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project janusgraph by JanusGraph.

the class RestElasticSearchClient method createMapping.

@Override
public void createMapping(String indexName, String typeName, Map<String, Object> mapping) throws IOException {
    Request request;
    if (useMappingTypes) {
        request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping" + REQUEST_SEPARATOR + typeName);
        if (esVersion7) {
            request.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
        }
    } else {
        request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping");
    }
    performRequest(request, mapWriter.writeValueAsBytes(mapping));
}
Also used : Request(org.elasticsearch.client.Request)

Example 78 with Request

use of org.graylog.shaded.elasticsearch7.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 79 with Request

use of org.graylog.shaded.elasticsearch7.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 80 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ClusterAdapterES7 method clusterAllocationDiskSettings.

@Override
public ClusterAllocationDiskSettings clusterAllocationDiskSettings() {
    final ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
    request.includeDefaults(true);
    final ClusterGetSettingsResponse response = client.execute((c, requestOptions) -> c.cluster().getSettings(request, requestOptions));
    return ClusterAllocationDiskSettingsFactory.create(Boolean.parseBoolean(response.getSetting("cluster.routing.allocation.disk.threshold_enabled")), response.getSetting("cluster.routing.allocation.disk.watermark.low"), response.getSetting("cluster.routing.allocation.disk.watermark.high"), response.getSetting("cluster.routing.allocation.disk.watermark.flood_stage"));
}
Also used : ClusterGetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse) ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest)

Aggregations

Request (org.elasticsearch.client.Request)54 Response (org.elasticsearch.client.Response)34 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 IOException (java.io.IOException)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 HttpEntity (org.apache.http.HttpEntity)11 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 StringEntity (org.apache.http.entity.StringEntity)6 RestClient (org.elasticsearch.client.RestClient)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5