Search in sources :

Example 16 with Response

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

the class RecoveryIT method testAutoExpandIndicesDuringRollingUpgrade.

public void testAutoExpandIndicesDuringRollingUpgrade() throws Exception {
    final String indexName = "test-auto-expand-filtering";
    final Version minimumNodeVersion = minimumNodeVersion();
    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());
    if (CLUSTER_TYPE == ClusterType.OLD) {
        createIndex(indexName, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomInt(2)).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all").build());
        ensureGreen(indexName);
        updateIndexSettings(indexName, Settings.builder().put(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + "._id", nodes.get(randomInt(2))));
    }
    final int numberOfReplicas = Integer.parseInt(getIndexSettingsAsMap(indexName).get(IndexMetadata.SETTING_NUMBER_OF_REPLICAS).toString());
    if (minimumNodeVersion.onOrAfter(LegacyESVersion.V_7_6_0)) {
        assertEquals(nodes.size() - 2, numberOfReplicas);
        ensureGreen(indexName);
    } else {
        assertEquals(nodes.size() - 1, numberOfReplicas);
    }
}
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) ArrayList(java.util.ArrayList)

Example 17 with Response

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

the class RecoveryIT method assertCount.

private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
    final int actualDocs;
    try {
        final Request request = new Request("GET", index + "/_count");
        if (preference != null) {
            request.addParameter("preference", preference);
        }
        final Response response = client().performRequest(request);
        actualDocs = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
    } catch (ResponseException e) {
        try {
            final Response recoveryStateResponse = client().performRequest(new Request("GET", index + "/_recovery"));
            fail("failed to get doc count for index [" + index + "] with preference [" + preference + "]" + " response [" + e + "]" + " recovery [" + EntityUtils.toString(recoveryStateResponse.getEntity()) + "]");
        } catch (Exception inner) {
            e.addSuppressed(inner);
        }
        throw e;
    }
    assertThat("preference [" + preference + "]", actualDocs, equalTo(expectedCount));
}
Also used : Response(org.opensearch.client.Response) ResponseException(org.opensearch.client.ResponseException) Request(org.opensearch.client.Request) IOException(java.io.IOException) ResponseException(org.opensearch.client.ResponseException)

Example 18 with Response

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

the class RecoveryIT method testRelocationWithConcurrentIndexing.

public void testRelocationWithConcurrentIndexing() throws Exception {
    final String index = "relocation_with_concurrent_indexing";
    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("index.routing.allocation.include._tier_preference", "").put(SETTING_ALLOCATION_MAX_RETRY.getKey(), // fail faster
            "0");
            createIndex(index, settings.build());
            indexDocs(index, 0, 10);
            ensureGreen(index);
            // make sure that no shards are allocated, so we can make sure the primary stays on the old node (when one
            // node stops, we lose the master too, so a replica will not be promoted)
            updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none"));
            break;
        case MIXED:
            final String newNode = getNodeId(v -> v.equals(Version.CURRENT));
            final String oldNode = getNodeId(v -> v.before(Version.CURRENT));
            // remove the replica and guaranteed the primary is placed on the old node
            updateIndexSettings(index, Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0).put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String) null).put("index.routing.allocation.include._id", oldNode).putNull("index.routing.allocation.include._tier_preference"));
            // wait for the primary to be assigned
            ensureGreen(index);
            // wait for all other shard activity to finish
            ensureNoInitializingShards();
            updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
            asyncIndexDocs(index, 10, 50).get();
            // ensure the relocation from old node to new node has occurred; otherwise ensureGreen can
            // return true even though shards haven't moved to the new node yet (allocation was throttled).
            assertBusy(() -> {
                Map<String, ?> state = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
                String xpath = "routing_table.indices." + index + ".shards.0.node";
                @SuppressWarnings("unchecked") List<String> assignedNodes = (List<String>) XContentMapValues.extractValue(xpath, state);
                assertNotNull(state.toString(), assignedNodes);
                assertThat(state.toString(), newNode, in(assignedNodes));
            }, 60, TimeUnit.SECONDS);
            ensureGreen(index);
            client().performRequest(new Request("POST", index + "/_refresh"));
            assertCount(index, "_only_nodes:" + newNode, 60);
            break;
        case UPGRADED:
            updateIndexSettings(index, Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2).put("index.routing.allocation.include._id", (String) null).putNull("index.routing.allocation.include._tier_preference"));
            asyncIndexDocs(index, 60, 45).get();
            ensureGreen(index);
            client().performRequest(new Request("POST", index + "/_refresh"));
            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());
            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);
    }
    if (randomBoolean()) {
        syncedFlush(index, randomBoolean());
        ensureGlobalCheckpointSynced(index);
    }
}
Also used : ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request) ArrayList(java.util.ArrayList) Response(org.opensearch.client.Response) ArrayList(java.util.ArrayList) List(java.util.List) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 19 with Response

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

the class CorsNotSetIT method testThatOmittingCorsHeaderDoesNotReturnAnything.

public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws IOException {
    Response response = getRestClient().performRequest(new Request("GET", "/"));
    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) Request(org.opensearch.client.Request)

Example 20 with Response

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

the class OpenSearchDashboardsSystemIndexIT method testAliases.

public void testAliases() throws IOException {
    assumeFalse("In this test, .opensearch_dashboards is the alias name", ".opensearch_dashboards".equals(indexName));
    Request request = new Request("PUT", "/_opensearch_dashboards/" + indexName);
    Response response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    request = new Request("PUT", "/_opensearch_dashboards/" + indexName + "/_alias/.opensearch_dashboards");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    request = new Request("GET", "/_opensearch_dashboards/_aliases");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(EntityUtils.toString(response.getEntity()), containsString(".opensearch_dashboards"));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

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