Search in sources :

Example 6 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class ESClientYamlSuiteTestCase method readVersionsFromInfo.

private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
    Version version = null;
    for (int i = 0; i < numHosts; i++) {
        //we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
        Response response = restClient.performRequest("GET", "/");
        ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
        Object latestVersion = restTestResponse.evaluate("version.number");
        if (latestVersion == null) {
            throw new RuntimeException("elasticsearch version not found in the response");
        }
        final Version currentVersion = Version.fromString(latestVersion.toString());
        if (version == null) {
            version = currentVersion;
        } else if (version.onOrAfter(currentVersion)) {
            version = currentVersion;
        }
    }
    return version;
}
Also used : Response(org.elasticsearch.client.Response) Version(org.elasticsearch.Version)

Example 7 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class WaitForRefreshAndCloseTests method start.

private ActionFuture<String> start(String method, String path, HttpEntity body) {
    PlainActionFuture<String> future = new PlainActionFuture<>();
    Map<String, String> params = new HashMap<>();
    params.put("refresh", "wait_for");
    params.put("error_trace", "");
    client().performRequestAsync(method, docPath() + path, params, body, new ResponseListener() {

        @Override
        public void onSuccess(Response response) {
            try {
                future.onResponse(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
            } catch (IOException e) {
                future.onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception exception) {
            future.onFailure(exception);
        }
    });
    return future;
}
Also used : Response(org.elasticsearch.client.Response) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) HashMap(java.util.HashMap) ResponseListener(org.elasticsearch.client.ResponseListener) IOException(java.io.IOException) ResponseException(org.elasticsearch.client.ResponseException) IOException(java.io.IOException)

Example 8 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class Netty4HeadBodyIsEmptyIT method headTestCase.

private void headTestCase(final String url, final Map<String, String> params, final int expectedStatusCode, final Matcher<Integer> matcher) throws IOException {
    Response response = client().performRequest("HEAD", url, params);
    assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
    assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher);
    assertNull("HEAD requests shouldn't have a response body but " + url + " did", response.getEntity());
}
Also used : Response(org.elasticsearch.client.Response)

Example 9 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class IndexingIT method assertCount.

private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
    final Response response = client().performRequest("GET", index + "/_count", Collections.singletonMap("preference", preference));
    assertOK(response);
    final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
    assertThat(actualCount, equalTo(expectedCount));
}
Also used : Response(org.elasticsearch.client.Response)

Example 10 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class IndexingIT method buildNodeAndVersions.

private Nodes buildNodeAndVersions() throws IOException {
    Response response = client().performRequest("GET", "_nodes");
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
    Nodes nodes = new Nodes();
    for (String id : nodesAsMap.keySet()) {
        nodes.add(new Node(id, objectPath.evaluate("nodes." + id + ".name"), Version.fromString(objectPath.evaluate("nodes." + id + ".version")), HttpHost.create(objectPath.evaluate("nodes." + id + ".http.publish_address"))));
    }
    response = client().performRequest("GET", "_cluster/state");
    nodes.setMasterNodeId(ObjectPath.createFromResponse(response).evaluate("master_node"));
    return nodes;
}
Also used : Response(org.elasticsearch.client.Response) ObjectPath(org.elasticsearch.test.rest.yaml.ObjectPath)

Aggregations

Response (org.elasticsearch.client.Response)75 IOException (java.io.IOException)24 Request (org.elasticsearch.client.Request)19 BasicHeader (org.apache.http.message.BasicHeader)14 NStringEntity (org.apache.http.nio.entity.NStringEntity)14 HttpEntity (org.apache.http.HttpEntity)13 ResponseException (org.elasticsearch.client.ResponseException)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HashMap (java.util.HashMap)9 RestClient (org.elasticsearch.client.RestClient)8 Map (java.util.Map)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ArrayList (java.util.ArrayList)6 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)6 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)6 JSONParser (org.json.simple.parser.JSONParser)6 ParseException (org.json.simple.parser.ParseException)6 InputStream (java.io.InputStream)5 StringEntity (org.apache.http.entity.StringEntity)5