Skip to content

Commit

Permalink
Adapt the MediaType changes in core
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 committed Jul 25, 2023
1 parent 59e2657 commit c393686
Show file tree
Hide file tree
Showing 82 changed files with 617 additions and 617 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.http.BindHttpException;
import org.opensearch.node.PluginAwareNode;
import org.opensearch.plugins.Plugin;
Expand Down Expand Up @@ -324,7 +324,7 @@ public void waitForCluster(ClusterHealthStatus status, TimeValue timeout, int ex
.actionGet();

if (log.isDebugEnabled()) {
log.debug("Current ClusterState:\n{}", Strings.toString(XContentType.JSON, healthResponse));
log.debug("Current ClusterState:\n{}", Strings.toString(MediaType.JSON, healthResponse));
}

if (healthResponse.isTimedOut()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import org.apache.logging.log4j.Logger;

import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.security.DefaultObjectMapper;

Expand Down Expand Up @@ -163,7 +163,7 @@ private StringEntity toStringEntity(String body) {
}

public HttpResponse putJson(String path, ToXContentObject body) {
return putJson(path, Strings.toString(XContentType.JSON, body));
return putJson(path, Strings.toString(MediaType.JSON, body));
}

public HttpResponse put(String path) {
Expand All @@ -182,7 +182,7 @@ public HttpResponse postJson(String path, String body, Header... headers) {
}

public HttpResponse postJson(String path, ToXContentObject body) {
return postJson(path, Strings.toString(XContentType.JSON, body));
return postJson(path, Strings.toString(MediaType.JSON, body));
}

public HttpResponse post(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.opensearch.SpecialPermission;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;
Expand Down Expand Up @@ -192,7 +192,7 @@ private boolean handleLowLevel(RestRequest restRequest, RestChannel restChannel)
XPathExpressionException, ParserConfigurationException, SAXException, SettingsException {
try {

if (restRequest.getXContentType() != XContentType.JSON) {
if (restRequest.getMediaType() != MediaType.JSON) {
throw new OpenSearchSecurityException(
"/_opendistro/_security/api/authtoken expects content with type application/json",
RestStatus.UNSUPPORTED_MEDIA_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.opensearch.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;

Expand Down Expand Up @@ -105,6 +105,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(XContentType.JSON, this, true, true);
return Strings.toString(MediaType.JSON, this, true, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -572,14 +572,14 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
NamedXContentRegistry.EMPTY,
THROW_UNSUPPORTED_OPERATION,
originalResult.internalSourceRef(),
XContentType.JSON
MediaType.JSON
)
) {
Object base64 = parser.map().values().iterator().next();
if (base64 instanceof String) {
originalSource = (new String(BaseEncoding.base64().decode((String) base64), StandardCharsets.UTF_8));
} else {
originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, XContentType.JSON);
originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, MediaType.JSON);
}
} catch (Exception e) {
log.error(e.toString());
Expand All @@ -590,14 +590,14 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
NamedXContentRegistry.EMPTY,
THROW_UNSUPPORTED_OPERATION,
currentIndex.source(),
XContentType.JSON
MediaType.JSON
)
) {
Object base64 = parser.map().values().iterator().next();
if (base64 instanceof String) {
currentSource = new String(BaseEncoding.base64().decode((String) base64), StandardCharsets.UTF_8);
} else {
currentSource = XContentHelper.convertToJson(currentIndex.source(), false, XContentType.JSON);
currentSource = XContentHelper.convertToJson(currentIndex.source(), false, MediaType.JSON);
}
} catch (Exception e) {
log.error(e.toString());
Expand All @@ -608,8 +608,8 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
);
msg.addSecurityConfigWriteDiffSource(diffnode.size() == 0 ? "" : diffnode.toString(), id);
} else {
originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, XContentType.JSON);
currentSource = XContentHelper.convertToJson(currentIndex.source(), false, XContentType.JSON);
originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, MediaType.JSON);
currentSource = XContentHelper.convertToJson(currentIndex.source(), false, MediaType.JSON);
final JsonNode diffnode = JsonDiff.asJson(
DefaultObjectMapper.objectMapper.readTree(originalSource),
DefaultObjectMapper.objectMapper.readTree(currentSource)
Expand All @@ -629,7 +629,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
NamedXContentRegistry.EMPTY,
THROW_UNSUPPORTED_OPERATION,
currentIndex.source(),
XContentType.JSON
MediaType.JSON
)
) {
Object base64 = parser.map().values().iterator().next();
Expand All @@ -640,7 +640,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
);
} else {
msg.addSecurityConfigTupleToRequestBody(
new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()),
new Tuple<MediaType, BytesReference>(MediaType.JSON, currentIndex.source()),
id
);
}
Expand All @@ -653,11 +653,11 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
} else {

// previous source, can be null if document is a new one
// msg.ComplianceWritePreviousSource(new Tuple<XContentType, BytesReference>(XContentType.JSON,
// msg.ComplianceWritePreviousSource(new Tuple<MediaType, BytesReference>(MediaType.JSON,
// originalResult.internalSourceRef()));

// current source, normally not null or empty
msg.addTupleToRequestBody(new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()));
msg.addTupleToRequestBody(new Tuple<MediaType, BytesReference>(MediaType.JSON, currentIndex.source()));
}

}
Expand Down Expand Up @@ -728,7 +728,7 @@ public Map run() {
final String sha256 = DigestUtils.sha256Hex(configAsMap.toString() + envAsMap.toString() + propsAsMap.toString());
AuditMessage msg = new AuditMessage(AuditCategory.COMPLIANCE_EXTERNAL_CONFIG, clusterService, null, null);

try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
try (XContentBuilder builder = XContentBuilder.builder(MediaType.JSON.xContent())) {
builder.startObject();
builder.startObject("external_configuration");
builder.field("opensearch_yml", configAsMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.common.Strings;
import org.opensearch.core.index.shard.ShardId;
Expand Down Expand Up @@ -205,7 +205,7 @@ void addSecurityConfigWriteDiffSource(final String diff, final String id) {
// }
// }

public void addTupleToRequestBody(Tuple<XContentType, BytesReference> xContentTuple) {
public void addTupleToRequestBody(Tuple<MediaType, BytesReference> xContentTuple) {
if (xContentTuple != null) {
try {
auditInfo.put(REQUEST_BODY, XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()));
Expand Down Expand Up @@ -241,7 +241,7 @@ void addSecurityConfigContentToRequestBody(final String source, final String id)
}
}

void addSecurityConfigTupleToRequestBody(final Tuple<XContentType, BytesReference> xContentTuple, final String id) {
void addSecurityConfigTupleToRequestBody(final Tuple<MediaType, BytesReference> xContentTuple, final String id) {
if (xContentTuple != null) {
try {
addSecurityConfigContentToRequestBody(XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()), id);
Expand Down Expand Up @@ -377,7 +377,7 @@ void addRestRequestInfo(final RestRequest request, final AuditConfig.Filter filt
addRestMethod(request.method());
if (filter.shouldLogRequestBody() && request.hasContentOrSourceParam()) {
try {
final Tuple<XContentType, BytesReference> xContentTuple = request.contentOrSourceParam();
final Tuple<MediaType, BytesReference> xContentTuple = request.contentOrSourceParam();
final String requestBody = XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1());
if (path != null
&& requestBody != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.index.Index;
import org.opensearch.index.reindex.DeleteByQueryRequest;
Expand Down Expand Up @@ -287,7 +287,7 @@ private static AuditMessage resolveInner(
indices,
resolver,
cs,
XContentType.JSON,
MediaType.JSON,
sourceAsMap,
settings,
resolveIndices,
Expand Down Expand Up @@ -381,7 +381,7 @@ private static void addIndicesSourceSafe(
final String[] indices,
final IndexNameExpressionResolver resolver,
final ClusterService cs,
final XContentType xContentType,
final MediaType xContentType,
final Object source,
final Settings settings,
boolean resolveIndices,
Expand Down Expand Up @@ -438,12 +438,12 @@ private static void addIndicesSourceSafe(
}
}

private static Tuple<XContentType, BytesReference> convertSource(XContentType type, BytesReference bytes) {
private static Tuple<MediaType, BytesReference> convertSource(MediaType type, BytesReference bytes) {
if (type == null) {
type = XContentType.JSON;
type = MediaType.JSON;
}

return new Tuple<XContentType, BytesReference>(type, bytes);
return new Tuple<MediaType, BytesReference>(type, bytes);
}

private static String[] arrayOrEmpty(String[] array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.security.DefaultObjectMapper;
Expand Down Expand Up @@ -277,7 +277,7 @@ private SecurityDynamicConfiguration<?> toConfig(GetResponse singleGetResponse,
XContentParser parser = null;

try {
parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, ref, XContentType.JSON);
parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, ref, MediaType.JSON);
parser.nextToken();
parser.nextToken();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.util.concurrent.ThreadContext.StoredContext;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.env.Environment;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.security.auditlog.AuditLog;
Expand Down Expand Up @@ -464,7 +464,7 @@ public Map<CType, SecurityDynamicConfiguration<?>> getConfigurationsFromIndex(
if (logComplianceEvent && auditLog.getComplianceConfig().isEnabled()) {
CType configurationType = configTypes.iterator().next();
Map<String, String> fields = new HashMap<String, String>();
fields.put(configurationType.toLCString(), Strings.toString(XContentType.JSON, retVal.get(configurationType)));
fields.put(configurationType.toLCString(), Strings.toString(MediaType.JSON, retVal.get(configurationType)));
auditLog.logDocumentRead(this.securityIndex, configurationType.toLCString(), null, fields);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import org.opensearch.common.lucene.index.SequentialStoredFieldsLeafReader;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.IndexService;
Expand Down Expand Up @@ -697,10 +697,10 @@ public void binaryField(final FieldInfo fieldInfo, final byte[] value) throws IO

if (fieldInfo.name.equals("_source")) {
final BytesReference bytesRef = new BytesArray(value);
final Tuple<XContentType, Map<String, Object>> bytesRefTuple = XContentHelper.convertToMap(
final Tuple<MediaType, Map<String, Object>> bytesRefTuple = XContentHelper.convertToMap(
bytesRef,
false,
XContentType.JSON
MediaType.JSON
);
Map<String, Object> filteredSource = bytesRefTuple.v2();
MapUtils.deepTraverseMap(filteredSource, HASH_CB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.index.query.ParsedQuery;
import org.opensearch.core.rest.RestStatus;
Expand Down Expand Up @@ -230,10 +230,10 @@ public boolean invoke(
StringBuilder sb = new StringBuilder();

if (searchRequest.source() != null) {
sb.append(Strings.toString(XContentType.JSON, searchRequest.source()) + System.lineSeparator());
sb.append(Strings.toString(MediaType.JSON, searchRequest.source()) + System.lineSeparator());
}

sb.append(Strings.toString(XContentType.JSON, af) + System.lineSeparator());
sb.append(Strings.toString(MediaType.JSON, af) + System.lineSeparator());

LogManager.getLogger("debuglogger").error(sb.toString());

Expand All @@ -245,7 +245,7 @@ public boolean invoke(
LogManager.getLogger("debuglogger")
.error(
"Shard requestcache enabled for "
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(XContentType.JSON, searchRequest.source()))
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(MediaType.JSON, searchRequest.source()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext.StoredContext;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.engine.VersionConflictEngineException;
Expand Down Expand Up @@ -376,7 +376,7 @@ public static void saveAndUpdateConfigs(
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.setIfSeqNo(configuration.getSeqNo())
.setIfPrimaryTerm(configuration.getPrimaryTerm())
.source(id, XContentHelper.toXContent(configuration, XContentType.JSON, false)),
.source(id, XContentHelper.toXContent(configuration, MediaType.JSON, false)),
new ConfigUpdatingActionListener<>(new String[] { id }, client, actionListener)
);
} catch (IOException e) {
Expand Down
Loading

0 comments on commit c393686

Please sign in to comment.