use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class FullClusterRestartIT method testSystemIndexMetadataIsUpgraded.
@SuppressWarnings("unchecked")
public void testSystemIndexMetadataIsUpgraded() throws Exception {
final String systemIndexWarning = "this request accesses system indices: [.tasks], but in a future major version, direct " + "access to system indices will be prevented by default";
if (isRunningAgainstOldCluster()) {
// create index
Request createTestIndex = new Request("PUT", "/test_index_old");
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0, \"index.number_of_shards\": 1}}");
client().performRequest(createTestIndex);
Request bulk = new Request("POST", "/_bulk");
bulk.addParameter("refresh", "true");
bulk.setJsonEntity("{\"index\": {\"_index\": \"test_index_old\"}}\n" + "{\"f1\": \"v1\", \"f2\": \"v2\"}\n");
client().performRequest(bulk);
// start a async reindex job
Request reindex = new Request("POST", "/_reindex");
reindex.setJsonEntity("{\n" + " \"source\":{\n" + " \"index\":\"test_index_old\"\n" + " },\n" + " \"dest\":{\n" + " \"index\":\"test_index_reindex\"\n" + " }\n" + "}");
reindex.addParameter("wait_for_completion", "false");
Map<String, Object> response = entityAsMap(client().performRequest(reindex));
String taskId = (String) response.get("task");
// wait for task
Request getTask = new Request("GET", "/_tasks/" + taskId);
getTask.addParameter("wait_for_completion", "true");
client().performRequest(getTask);
// make sure .tasks index exists
Request getTasksIndex = new Request("GET", "/.tasks");
getTasksIndex.addParameter("allow_no_indices", "false");
if (getOldClusterVersion().before(LegacyESVersion.V_7_0_0)) {
getTasksIndex.addParameter("include_type_name", "false");
}
getTasksIndex.setOptions(expectVersionSpecificWarnings(v -> {
v.current(systemIndexWarning);
v.compatible(systemIndexWarning);
}));
assertBusy(() -> {
try {
assertThat(client().performRequest(getTasksIndex).getStatusLine().getStatusCode(), is(200));
} catch (ResponseException e) {
throw new AssertionError(".tasks index does not exist yet");
}
});
// upgraded properly. If we're already on 8.x, skip this part of the test.
if (minimumNodeVersion().before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Create an alias to make sure it gets upgraded properly
Request putAliasRequest = new Request("POST", "/_aliases");
putAliasRequest.setJsonEntity("{\n" + " \"actions\": [\n" + " {\"add\": {\"index\": \".tasks\", \"alias\": \"test-system-alias\"}},\n" + " {\"add\": {\"index\": \"test_index_reindex\", \"alias\": \"test-system-alias\"}}\n" + " ]\n" + "}");
assertThat(client().performRequest(putAliasRequest).getStatusLine().getStatusCode(), is(200));
}
} else {
assertBusy(() -> {
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata");
Map<String, Object> indices = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get("metadata.indices");
// Make sure our non-system index is still non-system
assertThat(new XContentTestUtils.JsonMapView(indices).get("test_index_old.system"), is(false));
// Can't get the .tasks index via JsonMapView because it splits on `.`
assertThat(indices, hasKey(".tasks"));
XContentTestUtils.JsonMapView tasksIndex = new XContentTestUtils.JsonMapView((Map<String, Object>) indices.get(".tasks"));
assertThat(tasksIndex.get("system"), is(true));
// If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
assertThat(tasksCreatedVersionString, notNullValue());
final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Verify that the alias survived the upgrade
Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
v.current(systemIndexWarning);
v.compatible(systemIndexWarning);
}));
Map<String, Object> aliasResponse = entityAsMap(client().performRequest(getAliasRequest));
assertThat(aliasResponse, hasKey(".tasks"));
assertThat(aliasResponse, hasKey("test_index_reindex"));
}
});
}
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class CrossClusterSearchUnavailableClusterIT method updateRemoteClusterSettings.
private static void updateRemoteClusterSettings(Map<String, Object> settings) throws IOException {
Request request = new Request("PUT", "/_cluster/settings");
request.setEntity(buildUpdateSettingsRequestBody(settings));
Response response = client().performRequest(request);
assertEquals(200, response.getStatusLine().getStatusCode());
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class CrossClusterSearchUnavailableClusterIT method testSearchSkipUnavailable.
public void testSearchSkipUnavailable() throws IOException {
try (MockTransportService remoteTransport = startTransport("node0", new CopyOnWriteArrayList<>(), Version.CURRENT, threadPool)) {
DiscoveryNode remoteNode = remoteTransport.getLocalDiscoNode();
updateRemoteClusterSettings(Collections.singletonMap("seeds", remoteNode.getAddress().toString()));
for (int i = 0; i < 10; i++) {
restHighLevelClient.index(new IndexRequest("index").id(String.valueOf(i)).source("field", "value"), RequestOptions.DEFAULT);
}
Response refreshResponse = client().performRequest(new Request("POST", "/index/_refresh"));
assertEquals(200, refreshResponse.getStatusLine().getStatusCode());
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("index"), RequestOptions.DEFAULT);
assertSame(SearchResponse.Clusters.EMPTY, response.getClusters());
assertEquals(10, response.getHits().getTotalHits().value);
assertEquals(10, response.getHits().getHits().length);
}
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("index", "remote1:index"), RequestOptions.DEFAULT);
assertEquals(2, response.getClusters().getTotal());
assertEquals(2, response.getClusters().getSuccessful());
assertEquals(0, response.getClusters().getSkipped());
assertEquals(10, response.getHits().getTotalHits().value);
assertEquals(10, response.getHits().getHits().length);
}
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("remote1:index"), RequestOptions.DEFAULT);
assertEquals(1, response.getClusters().getTotal());
assertEquals(1, response.getClusters().getSuccessful());
assertEquals(0, response.getClusters().getSkipped());
assertEquals(0, response.getHits().getTotalHits().value);
}
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("index", "remote1:index").scroll("1m"), RequestOptions.DEFAULT);
assertEquals(2, response.getClusters().getTotal());
assertEquals(2, response.getClusters().getSuccessful());
assertEquals(0, response.getClusters().getSkipped());
assertEquals(10, response.getHits().getTotalHits().value);
assertEquals(10, response.getHits().getHits().length);
String scrollId = response.getScrollId();
SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters());
assertEquals(10, scrollResponse.getHits().getTotalHits().value);
assertEquals(0, scrollResponse.getHits().getHits().length);
}
remoteTransport.close();
updateRemoteClusterSettings(Collections.singletonMap("skip_unavailable", true));
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("index", "remote1:index"), RequestOptions.DEFAULT);
assertEquals(2, response.getClusters().getTotal());
assertEquals(1, response.getClusters().getSuccessful());
assertEquals(1, response.getClusters().getSkipped());
assertEquals(10, response.getHits().getTotalHits().value);
assertEquals(10, response.getHits().getHits().length);
}
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("remote1:index"), RequestOptions.DEFAULT);
assertEquals(1, response.getClusters().getTotal());
assertEquals(0, response.getClusters().getSuccessful());
assertEquals(1, response.getClusters().getSkipped());
assertEquals(0, response.getHits().getTotalHits().value);
}
{
SearchResponse response = restHighLevelClient.search(new SearchRequest("index", "remote1:index").scroll("1m"), RequestOptions.DEFAULT);
assertEquals(2, response.getClusters().getTotal());
assertEquals(1, response.getClusters().getSuccessful());
assertEquals(1, response.getClusters().getSkipped());
assertEquals(10, response.getHits().getTotalHits().value);
assertEquals(10, response.getHits().getHits().length);
String scrollId = response.getScrollId();
SearchResponse scrollResponse = restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);
assertSame(SearchResponse.Clusters.EMPTY, scrollResponse.getClusters());
assertEquals(10, scrollResponse.getHits().getTotalHits().value);
assertEquals(0, scrollResponse.getHits().getHits().length);
}
updateRemoteClusterSettings(Collections.singletonMap("skip_unavailable", false));
assertSearchConnectFailure();
Map<String, Object> map = new HashMap<>();
map.put("seeds", null);
map.put("skip_unavailable", null);
updateRemoteClusterSettings(map);
}
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class IndexingIT method assertVersion.
private void assertVersion(final String index, final int docId, final String preference, final int expectedVersion) throws IOException {
Request request = new Request("GET", index + "/_doc/" + docId);
request.addParameter("preference", preference);
final Response response = client().performRequest(request);
assertOK(response);
final int actualVersion = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("_version").toString());
assertThat("version mismatch for doc [" + docId + "] preference [" + preference + "]", actualVersion, equalTo(expectedVersion));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class IndexingIT method assertCount.
private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
Request request = new Request("GET", index + "/_count");
request.addParameter("preference", preference);
final Response response = client().performRequest(request);
assertOK(response);
final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
assertThat(actualCount, equalTo(expectedCount));
}
Aggregations