Search in sources :

Example 6 with Ping

use of io.searchbox.core.Ping in project graylog2-server by Graylog2.

the class NodeAdapterES6 method version.

@Override
public Optional<SearchVersion> version() {
    final Ping request = new Ping.Builder().build();
    final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Unable to retrieve Elasticsearch version");
    return Optional.ofNullable(jestResult.getJsonObject().path("version").path("number").asText(null)).map(this::parseVersion).map(SearchVersion::elasticsearch);
}
Also used : Ping(io.searchbox.core.Ping) SearchVersion(org.graylog2.storage.SearchVersion) JestResult(io.searchbox.client.JestResult)

Example 7 with Ping

use of io.searchbox.core.Ping in project graylog2-server by Graylog2.

the class JestUtilsTest method executeWithQueryParsingException.

@Test
public void executeWithQueryParsingException() throws Exception {
    final Ping request = new Ping.Builder().build();
    final JestResult resultMock = mock(JestResult.class);
    when(resultMock.isSucceeded()).thenReturn(false);
    final ObjectNode rootCauseStub = objectMapper.createObjectNode();
    rootCauseStub.set("type", new TextNode("query_parsing_exception"));
    rootCauseStub.set("reason", new TextNode("foobar"));
    rootCauseStub.set("line", new IntNode(23));
    rootCauseStub.set("col", new IntNode(42));
    rootCauseStub.set("index", new TextNode("my_index"));
    final ArrayNode rootCausesStub = objectMapper.createArrayNode();
    rootCausesStub.add(rootCauseStub);
    final ObjectNode errorStub = objectMapper.createObjectNode();
    errorStub.set("root_cause", rootCausesStub);
    final ObjectNode responseStub = objectMapper.createObjectNode();
    responseStub.set("error", errorStub);
    when(resultMock.getJsonObject()).thenReturn(responseStub);
    when(clientMock.execute(request)).thenReturn(resultMock);
    try {
        JestUtils.execute(clientMock, request, () -> "BOOM");
        fail("Expected QueryParsingException to be thrown");
    } catch (QueryParsingException e) {
        assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("foobar").hasNoSuppressedExceptions();
        assertThat(e.getErrorDetails()).containsExactly("foobar");
        assertThat(e.getLine()).contains(23);
        assertThat(e.getColumn()).contains(42);
        assertThat(e.getIndex()).contains("my_index");
    }
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Ping(io.searchbox.core.Ping) QueryParsingException(org.graylog2.indexer.QueryParsingException) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JestResult(io.searchbox.client.JestResult) Test(org.junit.Test)

Aggregations

Ping (io.searchbox.core.Ping)7 JestResult (io.searchbox.client.JestResult)6 Test (org.junit.Test)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ElasticsearchException (org.graylog2.indexer.ElasticsearchException)2 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 QueryParsingException (org.graylog2.indexer.QueryParsingException)1 SearchVersion (org.graylog2.storage.SearchVersion)1