Search in sources :

Example 91 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class RecoveryIT method getNodeId.

private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
    Response response = client().performRequest(new Request("GET", "_nodes"));
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
    for (String id : nodesAsMap.keySet()) {
        Version version = Version.fromString(objectPath.evaluate("nodes." + id + ".version"));
        if (versionPredicate.test(version)) {
            return id;
        }
    }
    return null;
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Request(org.opensearch.client.Request)

Example 92 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class RecoveryIT method testRecoveryWithConcurrentIndexing.

public void testRecoveryWithConcurrentIndexing() throws Exception {
    final String index = "recovery_with_concurrent_indexing";
    Response response = client().performRequest(new Request("GET", "_nodes"));
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
    List<String> nodes = new ArrayList<>(nodeMap.keySet());
    switch(CLUSTER_TYPE) {
        case OLD:
            Settings.Builder settings = Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2).put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms").put(SETTING_ALLOCATION_MAX_RETRY.getKey(), // fail faster
            "0");
            createIndex(index, settings.build());
            indexDocs(index, 0, 10);
            ensureGreen(index);
            // make sure that we can index while the replicas are recovering
            updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "primaries"));
            break;
        case MIXED:
            updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String) null));
            asyncIndexDocs(index, 10, 50).get();
            ensureGreen(index);
            client().performRequest(new Request("POST", index + "/_refresh"));
            assertCount(index, "_only_nodes:" + nodes.get(0), 60);
            assertCount(index, "_only_nodes:" + nodes.get(1), 60);
            assertCount(index, "_only_nodes:" + nodes.get(2), 60);
            // make sure that we can index while the replicas are recovering
            updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "primaries"));
            break;
        case UPGRADED:
            updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String) null));
            asyncIndexDocs(index, 60, 45).get();
            ensureGreen(index);
            client().performRequest(new Request("POST", index + "/_refresh"));
            assertCount(index, "_only_nodes:" + nodes.get(0), 105);
            assertCount(index, "_only_nodes:" + nodes.get(1), 105);
            assertCount(index, "_only_nodes:" + nodes.get(2), 105);
            break;
        default:
            throw new IllegalStateException("unknown type " + CLUSTER_TYPE);
    }
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request) ArrayList(java.util.ArrayList) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 93 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class CorsNotSetIT method testCorsSettingDefaultBehaviourDoesNotReturnAnything.

public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws IOException {
    String corsValue = "http://localhost:9200";
    Request request = new Request("GET", "/");
    RequestOptions.Builder options = request.getOptions().toBuilder();
    options.addHeader("User-Agent", "Mozilla Bar");
    options.addHeader("Origin", corsValue);
    request.setOptions(options);
    Response response = getRestClient().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
    assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
Also used : Response(org.opensearch.client.Response) RequestOptions(org.opensearch.client.RequestOptions) Request(org.opensearch.client.Request)

Example 94 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class JodaCompatibilityIT method performOnAllNodes.

private void performOnAllNodes(Request search, Consumer<Response> consumer) throws IOException {
    List<Node> nodes = client().getNodes();
    for (Node node : nodes) {
        client().setNodes(Collections.singletonList(node));
        Response response = client().performRequest(search);
        consumer.accept(response);
        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    }
    client().setNodes(nodes);
}
Also used : Response(org.opensearch.client.Response) Node(org.opensearch.client.Node)

Example 95 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class SearchRestCancellationIT method verifyCancellationDuringFetchPhase.

void verifyCancellationDuringFetchPhase(String searchAction, Request searchRequest) throws Exception {
    Map<String, String> nodeIdToName = readNodesInfo();
    List<ScriptedBlockPlugin> plugins = initBlockFactory();
    indexTestData();
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Exception> error = new AtomicReference<>();
    Cancellable cancellable = getRestClient().performRequestAsync(searchRequest, new ResponseListener() {

        @Override
        public void onSuccess(Response response) {
            latch.countDown();
        }

        @Override
        public void onFailure(Exception exception) {
            error.set(exception);
            latch.countDown();
        }
    });
    awaitForBlock(plugins);
    cancellable.cancel();
    ensureSearchTaskIsCancelled(searchAction, nodeIdToName::get);
    disableBlocks(plugins);
    latch.await();
    assertThat(error.get(), instanceOf(CancellationException.class));
}
Also used : Cancellable(org.opensearch.client.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResponseListener(org.opensearch.client.ResponseListener) CountDownLatch(java.util.concurrent.CountDownLatch) CancellationException(java.util.concurrent.CancellationException) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) Response(org.opensearch.client.Response) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) CancellationException(java.util.concurrent.CancellationException)

Aggregations

Response (org.opensearch.client.Response)134 Request (org.opensearch.client.Request)113 ResponseException (org.opensearch.client.ResponseException)24 Map (java.util.Map)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 ArrayList (java.util.ArrayList)17 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)16 RestClient (org.opensearch.client.RestClient)15 HashMap (java.util.HashMap)14 RequestOptions (org.opensearch.client.RequestOptions)12 ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 IndexRequest (org.opensearch.action.index.IndexRequest)11 IOException (java.io.IOException)10 List (java.util.List)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 Version (org.opensearch.Version)8 WriteRequest (org.opensearch.action.support.WriteRequest)8 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)7 IndexResponse (org.opensearch.action.index.IndexResponse)7 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)7