use of org.opensearch.client.RequestOptions.Builder in project OpenSearch by opensearch-project.
the class OpenSearchRestTestCase method refreshAllIndices.
protected void refreshAllIndices() throws IOException {
boolean includeHidden = minimumNodeVersion().onOrAfter(LegacyESVersion.V_7_7_0);
Request refreshRequest = new Request("POST", "/_refresh");
refreshRequest.addParameter("expand_wildcards", "open" + (includeHidden ? ",hidden" : ""));
// Allow system index deprecation warnings
final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
requestOptions.setWarningsHandler(warnings -> {
if (warnings.isEmpty()) {
return false;
} else if (warnings.size() > 1) {
return true;
} else {
return warnings.get(0).startsWith("this request accesses system indices:") == false;
}
});
refreshRequest.setOptions(requestOptions);
client().performRequest(refreshRequest);
}
use of org.opensearch.client.RequestOptions.Builder in project OpenSearch by opensearch-project.
the class OpenSearchRestTestCase method expectSoftDeletesWarning.
protected static void expectSoftDeletesWarning(Request request, String indexName) {
final List<String> esExpectedWarnings = Collections.singletonList("Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. " + "Please do not specify value for setting [index.soft_deletes.enabled] of index [" + indexName + "].");
final List<String> opensearchExpectedWarnings = Collections.singletonList("Creating indices with soft-deletes disabled is deprecated and will be removed in future OpenSearch versions. " + "Please do not specify value for setting [index.soft_deletes.enabled] of index [" + indexName + "].");
final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(LegacyESVersion.V_7_6_0) && version.before(Version.V_1_0_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.equals(esExpectedWarnings) == false);
request.setOptions(requestOptions);
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(LegacyESVersion.V_7_6_0) && version.before(Version.V_1_0_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(esExpectedWarnings) == false);
request.setOptions(requestOptions);
}
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_1_0_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.equals(opensearchExpectedWarnings) == false);
request.setOptions(requestOptions);
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(Version.V_1_0_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(opensearchExpectedWarnings) == false);
request.setOptions(requestOptions);
}
}
use of org.opensearch.client.RequestOptions.Builder in project OpenSearch by opensearch-project.
the class OpenSearchRestTestCase method allowTypesRemovalWarnings.
/**
* Creates RequestOptions designed to ignore [types removal] warnings but nothing else
* @deprecated this method is only required while we deprecate types and can be removed in 8.0
*/
@Deprecated
public static RequestOptions allowTypesRemovalWarnings() {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.setWarningsHandler(new WarningsHandler() {
@Override
public boolean warningsShouldFailRequest(List<String> warnings) {
for (String warning : warnings) {
if (warning.startsWith("[types removal]") == false) {
// Something other than a types removal message - return true
return true;
}
}
return false;
}
});
return builder.build();
}
use of org.opensearch.client.RequestOptions.Builder in project OpenSearch by opensearch-project.
the class OpenSearchRestTestCase method expectTranslogRetentionWarning.
protected static void expectTranslogRetentionWarning(Request request) {
final List<String> expectedWarnings = Collections.singletonList("Translog retention settings [index.translog.retention.age] " + "and [index.translog.retention.size] are deprecated and effectively ignored. They will be removed in a future version.");
final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(LegacyESVersion.V_7_7_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.equals(expectedWarnings) == false);
request.setOptions(requestOptions);
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(LegacyESVersion.V_7_7_0))) {
requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
request.setOptions(requestOptions);
}
}
use of org.opensearch.client.RequestOptions.Builder in project OpenSearch by opensearch-project.
the class OpenSearchRestTestCase method syncedFlush.
protected void syncedFlush(String indexName, boolean retryOnConflict) throws Exception {
final Request request = new Request("POST", indexName + "/_flush/synced");
final Builder options = RequestOptions.DEFAULT.toBuilder();
// 8.0 kept in warning message for legacy purposes TODO: changge to 3.0
final List<String> warningMessage = Arrays.asList("Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead.");
final List<String> expectedWarnings = Arrays.asList("Synced flush was removed and a normal flush was performed instead. This transition will be removed in a future version.");
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_2_0_0))) {
options.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(LegacyESVersion.V_7_6_0))) {
options.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false && warnings.equals(warningMessage) == false);
}
request.setOptions(options);
// We have to spin synced-flush requests here because we fire the global checkpoint sync for the last write operation.
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
assertBusy(() -> {
try {
Response resp = client().performRequest(request);
if (retryOnConflict) {
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
assertThat(result.get("failed"), equalTo(0));
}
} catch (ResponseException ex) {
assertThat(ex.getResponse().getStatusLine(), equalTo(HttpStatus.SC_CONFLICT));
if (retryOnConflict) {
// cause assert busy to retry
throw new AssertionError(ex);
}
}
});
// ensure the global checkpoint is synced; otherwise we might trim the commit with syncId
ensureGlobalCheckpointSynced(indexName);
}
Aggregations