Search in sources :

Example 26 with RequestOptions

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

the class CatApi method perform.

private <R> R perform(Request request, TypeReference<R> responseClass, String errorMessage) {
    return client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return returnType(response, responseClass);
    }, errorMessage);
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)

Example 27 with RequestOptions

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

the class ClusterStateApi method fields.

public Map<String, Set<String>> fields(Collection<String> indices) {
    final Request request = request(indices);
    final JsonNode jsonResponse = client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve fields from indices: " + String.join(",", indices));
    // noinspection UnstableApiUsage
    return Streams.stream(jsonResponse.path("metadata").path("indices").fields()).flatMap(index -> allFieldsFromIndex(index.getKey(), index.getValue())).collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, Collectors.toSet())));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Set(java.util.Set) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) AbstractMap(java.util.AbstractMap) Stream(java.util.stream.Stream) Map(java.util.Map) Collectors.mapping(java.util.stream.Collectors.mapping) JsonNode(com.fasterxml.jackson.databind.JsonNode) Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 28 with RequestOptions

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

the class IndicesAdapterES7 method markIndexReopened.

@Override
public void markIndexReopened(String index) {
    final String aliasName = index + Indices.REOPENED_ALIAS_SUFFIX;
    final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    final IndicesAliasesRequest.AliasActions aliasAction = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD).index(index).alias(aliasName);
    indicesAliasesRequest.addAliasAction(aliasAction);
    client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "Couldn't create reopened alias for index " + index);
}
Also used : IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)

Example 29 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project hazelcast by hazelcast.

the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest.

@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest() throws Exception {
    when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
    // get different instance than default
    TestSupport testSupport = runProcessor(request -> {
        Builder builder = RequestOptions.DEFAULT.toBuilder();
        builder.addHeader("TestHeader", "value");
        return builder.build();
    });
    testSupport.expectOutput(emptyList());
    ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
    verify(mockClient).search(any(), captor.capture());
    RequestOptions capturedOptions = captor.getValue();
    assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
Also used : TotalHits(org.apache.lucene.search.TotalHits) RestClient(org.elasticsearch.client.RestClient) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) SearchHits(org.elasticsearch.search.SearchHits) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) SearchRequest(org.elasticsearch.action.search.SearchRequest) Node(org.elasticsearch.client.Node) Builder(org.elasticsearch.client.RequestOptions.Builder) Prirep(com.hazelcast.jet.elastic.impl.Shard.Prirep) BytesArray(org.elasticsearch.common.bytes.BytesArray) ArgumentCaptor(org.mockito.ArgumentCaptor) Text(org.elasticsearch.common.text.Text) SearchResponse(org.elasticsearch.action.search.SearchResponse) RequestOptions(org.elasticsearch.client.RequestOptions) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Before(org.junit.Before) SearchHit(org.elasticsearch.search.SearchHit) FunctionEx(com.hazelcast.function.FunctionEx) Collections.emptyMap(java.util.Collections.emptyMap) ActionRequest(org.elasticsearch.action.ActionRequest) SliceBuilder(org.elasticsearch.search.slice.SliceBuilder) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Category(org.junit.experimental.categories.Category) EQUAL_TO(org.apache.lucene.search.TotalHits.Relation.EQUAL_TO) Serializable(java.io.Serializable) Mockito.verify(org.mockito.Mockito.verify) TotalHits(org.apache.lucene.search.TotalHits) List(java.util.List) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) TestSupport(com.hazelcast.jet.core.test.TestSupport) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Mockito.mock(org.mockito.Mockito.mock) SearchHit(org.elasticsearch.search.SearchHit) RequestOptions(org.elasticsearch.client.RequestOptions) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Builder(org.elasticsearch.client.RequestOptions.Builder) SliceBuilder(org.elasticsearch.search.slice.SliceBuilder) TestSupport(com.hazelcast.jet.core.test.TestSupport) SearchHits(org.elasticsearch.search.SearchHits) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 30 with RequestOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions 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)

Aggregations

IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)8 CreateIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)8 Collectors (java.util.stream.Collectors)7 ClusterHealthRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)7 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)7 Inject (javax.inject.Inject)6 DeleteIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 UpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)6 DeleteIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)6 IndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest)6 PutIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ClusterUpdateSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)5 BulkRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest)5 ElasticsearchClient (org.graylog.storage.elasticsearch7.ElasticsearchClient)5