Search in sources :

Example 96 with Response

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

the class ElasticCatClient method master.

/**
 * Returns current master of the ES cluster
 */
public Master master() {
    try {
        Request r = new Request("GET", "/_cat/master");
        r.addParameter("format", "json");
        Response res = withRetry(() -> client.performRequest(r), retries);
        try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
            JsonArray array = Json.parse(reader).asArray();
            JsonObject object = array.get(0).asObject();
            return new Master(object.get("host").asString(), object.get("id").asString(), object.get("ip").asString(), object.get("node").asString());
        }
    } catch (IOException e) {
        throw new JetException("Could not get ES cluster master", e);
    }
}
Also used : Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) JsonObject(com.hazelcast.internal.json.JsonObject) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Example 97 with Response

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

the class ElasticCatClientTest method response.

private Response response(String json) throws IOException {
    Response response = mock(Response.class, RETURNS_DEEP_STUBS);
    when(response.getEntity().getContent()).thenReturn(new FileInputStream("src/test/resources/mock_es_responses/" + json));
    return response;
}
Also used : Response(org.elasticsearch.client.Response) FileInputStream(java.io.FileInputStream)

Example 98 with Response

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

the class ElasticCatClientTest method shouldRetryOnShards.

@Test
public void shouldRetryOnShards() throws IOException {
    ElasticCatClient catClient = new ElasticCatClient(restClient, 5);
    Response nodesResponse = response("es2node_nodes.json");
    Response shardsResponse = response("es2node_shards.json");
    when(restClient.performRequest(any())).thenThrow(new IOException("Could not connect")).thenReturn(nodesResponse, shardsResponse);
    List<Shard> shards = catClient.shards("my-index");
    assertThat(shards).extracting(Shard::getHttpAddress).containsOnly("127.0.0.1:9200", "127.0.0.1:9201");
}
Also used : Response(org.elasticsearch.client.Response) IOException(java.io.IOException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 99 with Response

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

the class ElasticCatClientTest method shards.

@Test
public void shards() throws IOException {
    ElasticCatClient catClient = new ElasticCatClient(restClient, 5);
    Response nodesResponse = response("es2node_nodes.json");
    Response shardsResponse = response("es2node_shards.json");
    when(restClient.performRequest(any())).thenReturn(nodesResponse, shardsResponse);
    List<Shard> shards = catClient.shards("my-index");
    assertThat(shards).extracting(Shard::getHttpAddress).containsOnly("127.0.0.1:9200", "127.0.0.1:9201");
}
Also used : Response(org.elasticsearch.client.Response) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 100 with Response

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project sonarqube by SonarSource.

the class EsClient method clusterStats.

// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
public ClusterStatsResponse clusterStats() {
    return execute(() -> {
        Request request = new Request("GET", "/_cluster/stats");
        Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
        return ClusterStatsResponse.toClusterStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
    });
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ClearIndicesCacheResponse(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Response(org.elasticsearch.client.Response) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) ClusterStatsResponse(org.sonar.server.es.response.ClusterStatsResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndicesStatsResponse(org.sonar.server.es.response.IndicesStatsResponse) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClearIndicesCacheRequest(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Request(org.elasticsearch.client.Request) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonObject(com.google.gson.JsonObject)

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