Skip to content

Commit

Permalink
Fix core XcontentType refactor (opensearch-project#873)
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
(cherry picked from commit d4cafd6)
  • Loading branch information
Hailong-am committed Aug 7, 2023
1 parent fbfc896 commit d8a3ac6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -55,7 +55,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 @@ -73,7 +73,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 @@ -24,7 +24,8 @@ import org.opensearch.core.xcontent.DeprecationHandler
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.common.xcontent.XContentType
import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN
import org.opensearch.rest.RestStatus
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 @@ -194,7 +195,11 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
}

val response = client.performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all"))
<<<<<<< HEAD
val xContentType = XContentType.fromMediaType(response.entity.contentType.value)
=======
val xContentType = MediaType.fromMediaType(response.entity.contentType)
>>>>>>> d4cafd60 (Fix core XcontentType refactor (#873))
xContentType.xContent().createParser(
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.entity.content
Expand Down Expand Up @@ -263,7 +268,11 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() {
protected fun waitForThreadPools(client: RestClient) {
val response = client.performRequest(Request("GET", "/_cat/thread_pool?format=json"))

<<<<<<< HEAD
val xContentType = XContentType.fromMediaType(response.entity.contentType.value)
=======
val xContentType = MediaType.fromMediaType(response.entity.contentType)
>>>>>>> d4cafd60 (Fix core XcontentType refactor (#873))
xContentType.xContent().createParser(
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.entity.content
Expand Down

0 comments on commit d8a3ac6

Please sign in to comment.