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);
}
}
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));
}
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);
}
}
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());
}
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"));
}
Aggregations