Skip to content

Commit

Permalink
Fixed usages of deprecated methods and constants from OSCore and comm…
Browse files Browse the repository at this point in the history
…on-util (#687)

* Fixed usages of deprecated methods and constants

Signed-off-by: Angie Zhang <[email protected]>

* Fixed usages of deprecated methods and constants

Signed-off-by: Angie Zhang <[email protected]>

* Fixed flaky test: RestStopRollupActionIT: test stopping rollup with metadata

Signed-off-by: Angie Zhang <[email protected]>

---------

Signed-off-by: Angie Zhang <[email protected]>
  • Loading branch information
Angie Zhang authored Feb 17, 2023
1 parent e84d9e0 commit 289ab3b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler

import org.opensearch.client.node.NodeClient
import org.opensearch.common.Strings
import org.opensearch.common.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 @@ -54,7 +55,7 @@ class RestAddPolicyAction : BaseRestHandler() {
}

val body = if (request.hasContent()) {
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType).v2()
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType as (MediaType)).v2()
} else {
mapOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler
import org.opensearch.client.node.NodeClient
import org.opensearch.common.Strings
import org.opensearch.common.logging.DeprecationLogger
import org.opensearch.common.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 @@ -54,7 +55,7 @@ class RestRetryFailedManagedIndexAction : BaseRestHandler() {
throw IllegalArgumentException("Missing indices")
}
val body = if (request.hasContent()) {
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType).v2()
XContentHelper.convertToMap(request.requiredContent(), false, request.xContentType as (MediaType)).v2()
} else {
mapOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.opensearch.common.settings.Settings
import org.opensearch.common.unit.TimeValue
import org.opensearch.common.util.concurrent.ThreadContext
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.MediaType
import org.opensearch.common.xcontent.NamedXContentRegistry
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -66,14 +67,16 @@ const val OPENDISTRO_SECURITY_PROTECTED_INDICES_CONF_REQUEST = "_opendistro_secu
fun contentParser(bytesReference: BytesReference): XContentParser {
return XContentHelper.createParser(
NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON
LoggingDeprecationHandler.INSTANCE,
bytesReference,
XContentType.JSON
)
}

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

fun XContentParser.instant(): Instant? {
Expand Down Expand Up @@ -197,7 +200,7 @@ fun OpenSearchException.isRetryable(): Boolean {
*/
fun XContentBuilder.string(): String = BytesReference.bytes(this).utf8ToString()

fun XContentBuilder.toMap(): Map<String, Any> = XContentHelper.convertToMap(BytesReference.bytes(this), false, XContentType.JSON).v2()
fun XContentBuilder.toMap(): Map<String, Any> = XContentHelper.convertToMap(BytesReference.bytes(this), false, XContentType.JSON as (MediaType)).v2()

/**
* Converts [OpenSearchClient] methods that take a callback into a kotlin suspending function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.opensearch.common.bytes.BytesReference
import org.opensearch.common.inject.Inject
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.Writeable
import org.opensearch.common.xcontent.MediaType
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentHelper
import org.opensearch.common.xcontent.XContentType
Expand Down Expand Up @@ -81,7 +82,7 @@ class TransportUpdateRollupMappingAction @Inject constructor(
val rollup = XContentHelper.convertToMap(
BytesReference.bytes(request.rollup.toXContent(XContentFactory.jsonBuilder(), XCONTENT_WITHOUT_TYPE)),
false,
XContentType.JSON
XContentType.JSON as (MediaType)
).v2()
val metaMappings = mutableMapOf<String, Any>()
// TODO: Clean this up
Expand Down
16 changes: 12 additions & 4 deletions src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ package org.opensearch.indexmanagement
import org.apache.hc.core5.http.HttpHost
import org.opensearch.client.RestClient
import org.opensearch.common.io.PathUtils
import org.opensearch.common.settings.MockSecureSettings
import org.opensearch.common.settings.SecureSettings
import org.opensearch.common.settings.Settings
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD_SETTING
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD_SETTING
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH
import org.opensearch.commons.rest.SecureRestClientBuilder
import org.opensearch.test.rest.OpenSearchRestTestCase
Expand All @@ -29,15 +31,21 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
/**
* Returns the REST client settings used for super-admin actions like cleaning up after the test has completed.
*/
protected open fun createSecureSettings(): SecureSettings? {
val mockSecureSettings = MockSecureSettings()
mockSecureSettings.setString(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD_SETTING.key, "changeit")
mockSecureSettings.setString(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD_SETTING.key, "changeit")
return mockSecureSettings
}

override fun restAdminSettings(): Settings {
return Settings
.builder()
.put("http.port", 9200)
.put(OPENSEARCH_SECURITY_SSL_HTTP_ENABLED, isHttps())
.put(OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH, "sample.pem")
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH, "test-kirk.jks")
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD, "changeit")
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD, "changeit")
.setSecureSettings(createSecureSettings())
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class RestStopRollupActionIT : RollupRestTestCase() {
roles = emptyList(),
pageSize = 10,
delay = 0,
continuous = false,
continuous = true,
dimensions = listOf(
DateHistogram(sourceField = "tpep_pickup_datetime", fixedInterval = "1h"),
Terms("RatecodeID", "RatecodeID"),
Expand Down

0 comments on commit 289ab3b

Please sign in to comment.