From abdf77bfa5cdbad0daf8e2a3bbfc90a7835d5221 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Thu, 22 Aug 2024 16:16:44 -0400 Subject: [PATCH] [Backport 2.x] Use adminClient instead of client when interacting with system index in integTests (#1222) (#1223) * Use adminClient instead of client when interacting with system index in integTests (#1222) (cherry picked from commit b7ddbb693128e5de31482a0d2bc8c16eef710662) * Switch to APPLICATION_JSON Signed-off-by: Craig Perkins --------- Signed-off-by: Craig Perkins --- .../IndexManagementIndicesIT.kt | 2 +- .../IndexManagementRestTestCase.kt | 34 ++++++++++--------- .../indexmanagement/SecurityRestTestCase.kt | 2 +- .../filter/NotificationActionListenerIT.kt | 2 +- .../resthandler/LRONConfigRestTestCase.kt | 2 +- .../RestIndexLRONConfigActionIT.kt | 2 +- .../IndexStateManagementRestTestCase.kt | 17 +++++----- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt index 1816f6644..955b1667b 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementIndicesIT.kt @@ -132,7 +132,7 @@ class IndexManagementIndicesIT : IndexStateManagementRestTestCase() { .replace("\"schema_version\": $configSchemaVersion", "\"schema_version\": 0") val entity = StringEntity(mapping, ContentType.APPLICATION_JSON) - client().makeRequest( + adminClient().makeRequest( RestRequest.Method.PUT.toString(), "/$INDEX_MANAGEMENT_INDEX/_mapping", emptyMap(), entity, ) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt index 1d1aeb6fd..1dca29ac9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt @@ -219,14 +219,15 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { // During this period, this update got missed // Since from the log, this happens very fast (within 0.1~0.2s), the above cluster explain may not have the granularity to catch this. logger.info("Update rollup start time to $startTimeMillis") - val response = client().makeRequest( - "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}?wait_for_active_shards=$waitForActiveShards&refresh=true", - StringEntity( - "{\"doc\":{\"rollup\":{\"schedule\":{\"interval\":{\"start_time\":" + - "\"$startTimeMillis\"}}}}}", - ContentType.APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}?wait_for_active_shards=$waitForActiveShards&refresh=true", + StringEntity( + "{\"doc\":{\"rollup\":{\"schedule\":{\"interval\":{\"start_time\":" + + "\"$startTimeMillis\"}}}}}", + ContentType.APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -248,14 +249,15 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { val millis = Duration.of(intervalSchedule.interval.toLong(), intervalSchedule.unit).minusSeconds(2).toMillis() val startTimeMillis = desiredStartTimeMillis ?: (Instant.now().toEpochMilli() - millis) val waitForActiveShards = if (isMultiNode) "all" else "1" - val response = client().makeRequest( - "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}?wait_for_active_shards=$waitForActiveShards", - StringEntity( - "{\"doc\":{\"transform\":{\"schedule\":{\"interval\":{\"start_time\":" + - "\"$startTimeMillis\"}}}}}", - ContentType.APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_update/${update.id}?wait_for_active_shards=$waitForActiveShards", + StringEntity( + "{\"doc\":{\"transform\":{\"schedule\":{\"interval\":{\"start_time\":" + + "\"$startTimeMillis\"}}}}}", + ContentType.APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt index af56b400e..502780f71 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt @@ -486,7 +486,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { } protected fun deleteIndexByName(index: String) { - executeRequest(request = Request(RestRequest.Method.DELETE.name, "/$index"), client = client()) + executeRequest(request = Request(RestRequest.Method.DELETE.name, "/$index"), client = adminClient()) } protected fun validateSourceIndex(indexName: String) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt index 83ab81bb4..c99a09088 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/filter/NotificationActionListenerIT.kt @@ -393,7 +393,7 @@ class NotificationActionListenerIT : IndexManagementRestTestCase() { closeIndex("source-index") // delete system index - client.makeRequest("DELETE", IndexManagementPlugin.CONTROL_CENTER_INDEX) + adminClient().makeRequest("DELETE", IndexManagementPlugin.CONTROL_CENTER_INDEX) val response = client.makeRequest( "POST", "source-index/_open", diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt index 731d61ac7..0e2860030 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/LRONConfigRestTestCase.kt @@ -31,7 +31,7 @@ abstract class LRONConfigRestTestCase : IndexManagementRestTestCase() { @After fun removeAllDocs() { try { - client().makeRequest( + adminClient().makeRequest( "POST", "${IndexManagementPlugin.CONTROL_CENTER_INDEX}/_delete_by_query", mapOf("refresh" to "true"), diff --git a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt index 471216c47..36635803e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/controlcenter/notification/resthandler/RestIndexLRONConfigActionIT.kt @@ -178,7 +178,7 @@ class RestIndexLRONConfigActionIT : LRONConfigRestTestCase() { val lronConfig = randomLRONConfig(taskId = randomTaskId(nodeId = nodeIdsInRestIT.random())) createLRONConfig(lronConfig) - val response = client().makeRequest("GET", "/${IndexManagementPlugin.CONTROL_CENTER_INDEX}/_mapping") + val response = adminClient().makeRequest("GET", "/${IndexManagementPlugin.CONTROL_CENTER_INDEX}/_mapping") val parserMap = createParser(XContentType.JSON.xContent(), response.entity.content).map() as Map> val mappingsMap = parserMap[IndexManagementPlugin.CONTROL_CENTER_INDEX]!!["mappings"] as Map val expected = createParser( diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt index ac53cfbf3..e56e0ea9d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt @@ -451,14 +451,15 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() val startTimeMillis = desiredStartTimeMillis ?: Instant.now().toEpochMilli() - millis val waitForActiveShards = if (isMultiNode) "all" else "1" val endpoint = "$INDEX_MANAGEMENT_INDEX/_update/${update.id}?wait_for_active_shards=$waitForActiveShards;retry_on_conflict=$retryOnConflict" - val response = client().makeRequest( - "POST", endpoint, - StringEntity( - "{\"doc\":{\"managed_index\":{\"schedule\":{\"interval\":{\"start_time\":" + - "\"$startTimeMillis\"}}}}}", - APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", endpoint, + StringEntity( + "{\"doc\":{\"managed_index\":{\"schedule\":{\"interval\":{\"start_time\":" + + "\"$startTimeMillis\"}}}}}", + APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) }