Search in sources :

Example 56 with Response

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

the class StatsApi method stats.

private JsonNode stats(Collection<String> indices, Collection<String> metrics, Consumer<Request> prepareRequest) {
    final StringBuilder endpoint = new StringBuilder();
    if (!indices.isEmpty()) {
        final String joinedIndices = String.join(",", indices);
        endpoint.append("/");
        endpoint.append(joinedIndices);
    }
    endpoint.append("/_stats");
    if (!metrics.isEmpty()) {
        final String joinedMetrics = String.join(",", metrics);
        endpoint.append("/");
        endpoint.append(joinedMetrics);
    }
    final Request request = new Request("GET", endpoint.toString());
    prepareRequest.accept(request);
    return client.execute((c, requestOptions) -> {
        request.setOptions(requestOptions);
        final Response response = c.getLowLevelClient().performRequest(request);
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve index stats for " + String.join(",", indices));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)

Example 57 with Response

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response 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 58 with Response

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response 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 59 with Response

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

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorSingleHeader.

@Test
public void testInterceptorSingleHeader() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(1);
    assertThat(response.getAllHeaders()[0].getName()).as("Remaining Header should be same as the given.").isEqualTo("Test");
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 60 with Response

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

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers.

@Test
public void testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    response.addHeader("Warning", "This warning should not trigger the interceptor.");
    response.addHeader("Warning", "This text contains the trigger: but in a future major version, direct access to system indices and their aliases will not be allowed - and should be filtered out");
    response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
    assertThat(response.getAllHeaders()).as("Number of Headers should be 4 before start.").hasSize(4);
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be 2 less after running the interceptor.").hasSize(2);
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

Response (org.elasticsearch.client.Response)111 Request (org.elasticsearch.client.Request)38 IOException (java.io.IOException)33 HttpEntity (org.apache.http.HttpEntity)24 NStringEntity (org.apache.http.nio.entity.NStringEntity)21 Test (org.junit.Test)20 HashMap (java.util.HashMap)17 Map (java.util.Map)14 BasicHeader (org.apache.http.message.BasicHeader)14 ResponseException (org.elasticsearch.client.ResponseException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 RestClient (org.elasticsearch.client.RestClient)11 ArrayList (java.util.ArrayList)10 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)10 StringEntity (org.apache.http.entity.StringEntity)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 InputStream (java.io.InputStream)8 JSONObject (org.json.simple.JSONObject)8 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7