Skip to content

Commit

Permalink
Fix bwc test failure of throwing direct access to system index when g…
Browse files Browse the repository at this point in the history
…etting mapping

Signed-off-by: gaobinlong <[email protected]>
  • Loading branch information
gaobinlong committed Oct 11, 2023
1 parent 6c15468 commit 415148a
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,29 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() {
}

protected fun getCurrentMappingsSchemaVersion(): Int {
val indexName = ".opensearch-notifications-config"
val getMappingRequest = Request(RestRequest.Method.GET.name, "$indexName/_mappings")
val getMappingRequest = Request(RestRequest.Method.GET.name, "${NotificationConfigIndex.INDEX_NAME}/_mappings")
val requestOptions = RequestOptions.DEFAULT.toBuilder()
// Allow direct access to system index warning
requestOptions.setWarningsHandler { warnings: List<String> ->
if (warnings.isEmpty()) {
return@setWarningsHandler false
} else if (warnings.size > 1) {
return@setWarningsHandler true
} else {
return@setWarningsHandler !warnings[0].startsWith("this request accesses system indices:")
}
}
getMappingRequest.setOptions(requestOptions)
val response = executeRequest(getMappingRequest, RestStatus.OK.status, client())
val mappingsObject = response.get(indexName).asJsonObject.get("mappings").asJsonObject
val mappingsObject = response.get(NotificationConfigIndex.INDEX_NAME).asJsonObject.get("mappings").asJsonObject
return mappingsObject.get(NotificationConfigIndex._META)?.asJsonObject?.get(NotificationConfigIndex.SCHEMA_VERSION)?.asInt
?: NotificationConfigIndex.DEFAULT_SCHEMA_VERSION
}

// only refresh the notification config index to avoid too many warnings
@Throws(IOException::class)
override fun refreshAllIndices() {
val refreshRequest = Request("POST", NotificationConfigIndex.INDEX_NAME + "/_refresh")
val refreshRequest = Request("POST", "${NotificationConfigIndex.INDEX_NAME}/_refresh")
val requestOptions = RequestOptions.DEFAULT.toBuilder()
// Allow direct access to system index warning
requestOptions.setWarningsHandler { warnings: List<String> ->
Expand Down

0 comments on commit 415148a

Please sign in to comment.