Skip to content

Commit

Permalink
Fix core XcontentType refactor (#873)
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am authored Jul 27, 2023
1 parent 05bc0d5 commit d4cafd6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler

import org.opensearch.client.node.NodeClient
import org.opensearch.core.common.Strings
import org.opensearch.core.xcontent.MediaType
import org.opensearch.common.xcontent.XContentHelper
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI
Expand Down Expand Up @@ -55,7 +54,7 @@ class RestAddPolicyAction : BaseRestHandler() {
}

val body = if (request.hasContent()) {
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType as (MediaType)).v2()
XContentHelper.convertToMap(request.requiredContent(), false, request.mediaType).v2()
} else {
mapOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler
import org.opensearch.client.node.NodeClient
import org.opensearch.core.common.Strings
import org.opensearch.common.logging.DeprecationLogger
import org.opensearch.core.xcontent.MediaType
import org.opensearch.common.xcontent.XContentHelper
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ISM_BASE_URI
Expand Down Expand Up @@ -55,7 +54,7 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() {
throw IllegalArgumentException("Missing indices")
}
val body = if (request.hasContent()) {
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType as (MediaType)).v2()
XContentHelper.convertToMap(request.requiredContent(), false, request.mediaType).v2()
} else {
mapOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fun contentParser(bytesReference: BytesReference): XContentParser {

/** Convert an object to maps and lists representation */
fun ToXContent.convertToMap(): Map<String, Any> {
val bytesReference = XContentHelper.toXContent(this, XContentType.JSON, false)
val bytesReference = XContentHelper.toXContent(this, MediaType.fromMediaType(XContentType.JSON.mediaType()), ToXContent.EMPTY_PARAMS, false)
return XContentHelper.convertToMap(bytesReference, false, XContentType.JSON as (MediaType)).v2()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.common.xcontent.XContentType
import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN
import org.opensearch.core.rest.RestStatus
import org.opensearch.core.xcontent.MediaType
import java.io.IOException
import java.nio.file.Files
import java.util.*
Expand Down Expand Up @@ -189,7 +190,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
}

val response = client.performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all"))
val xContentType = XContentType.fromMediaType(response.entity.contentType)
val xContentType = MediaType.fromMediaType(response.entity.contentType)
xContentType.xContent().createParser(
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.entity.content
Expand Down Expand Up @@ -258,7 +259,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
protected fun waitForThreadPools(client: RestClient) {
val response = client.performRequest(Request("GET", "/_cat/thread_pool?format=json"))

val xContentType = XContentType.fromMediaType(response.entity.contentType)
val xContentType = MediaType.fromMediaType(response.entity.contentType)
xContentType.xContent().createParser(
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.entity.content
Expand Down

0 comments on commit d4cafd6

Please sign in to comment.