Search in sources :

Example 11 with ObjectPath

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

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

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