Search in sources :

Example 51 with Response

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project spring-boot by spring-projects.

the class ElasticsearchRestHealthIndicatorTests method elasticsearchIsDownByResponseCode.

@Test
void elasticsearchIsDownByResponseCode() throws IOException {
    Response response = mock(Response.class);
    StatusLine statusLine = mock(StatusLine.class);
    given(statusLine.getStatusCode()).willReturn(500);
    given(statusLine.getReasonPhrase()).willReturn("Internal server error");
    given(response.getStatusLine()).willReturn(statusLine);
    given(this.restClient.performRequest(any(Request.class))).willReturn(response);
    Health health = this.elasticsearchRestHealthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails()).contains(entry("statusCode", 500), entry("reasonPhrase", "Internal server error"));
}
Also used : Response(org.elasticsearch.client.Response) StatusLine(org.apache.http.StatusLine) Health(org.springframework.boot.actuate.health.Health) Request(org.elasticsearch.client.Request) Test(org.junit.jupiter.api.Test)

Example 52 with Response

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

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method setUp.

@Before
public void setUp() throws Exception {
    final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    when(indexLookup.indexNamesForStreamsInTimeRange(eq(ImmutableSet.of(stream1Id)), any())).thenReturn(ImmutableSet.of("index1", "index2"));
    when(indexLookup.indexNamesForStreamsInTimeRange(eq(ImmutableSet.of(stream2Id)), any())).thenReturn(ImmutableSet.of("index3"));
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) Before(org.junit.Before)

Example 53 with Response

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

the class ElasticsearchBackendMultiSearchTest method everySearchTypeGeneratesOneESQuery.

@Test
public void everySearchTypeGeneratesOneESQuery() throws Exception {
    final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    final List<SearchRequest> generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    assertThat(generatedRequest).hasSize(2);
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 54 with Response

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

the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.

@Test
public void multiSearchResultsAreAssignedToSearchTypes() throws Exception {
    final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
    assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot1", "pivot2");
    final PivotResult pivot1Result = (PivotResult) queryResult.searchTypes().get("pivot1");
    assertThat(pivot1Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("avg(field1)"), 27220.273504273504, true, "row-leaf")).build());
    final PivotResult pivot2Result = (PivotResult) queryResult.searchTypes().get("pivot2");
    assertThat(pivot2Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("max(field2)"), 42.0, true, "row-leaf")).build());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 55 with Response

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

the class FieldMappingApi method fieldTypes.

public Map<String, FieldMapping> fieldTypes(String index) {
    final JsonNode result = client.execute((c, requestOptions) -> {
        final Response response = c.getLowLevelClient().performRequest(request(index));
        return objectMapper.readTree(response.getEntity().getContent());
    }, "Unable to retrieve field types of index " + index);
    final JsonNode fields = result.path(index).path("mappings").path("properties");
    // noinspection UnstableApiUsage
    return Streams.stream(fields.fields()).collect(Collectors.toMap(Map.Entry::getKey, entry -> FieldMapping.create(entry.getValue().path("type").asText(), entry.getValue().path("fielddata").asBoolean())));
}
Also used : Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Inject(javax.inject.Inject) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AutoValue(com.google.auto.value.AutoValue) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) Streams(com.google.common.collect.Streams) Response(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response) Collectors(java.util.stream.Collectors) Nullable(javax.annotation.Nullable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map)

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