Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Revert "[Backport 2.x] Require MediaType in Strings.toString API (ope…
Browse files Browse the repository at this point in the history
…nsearch-project#6009) (opensearch-project#6414)"

This reverts commit c4ab236.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
  • Loading branch information
kartg committed Feb 22, 2023
1 parent 9977a1a commit d3aedef
Show file tree
Hide file tree
Showing 159 changed files with 245 additions and 407 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Refactor] core.common to new opensearch-common library ([#5976](https://github.com/opensearch-project/OpenSearch/pull/5976))
- Update API spec for cluster health API ([#6399](https://github.com/opensearch-project/OpenSearch/pull/6399))
- Remove deprecated org.gradle.util.DistributionLocator usage ([#6212](https://github.com/opensearch-project/OpenSearch/pull/6212))
- Require MediaType in Strings.toString API ([#6009](https://github.com/opensearch-project/OpenSearch/pull/6009))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -169,6 +168,6 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.snapshots.SnapshotId;

import java.io.IOException;
Expand Down Expand Up @@ -289,7 +288,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -188,7 +187,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}

public static class SnapshotPolicyStats implements ToXContentFragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Objects;
Expand Down Expand Up @@ -151,6 +150,6 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.search.aggregations.AggregationBuilders;
import org.opensearch.search.builder.SearchSourceBuilder;

Expand Down Expand Up @@ -172,8 +171,8 @@ public void testAggregationUsage() throws IOException {
.aggregation(AggregationBuilders.terms("str_terms").field("str.keyword"))
.aggregation(AggregationBuilders.terms("num_terms").field("num"))
.aggregation(AggregationBuilders.avg("num_avg").field("num"));
searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource));
searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource));
searchRequest.setJsonEntity(Strings.toString(searchSource));
searchRequest.setJsonEntity(Strings.toString(searchSource));
client().performRequest(searchRequest);

searchRequest = new Request("GET", "/test/_search");
Expand All @@ -182,8 +181,8 @@ public void testAggregationUsage() throws IOException {
.aggregation(AggregationBuilders.avg("num1").field("num"))
.aggregation(AggregationBuilders.avg("num2").field("num"))
.aggregation(AggregationBuilders.terms("foo").field("foo.keyword"));
String r = Strings.toString(XContentType.JSON, searchSource);
searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource));
String r = Strings.toString(searchSource);
searchRequest.setJsonEntity(Strings.toString(searchSource));
client().performRequest(searchRequest);

Response response = client().performRequest(new Request("GET", "_nodes/usage"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ public interface MediaType {
default String typeWithSubtype() {
return type() + "/" + subtype();
}

XContent xContent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public String mediaType() {
return mediaTypeWithoutParameters();
}

public abstract XContent xContent();

public abstract String mediaTypeWithoutParameters();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ public int hashCode() {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -207,6 +206,6 @@ public static MultiSearchTemplateResponse fromXContext(XContentParser parser) {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.lucene.search.MultiPhrasePrefixQuery;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.analysis.AnalyzerScope;
import org.opensearch.index.analysis.IndexAnalyzers;
Expand Down Expand Up @@ -610,15 +609,15 @@ public void testAnalyzerSerialization() throws IOException {
b.field("type", "search_as_you_type");
b.field("analyzer", "simple");
}));
String serialized = Strings.toString(XContentType.JSON, ms.documentMapper());
String serialized = Strings.toString(ms.documentMapper());
assertEquals(
serialized,
"{\"_doc\":{\"properties\":{\"field\":"
+ "{\"type\":\"search_as_you_type\",\"doc_values\":false,\"max_shingle_size\":3,\"analyzer\":\"simple\"}}}}"
);

merge(ms, mapping(b -> {}));
assertEquals(serialized, Strings.toString(XContentType.JSON, ms.documentMapper()));
assertEquals(serialized, Strings.toString(ms.documentMapper()));
}

private void documentParsingTestCase(Collection<String> values) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentParserUtils;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -106,7 +105,7 @@ public Map<String, Exception> getFailures() {

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentParserUtils;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.script.Script;

import java.io.IOException;
Expand Down Expand Up @@ -250,7 +249,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Objects;
Expand Down Expand Up @@ -129,7 +128,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.rankeval.RatedDocument.DocumentKey;
import org.opensearch.search.builder.SearchSourceBuilder;

Expand Down Expand Up @@ -341,7 +340,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this);
return Strings.toString(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,10 @@ public void testMetricDetails() {
+ ",\"unrated_docs\":"
+ unratedDocs
+ "}}",
Strings.toString(XContentType.JSON, detail)
Strings.toString(detail)
);
} else {
assertEquals(
"{\"dcg\":{\"dcg\":" + dcg + ",\"unrated_docs\":" + unratedDocs + "}}",
Strings.toString(XContentType.JSON, detail)
);
assertEquals("{\"dcg\":{\"dcg\":" + dcg + ",\"unrated_docs\":" + unratedDocs + "}}", Strings.toString(detail));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.IndexSettings;
Expand Down Expand Up @@ -1373,7 +1372,7 @@ public void testResize() throws Exception {
if (randomBoolean()) {
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
}
shrinkRequest.setJsonEntity("{\"settings\":" + Strings.toString(XContentType.JSON, settings.build()) + "}");
shrinkRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}");
client().performRequest(shrinkRequest);
ensureGreenLongWait(target);
assertNumHits(target, numDocs + moreDocs, 1);
Expand All @@ -1385,7 +1384,7 @@ public void testResize() throws Exception {
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
}
Request splitRequest = new Request("PUT", "/" + index + "/_split/" + target);
splitRequest.setJsonEntity("{\"settings\":" + Strings.toString(XContentType.JSON, settings.build()) + "}");
splitRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}");
client().performRequest(splitRequest);
ensureGreenLongWait(target);
assertNumHits(target, numDocs + moreDocs, 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ public void testCompletionSuggester() throws Exception {
sourceBuilder.suggest(suggestBuilder);
duelSearch(searchRequest, response -> {
assertMultiClusterSearchResponse(response);
assertEquals(Strings.toString(XContentType.JSON, response, true, true), 3, response.getSuggest().size());
assertEquals(Strings.toString(response, true, true), 3, response.getSuggest().size());
assertThat(response.getSuggest().getSuggestion("python").getEntries().size(), greaterThan(0));
assertThat(response.getSuggest().getSuggestion("java").getEntries().size(), greaterThan(0));
assertThat(response.getSuggest().getSuggestion("ruby").getEntries().size(), greaterThan(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.rest.RestStatus;

import java.io.IOException;
Expand Down Expand Up @@ -204,7 +203,7 @@ private void bulk(String index, String valueSuffix, int count) throws IOExceptio

private void createIndexWithDocMappings(String index, Settings settings, String mapping) throws IOException {
Request createIndexWithMappingsRequest = new Request(HttpPut.METHOD_NAME, "/" + index);
String entity = "{\"settings\": " + Strings.toString(XContentType.JSON, settings);
String entity = "{\"settings\": " + Strings.toString(settings);
if (mapping != null) {
entity += ",\"mappings\" : {" + mapping + "}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.AbstractRunnable;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.IndexSettings;
import org.opensearch.rest.RestStatus;
Expand Down Expand Up @@ -801,7 +800,7 @@ public void testSoftDeletesDisabledWarning() throws Exception {
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), softDeletesEnabled);
}
Request request = new Request("PUT", "/" + indexName);
request.setJsonEntity("{\"settings\": " + Strings.toString(XContentType.JSON, settings.build()) + "}");
request.setJsonEntity("{\"settings\": " + Strings.toString(settings.build()) + "}");
if (softDeletesEnabled == false) {
expectSoftDeletesWarning(request, indexName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testAutomaticCancellationDuringQueryPhase() throws Exception {
Request searchRequest = new Request("GET", "/test/_search");
SearchSourceBuilder searchSource = new SearchSourceBuilder().query(scriptQuery(
new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.SCRIPT_NAME, Collections.emptyMap())));
searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource));
searchRequest.setJsonEntity(Strings.toString(searchSource));
verifyCancellationDuringQueryPhase(SearchAction.NAME, searchRequest);
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public void testAutomaticCancellationDuringFetchPhase() throws Exception {
Request searchRequest = new Request("GET", "/test/_search");
SearchSourceBuilder searchSource = new SearchSourceBuilder().scriptField("test_field",
new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.SCRIPT_NAME, Collections.emptyMap()));
searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource));
searchRequest.setJsonEntity(Strings.toString(searchSource));
verifyCancellationDuringFetchPhase(SearchAction.NAME, searchRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,13 @@ public void testNoopUpdate() {

final BulkItemResponse noopUpdate = bulkResponse.getItems()[0];
assertThat(noopUpdate.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP));
assertThat(Strings.toString(XContentType.JSON, noopUpdate), noopUpdate.getResponse().getShardInfo().getSuccessful(), equalTo(2));
assertThat(Strings.toString(noopUpdate), noopUpdate.getResponse().getShardInfo().getSuccessful(), equalTo(2));

final BulkItemResponse notFoundUpdate = bulkResponse.getItems()[1];
assertNotNull(notFoundUpdate.getFailure());

final BulkItemResponse notFoundDelete = bulkResponse.getItems()[2];
assertThat(notFoundDelete.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOT_FOUND));
assertThat(
Strings.toString(XContentType.JSON, notFoundDelete),
notFoundDelete.getResponse().getShardInfo().getSuccessful(),
equalTo(2)
);
assertThat(Strings.toString(notFoundDelete), notFoundDelete.getResponse().getShardInfo().getSuccessful(), equalTo(2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.opensearch.common.collect.ImmutableOpenIntMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.set.Sets;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.gateway.GatewayAllocator;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.engine.Engine;
Expand Down Expand Up @@ -137,7 +136,7 @@ public void testBulkWeirdScenario() throws Exception {
assertThat(bulkResponse.hasFailures(), equalTo(false));
assertThat(bulkResponse.getItems().length, equalTo(2));

logger.info(Strings.toString(XContentType.JSON, bulkResponse, true, true));
logger.info(Strings.toString(bulkResponse, true, true));

internalCluster().assertSeqNos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void testMaybeFlush() throws Exception {
final FlushStats flushStats = shard.flushStats();
logger.info(
"--> translog stats [{}] gen [{}] commit_stats [{}] flush_stats [{}/{}]",
Strings.toString(XContentType.JSON, translogStats),
Strings.toString(translogStats),
translog.getGeneration().translogFileGeneration,
commitStats.getUserData(),
flushStats.getPeriodic(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,7 @@ public void testRecoverLocallyUpToGlobalCheckpoint() throws Exception {
.getShard(0)
.getRetentionLeases();
throw new AssertionError(
"expect an operation-based recovery:"
+ "retention leases"
+ Strings.toString(XContentType.JSON, retentionLeases)
+ "]"
"expect an operation-based recovery:" + "retention leases" + Strings.toString(retentionLeases) + "]"
);
}
connection.sendRequest(requestId, action, request, options);
Expand Down
Loading

0 comments on commit d3aedef

Please sign in to comment.