Search in sources :

Example 1 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class RecoveryIT method testHistoryUUIDIsGenerated.

public void testHistoryUUIDIsGenerated() throws Exception {
    final String index = "index_history_uuid";
    if (CLUSTER_TYPE == ClusterType.OLD) {
        Settings.Builder settings = Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1).put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms");
        createIndex(index, settings.build());
    } else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
        ensureGreen(index);
        Request shardStatsRequest = new Request("GET", index + "/_stats");
        shardStatsRequest.addParameter("level", "shards");
        Response response = client().performRequest(shardStatsRequest);
        ObjectPath objectPath = ObjectPath.createFromResponse(response);
        List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0");
        assertThat(shardStats, hasSize(2));
        String expectHistoryUUID = null;
        for (int shard = 0; shard < 2; shard++) {
            String nodeID = objectPath.evaluate("indices." + index + ".shards.0." + shard + ".routing.node");
            String historyUUID = objectPath.evaluate("indices." + index + ".shards.0." + shard + ".commit.user_data.history_uuid");
            assertThat("no history uuid found for shard on " + nodeID, historyUUID, notNullValue());
            if (expectHistoryUUID == null) {
                expectHistoryUUID = historyUUID;
            } else {
                assertThat("different history uuid found for shard on " + nodeID, historyUUID, equalTo(expectHistoryUUID));
            }
        }
    }
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request) ArrayList(java.util.ArrayList) List(java.util.List) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 2 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath 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 3 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath 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 4 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class Netty4BadRequestIT method testBadRequest.

public void testBadRequest() throws IOException {
    final Response response = client().performRequest(new Request("GET", "/_nodes/settings"));
    final ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final Map<String, Object> map = objectPath.evaluate("nodes");
    int maxMaxInitialLineLength = Integer.MIN_VALUE;
    final Setting<ByteSizeValue> httpMaxInitialLineLength = HttpTransportSettings.SETTING_HTTP_MAX_INITIAL_LINE_LENGTH;
    final String key = httpMaxInitialLineLength.getKey().substring("http.".length());
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        @SuppressWarnings("unchecked") final Map<String, Object> settings = (Map<String, Object>) ((Map<String, Object>) entry.getValue()).get("settings");
        final int maxIntialLineLength;
        if (settings.containsKey("http")) {
            @SuppressWarnings("unchecked") final Map<String, Object> httpSettings = (Map<String, Object>) settings.get("http");
            if (httpSettings.containsKey(key)) {
                maxIntialLineLength = ByteSizeValue.parseBytesSizeValue((String) httpSettings.get(key), key).bytesAsInt();
            } else {
                maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
            }
        } else {
            maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
        }
        maxMaxInitialLineLength = Math.max(maxMaxInitialLineLength, maxIntialLineLength);
    }
    final String path = "/" + new String(new byte[maxMaxInitialLineLength], Charset.forName("UTF-8")).replace('\0', 'a');
    final ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(new Request(randomFrom("GET", "POST", "PUT"), path)));
    assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(BAD_REQUEST.getStatus()));
    assertThat(e, hasToString(containsString("too_long_frame_exception")));
    assertThat(e, hasToString(matches("An HTTP line is larger than \\d+ bytes")));
}
Also used : ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) ResponseException(org.opensearch.client.ResponseException) Request(org.opensearch.client.Request) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Response(org.opensearch.client.Response) Map(java.util.Map)

Example 5 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class Netty4BadRequestIT method testInvalidParameterValue.

public void testInvalidParameterValue() throws IOException {
    final Request request = new Request("GET", "/_cluster/settings");
    request.addParameter("pretty", "neither-true-nor-false");
    final ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(request));
    final Response response = e.getResponse();
    assertThat(response.getStatusLine().getStatusCode(), equalTo(400));
    final ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final Map<String, Object> map = objectPath.evaluate("error");
    assertThat(map.get("type"), equalTo("illegal_argument_exception"));
    assertThat(map.get("reason"), equalTo("Failed to parse value [neither-true-nor-false] as only [true] or [false] are allowed."));
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) ResponseException(org.opensearch.client.ResponseException) Request(org.opensearch.client.Request) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 Request (org.opensearch.client.Request)11 Response (org.opensearch.client.Response)10 ArrayList (java.util.ArrayList)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.hasToString (org.hamcrest.Matchers.hasToString)3 Version (org.opensearch.Version)3 ResponseException (org.opensearch.client.ResponseException)3 Settings (org.opensearch.common.settings.Settings)3 IndexSettings (org.opensearch.index.IndexSettings)3 List (java.util.List)2 LegacyESVersion (org.opensearch.LegacyESVersion)2 Map (java.util.Map)1 RequestOptions (org.opensearch.client.RequestOptions)1 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)1