use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class Zen2RestApiIT method testRollingRestartOfTwoNodeCluster.
public void testRollingRestartOfTwoNodeCluster() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(1);
final List<String> nodes = internalCluster().startNodes(2);
createIndex("test", Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), // assign shards
TimeValue.ZERO).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, // causes rebalancing
2).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build());
ensureGreen("test");
RestClient restClient = getRestClient();
internalCluster().rollingRestart(new InternalTestCluster.RestartCallback() {
@Override
public void doAfterNodes(int n, Client client) throws IOException {
ensureGreen("test");
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + internalCluster().getNodeNames()[n]));
assertThat(response.getStatusLine().getStatusCode(), is(200));
}
@Override
public Settings onNodeStopped(String nodeName) throws IOException {
String viaNode = randomValueOtherThan(nodeName, () -> randomFrom(nodes));
List<Node> allNodes = restClient.getNodes();
try {
restClient.setNodes(Collections.singletonList(new Node(HttpHost.create(internalCluster().getInstance(HttpServerTransport.class, viaNode).boundAddress().publishAddress().toString()))));
Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/voting_config_exclusions"));
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(Integer.toString(1)).setTimeout(TimeValue.timeValueSeconds(30L)).setWaitForYellowStatus().get();
assertFalse(nodeName, clusterHealthResponse.isTimedOut());
return Settings.EMPTY;
} finally {
restClient.setNodes(allNodes);
}
}
});
ensureStableCluster(2);
ensureGreen("test");
assertThat(internalCluster().size(), is(2));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class Netty4BadRequestIT method testInvalidHeaderValue.
public void testInvalidHeaderValue() throws IOException {
final Request request = new Request("GET", "/_cluster/settings");
final RequestOptions.Builder options = request.getOptions().toBuilder();
options.addHeader("Content-Type", "\t");
request.setOptions(options);
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("content_type_header_exception"));
assertThat(map.get("reason"), equalTo("java.lang.IllegalArgumentException: invalid Content-Type header []"));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class MappingIT method testAllFieldDisable6x.
/**
* Create a mapping that explicitly disables the _all field (possible in 6x, see #37429)
* and check that it can be upgraded to 7x.
*/
public void testAllFieldDisable6x() throws Exception {
assumeTrue("_all", UPGRADE_FROM_VERSION.before(LegacyESVersion.V_7_0_0));
switch(CLUSTER_TYPE) {
case OLD:
Request createTestIndex = new Request("PUT", "all-index");
createTestIndex.addParameter("include_type_name", "false");
createTestIndex.setJsonEntity("{ \"settings\": { \"index.number_of_shards\": 1 }, " + "\"mappings\": {\"_all\": { \"enabled\": false }, \"properties\": { \"field\": { \"type\": \"text\" }}}}");
createTestIndex.setOptions(expectWarnings("[_all] is deprecated in 6.0+ and will be removed in 7.0. As a replacement," + " " + "you can use [copy_to] on mapping fields to create your own catch all field."));
Response resp = client().performRequest(createTestIndex);
assertEquals(200, resp.getStatusLine().getStatusCode());
break;
default:
final Request request = new Request("GET", "all-index");
Response response = client().performRequest(request);
assertEquals(200, response.getStatusLine().getStatusCode());
Object enabled = XContentMapValues.extractValue("all-index.mappings._all.enabled", entityAsMap(response));
assertNotNull(enabled);
assertEquals(false, enabled);
break;
}
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class RecoveryIT method indexVersionCreated.
/**
* Returns the version in which the given index has been created
*/
private static Version indexVersionCreated(final String indexName) throws IOException {
final Request request = new Request("GET", "/" + indexName + "/_settings");
final String versionCreatedSetting = indexName + ".settings.index.version.created";
request.addParameter("filter_path", versionCreatedSetting);
final Response response = client().performRequest(request);
return Version.fromId(Integer.parseInt(ObjectPath.createFromResponse(response).evaluate(versionCreatedSetting)));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class RecoveryIT method testCloseIndexDuringRollingUpgrade.
/**
* This test creates and closes a new index at every stage of the rolling upgrade. It then checks that the index
* is effectively closed and potentially replicated if the cluster supports replication of closed indices at the
* time the index was closed.
*/
public void testCloseIndexDuringRollingUpgrade() throws Exception {
final Version minimumNodeVersion = minimumNodeVersion();
final String indexName = String.join("_", "index", CLUSTER_TYPE.toString(), Integer.toString(minimumNodeVersion.id)).toLowerCase(Locale.ROOT);
final Request indexExistsRequest = new Request("HEAD", "/" + indexName);
indexExistsRequest.setOptions(allowTypesRemovalWarnings());
final Response indexExistsResponse = client().performRequest(indexExistsRequest);
if (RestStatus.OK.getStatus() != indexExistsResponse.getStatusLine().getStatusCode()) {
createIndex(indexName, Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0).build());
ensureGreen(indexName);
closeIndex(indexName);
}
if (minimumNodeVersion.onOrAfter(LegacyESVersion.V_7_2_0)) {
// index is created on a version that supports the replication of closed indices,
// so we expect the index to be closed and replicated
ensureGreen(indexName);
assertClosedIndex(indexName, true);
} else {
assertClosedIndex(indexName, false);
}
}
Aggregations