diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 596024a1f..cd9176ea7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @bowenlan-amzn @getsaurabh02 @lezzago @praveensameneni @xluo-aws @gaobinlong @Hailong-am @amsiglan @sbcd90 @eirsep @AWSHurneyt +* @bowenlan-amzn @Hailong-am @vikasvb90 diff --git a/.github/workflows/bwc-test-workflow.yml b/.github/workflows/bwc-test-workflow.yml index 692880cdd..dc905d65d 100644 --- a/.github/workflows/bwc-test-workflow.yml +++ b/.github/workflows/bwc-test-workflow.yml @@ -14,9 +14,10 @@ jobs: steps: # This step uses the setup-java Github action: https://github.com/actions/setup-java - name: Set Up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: - java-version: 17 + distribution: temurin # Temurin is a distribution of adoptium + java-version: 21 # index-management - name: Checkout Branch uses: actions/checkout@v2 @@ -25,8 +26,9 @@ jobs: echo "Running backwards compatibility tests..." ./gradlew bwcTestSuite - name: Upload failed logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: logs + overwrite: 'true' path: build/testclusters/indexmanagementBwcCluster*/logs/* diff --git a/.github/workflows/docker-security-test-workflow.yml b/.github/workflows/docker-security-test-workflow.yml index 496f8f469..de3d83ea9 100644 --- a/.github/workflows/docker-security-test-workflow.yml +++ b/.github/workflows/docker-security-test-workflow.yml @@ -13,9 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Set Up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: - java-version: 17 + distribution: temurin # Temurin is a distribution of adoptium + java-version: 21 - name: Checkout Branch uses: actions/checkout@v2 - name: Build Index Management @@ -83,10 +84,11 @@ jobs: echo "Security plugin is NOT available skipping this run as tests without security have already been run" fi - name: Upload failed logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: logs + overwrite: 'true' path: build/testclusters/integTest-*/logs/* - name: Collect docker logs on failure uses: jwalton/gh-docker-logs@v2 @@ -95,8 +97,9 @@ jobs: - name: Tar logs run: tar cvzf ./logs.tgz ./logs - name: Upload logs to GitHub - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: logs.tgz + overwrite: 'true' path: ./logs.tgz diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 8b7b1164b..5e947b345 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -32,4 +32,5 @@ jobs: export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text) echo "::add-mask::$SONATYPE_USERNAME" echo "::add-mask::$SONATYPE_PASSWORD" - ./gradlew publishPluginZipPublicationToSnapshotsRepository \ No newline at end of file + ./gradlew publishPluginZipPublicationToSnapshotsRepository + ./gradlew publishShadowPublicationToSnapshotsRepository \ No newline at end of file diff --git a/.github/workflows/multi-node-test-workflow.yml b/.github/workflows/multi-node-test-workflow.yml index 73881a6f1..9f97459f9 100644 --- a/.github/workflows/multi-node-test-workflow.yml +++ b/.github/workflows/multi-node-test-workflow.yml @@ -7,6 +7,8 @@ on: push: branches: - "**" +env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true jobs: Get-CI-Image-Tag: @@ -50,8 +52,9 @@ jobs: chown -R 1000:1000 `pwd` su `id -un 1000` -c "./gradlew integTest -PnumNodes=3 ${{ env.TEST_FILTER }}" - name: Upload failed logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: logs + overwrite: 'true' path: build/testclusters/integTest-*/logs/* diff --git a/.github/workflows/security-test-workflow.yml b/.github/workflows/security-test-workflow.yml index 855147d27..8dc6eb19c 100644 --- a/.github/workflows/security-test-workflow.yml +++ b/.github/workflows/security-test-workflow.yml @@ -7,6 +7,8 @@ on: push: branches: - "**" +env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true jobs: Get-CI-Image-Tag: @@ -28,19 +30,21 @@ jobs: steps: # This step uses the setup-java Github action: https://github.com/actions/setup-java - name: Set Up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: - java-version: 17 + distribution: temurin # Temurin is a distribution of adoptium + java-version: 21 # index-management - name: Checkout Branch uses: actions/checkout@v2 - name: Run integration tests run: | chown -R 1000:1000 `pwd` - su `id -un 1000` -c "./gradlew integTest -Dsecurity=true -Dhttps=true --tests '*SecurityBehaviorIT'" + su `id -un 1000` -c "./gradlew integTest -Dsecurity=true -Dhttps=true --tests '*IT'" - name: Upload failed logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: logs + overwrite: 'true' path: build/testclusters/integTest-*/logs/* diff --git a/.github/workflows/test-and-build-workflow.yml b/.github/workflows/test-and-build-workflow.yml index 70f084edd..5eb5a5b29 100644 --- a/.github/workflows/test-and-build-workflow.yml +++ b/.github/workflows/test-and-build-workflow.yml @@ -6,6 +6,8 @@ on: push: branches: - "**" +env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true jobs: Get-CI-Image-Tag: @@ -54,10 +56,10 @@ jobs: chown -R 1000:1000 `pwd` su `id -un 1000` -c "./gradlew build ${{ env.TEST_FILTER }}" - name: Upload failed logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ failure() }} with: - name: logs + name: logs-${{ matrix.java }}-${{ matrix.feature }} path: build/testclusters/integTest-*/logs/* - name: Create Artifact Path run: | @@ -69,10 +71,12 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} # This step uses the upload-artifact Github action: https://github.com/actions/upload-artifact - name: Upload Artifacts - uses: actions/upload-artifact@v1 + # v4 requires node.js 20 which is not supported + uses: actions/upload-artifact@v3 with: - name: index-management-plugin-ubuntu-latest + name: index-management-plugin-ubuntu-latest-${{ matrix.java }} path: index-management-artifacts + overwrite: 'true' test-and-build-windows-macos: env: @@ -124,7 +128,8 @@ jobs: cp ./build/distributions/*.zip index-management-artifacts # This step uses the upload-artifact Github action: https://github.com/actions/upload-artifact - name: Upload Artifacts - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: - name: index-management-plugin-${{ matrix.os }} + name: index-management-plugin-${{ matrix.os }}-${{ matrix.java }} path: index-management-artifacts + overwrite: 'true' diff --git a/MAINTAINERS.md b/MAINTAINERS.md index eb99db5e3..8127dcfa5 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,15 +5,23 @@ This document contains a list of maintainers in this repo. See [opensearch-proje ## Current Maintainers | Maintainer | GitHub ID | Affiliation | -| --------------------- | ----------------------------------------------------- | ----------- | -| Ashish Agrawal | [lezzago](https://github.com/lezzago) | Amazon | +|-----------------------|-------------------------------------------------------| ----------- | +| Vikas Bansal | [vikasvb90](https://github.com/vikasvb90) | Amazon | | Bowen Lan | [bowenlan-amzn](https://github.com/bowenlan-amzn) | Amazon | -| Praveen Sameneni | [praveensameneni](https://github.com/praveensameneni) | Amazon | -| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02/) | Amazon | -| Xuesong Luo | [xluo-aws](https://github.com/xluo-aws) | Amazon | | Hailong Cui | [Hailong-am](https://github.com/Hailong-am) | Amazon | -| Binlong Gao | [gaobinlong](https://github.com/gaobinlong) | Amazon | + +## Emeritus + +| Maintainer | GitHub ID | Affiliation | +|-----------------------|-------------------------------------------------------| ----------- | | Amardeepsingh Siglani | [amsiglan](https://github.com/amsiglan) | Amazon | +| Binlong Gao | [gaobinlong](https://github.com/gaobinlong) | Amazon | +| Ashish Agrawal | [lezzago](https://github.com/lezzago) | Amazon | +| Joanne Wang | [jowg-amazon](https://github.com/jowg-amazon) | Amazon | +| Praveen Sameneni | [praveensameneni](https://github.com/praveensameneni) | Amazon | +| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02/) | Amazon | | Subhobrata Dey | [sbcd90](https://github.com/sbcd90) | Amazon | | Surya Sashank Nistala | [eirsep](https://github.com/eirsep) | Amazon | | Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | Amazon | +| Xuesong Luo | [xluo-aws](https://github.com/xluo-aws) | Amazon | +| Rohit Ashiwal | [r1walz](https://github.com/r1walz) | Independent | diff --git a/build.gradle b/build.gradle index 4b45fb461..68084f884 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit buildscript { ext { isSnapshot = "true" == System.getProperty("build.snapshot", "true") - opensearch_version = System.getProperty("opensearch.version", "2.15.0-SNAPSHOT") + opensearch_version = System.getProperty("opensearch.version", "2.18.0-SNAPSHOT") buildVersionQualifier = System.getProperty("build.version_qualifier", "") // 2.2.0-SNAPSHOT -> 2.2.0.0-SNAPSHOT version_tokens = opensearch_version.tokenize('-') @@ -271,6 +271,8 @@ publishing { } } +tasks.generatePomFileForPluginZipPublication.dependsOn publishNebulaPublicationToMavenLocal + plugins.withId('java') { sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11 } diff --git a/release-notes/opensearch-index-management.release-notes-2.16.0.0.md b/release-notes/opensearch-index-management.release-notes-2.16.0.0.md new file mode 100644 index 000000000..027ad5fb7 --- /dev/null +++ b/release-notes/opensearch-index-management.release-notes-2.16.0.0.md @@ -0,0 +1,8 @@ +## Version 2.16.0.0 2024-07-29 + +Compatible with OpenSearch 2.16.0 + +### Maintenance +* Increment version to 2.16.0-SNAPSHOT ([#1187](https://github.com/opensearch-project/index-management/pull/1187)) +* Add publish in spi build.gradle ([#1207](https://github.com/opensearch-project/index-management/pull/1207)) +* Fix github action ([#1208](https://github.com/opensearch-project/index-management/pull/1208)) diff --git a/release-notes/opensearch-index-management.release-notes-2.17.0.0.md b/release-notes/opensearch-index-management.release-notes-2.17.0.0.md new file mode 100644 index 000000000..e33508f4c --- /dev/null +++ b/release-notes/opensearch-index-management.release-notes-2.17.0.0.md @@ -0,0 +1,11 @@ +## Version 2.17.0.0 2024-09-05 + +Compatible with OpenSearch 2.17.0 + +### Bug fixes +* Skipping execution based on cluster service ([#1219](https://github.com/opensearch-project/index-management/pull/1219)) + +### Maintenance +* Increment version to 2.17.0-SNAPSHOT ([#1221](https://github.com/opensearch-project/index-management/pull/1221)) +* Use adminClient instead of client when interacting with system index in integTests ([#1222](https://github.com/opensearch-project/index-management/pull/1222)) +* Move non-active maintainers to emeritus ([#1233](https://github.com/opensearch-project/index-management/pull/1233)) \ No newline at end of file diff --git a/spi/build.gradle b/spi/build.gradle index 0dc7df633..0a247b359 100644 --- a/spi/build.gradle +++ b/spi/build.gradle @@ -16,6 +16,7 @@ apply plugin: 'kotlin' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.jetbrains.kotlin.plugin.allopen' apply plugin: 'idea' +apply plugin: 'maven-publish' ext { projectSubstitutions = [:] @@ -83,6 +84,11 @@ tasks.register("sourcesJar", Jar) { from sourceSets.main.allSource } +task javadocJar(type: Jar) { + archiveClassifier = 'javadoc' + from javadoc.destinationDir +} + test { doFirst { test.classpath -= project.files(project.tasks.named('shadowJar')) @@ -103,3 +109,55 @@ check.dependsOn integTest testClusters.javaRestTest { testDistribution = 'INTEG_TEST' } + +publishing { + repositories { + maven { + name = 'staging' + url = "${rootProject.buildDir}/local-staging-repo" + } + maven { + name = "Snapshots" + url = "https://aws.oss.sonatype.org/content/repositories/snapshots" + credentials { + username "$System.env.SONATYPE_USERNAME" + password "$System.env.SONATYPE_PASSWORD" + } + } + } + publications { + shadow(MavenPublication) { + project.shadow.component(it) + + artifact sourcesJar + artifact javadocJar + + pom { + name = "OpenSearch Index Management SPI" + packaging = "jar" + url = "https://github.com/opensearch-project/index-management" + description = "OpenSearch Index Management SPI" + scm { + connection = "scm:git@github.com:opensearch-project/index-management.git" + developerConnection = "scm:git@github.com:opensearch-project/index-management.git" + url = "git@github.com:opensearch-project/index-management.git" + } + licenses { + license { + name = "The Apache License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + developers { + developer { + name = "OpenSearch" + url = "https://github.com/opensearch-project/index-management" + } + } + } + } + } + + gradle.startParameter.setShowStacktrace(ShowStacktrace.ALWAYS) + gradle.startParameter.setLogLevel(LogLevel.DEBUG) +} diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index 93e42aa29..d12650c28 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -414,7 +414,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin fieldCapsFilter = FieldCapsFilter(clusterService, settings, indexNameExpressionResolver) this.indexNameExpressionResolver = indexNameExpressionResolver - val skipFlag = SkipExecution(client) + val skipFlag = SkipExecution() RollupFieldValueExpressionResolver.registerServices(scriptService, clusterService) val rollupRunner = RollupRunner .registerClient(client) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/PluginVersionSweepCoordinator.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/PluginVersionSweepCoordinator.kt index ccf341fe4..06b90033d 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/PluginVersionSweepCoordinator.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/PluginVersionSweepCoordinator.kt @@ -25,7 +25,7 @@ class PluginVersionSweepCoordinator( private val skipExecution: SkipExecution, settings: Settings, private val threadPool: ThreadPool, - clusterService: ClusterService, + var clusterService: ClusterService, ) : CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default + CoroutineName("ISMPluginSweepCoordinator")), LifecycleListener(), ClusterStateListener { @@ -58,7 +58,7 @@ class PluginVersionSweepCoordinator( override fun clusterChanged(event: ClusterChangedEvent) { if (event.nodesChanged() || event.isNewCluster) { - skipExecution.sweepISMPluginVersion() + skipExecution.sweepISMPluginVersion(clusterService) initBackgroundSweepISMPluginVersionExecution() } } @@ -76,7 +76,7 @@ class PluginVersionSweepCoordinator( logger.info("Canceling sweep ism plugin version job") scheduledSkipExecution?.cancel() } else { - skipExecution.sweepISMPluginVersion() + skipExecution.sweepISMPluginVersion(clusterService) } } catch (e: Exception) { logger.error("Failed to sweep ism plugin version", e) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt index c74f27c89..1d0d6c841 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/SkipExecution.kt @@ -6,20 +6,14 @@ package org.opensearch.indexmanagement.indexstatemanagement import org.apache.logging.log4j.LogManager -import org.opensearch.action.admin.cluster.node.info.NodesInfoAction -import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest -import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse -import org.opensearch.action.admin.cluster.node.info.PluginsAndModules -import org.opensearch.client.Client -import org.opensearch.core.action.ActionListener +import org.opensearch.Version +import org.opensearch.cluster.service.ClusterService import org.opensearch.indexmanagement.util.OpenForTesting // TODO this can be moved to job scheduler, so that all extended plugin // can avoid running jobs in an upgrading cluster @OpenForTesting -class SkipExecution( - private val client: Client, -) { +class SkipExecution { private val logger = LogManager.getLogger(javaClass) @Volatile @@ -31,53 +25,27 @@ class SkipExecution( final var hasLegacyPlugin: Boolean = false private set - fun sweepISMPluginVersion() { - // if old version ISM plugin exists (2 versions ISM in one cluster), set skip flag to true - val request = NodesInfoRequest().clear().addMetric("plugins") - client.execute( - NodesInfoAction.INSTANCE, request, - object : ActionListener { - override fun onResponse(response: NodesInfoResponse) { - val versionSet = mutableSetOf() - val legacyVersionSet = mutableSetOf() - - response.nodes.map { it.getInfo(PluginsAndModules::class.java).pluginInfos } - .forEach { - it.forEach { nodePlugin -> - if (nodePlugin.name == "opensearch-index-management" || - nodePlugin.name == "opensearch_index_management" - ) { - versionSet.add(nodePlugin.version) - } - - if (nodePlugin.name == "opendistro-index-management" || - nodePlugin.name == "opendistro_index_management" - ) { - legacyVersionSet.add(nodePlugin.version) - } - } - } - - if ((versionSet.size + legacyVersionSet.size) > 1) { - flag = true - logger.info("There are multiple versions of Index Management plugins in the cluster: [$versionSet, $legacyVersionSet]") - } else { - flag = false - } - - if (versionSet.isNotEmpty() && legacyVersionSet.isNotEmpty()) { - hasLegacyPlugin = true - logger.info("Found legacy plugin versions [$legacyVersionSet] and opensearch plugins versions [$versionSet] in the cluster") - } else { - hasLegacyPlugin = false - } - } - - override fun onFailure(e: Exception) { - logger.error("Failed sweeping nodes for ISM plugin versions: $e") - flag = false - } - }, - ) + fun sweepISMPluginVersion(clusterService: ClusterService) { + try { + // if old version ISM plugin exists (2 versions ISM in one cluster), set skip flag to true + val currentMinVersion = clusterService.state().nodes.minNodeVersion + val currentMaxVersion = clusterService.state().nodes.maxNodeVersion + + if (currentMinVersion != null && !currentMinVersion.equals(currentMaxVersion)) { + flag = true + logger.info("There are multiple versions of Index Management plugins in the cluster: [$currentMaxVersion, $currentMinVersion]") + } else { + flag = false + } + + if (currentMinVersion.major > Version.CURRENT.major && currentMinVersion != currentMaxVersion) { + hasLegacyPlugin = true + logger.info("Found legacy plugin versions [$currentMinVersion] and opensearch plugins versions [$currentMaxVersion] in the cluster") + } else { + hasLegacyPlugin = false + } + } catch (e: Exception) { + logger.error("Unable to fetch node versions from cluster service", e) + } } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt index d71de58a6..ef745d412 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt @@ -7,20 +7,19 @@ package org.opensearch.indexmanagement.indexstatemanagement.step.snapshot import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper -import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus -import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest -import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse -import org.opensearch.cluster.SnapshotsInProgress.State +import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest +import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData +import org.opensearch.snapshots.SnapshotInfo +import org.opensearch.snapshots.SnapshotState import org.opensearch.transport.RemoteTransportException class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { - private val logger = LogManager.getLogger(javaClass) private var stepStatus = StepStatus.STARTING private var info: Map? = null @@ -34,30 +33,31 @@ class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { try { val snapshotName = getSnapshotName(managedIndexMetadata, indexName) ?: return this - val request = SnapshotsStatusRequest() + val newRequest = GetSnapshotsRequest() .snapshots(arrayOf(snapshotName)) .repository(repository) - val response: SnapshotsStatusResponse = context.client.admin().cluster().suspendUntil { snapshotsStatus(request, it) } - val status: SnapshotStatus? = response - .snapshots - .find { snapshotStatus -> - snapshotStatus.snapshot.snapshotId.name == snapshotName && snapshotStatus.snapshot.repository == repository - } + val response: GetSnapshotsResponse = context.client.admin().cluster().suspendUntil { getSnapshots(newRequest, it) } + val status: SnapshotInfo? = + response + .snapshots + .find { snapshotInfo -> + snapshotInfo.snapshotId().name == snapshotName + } if (status != null) { - when (status.state) { - State.INIT, State.STARTED -> { + when (status.state()) { + SnapshotState.IN_PROGRESS -> { stepStatus = StepStatus.CONDITION_NOT_MET - info = mapOf("message" to getSnapshotInProgressMessage(indexName), "state" to status.state.name) + info = mapOf("message" to getSnapshotInProgressMessage(indexName), "state" to status.state().toString()) } - State.SUCCESS -> { + SnapshotState.SUCCESS -> { stepStatus = StepStatus.COMPLETED - info = mapOf("message" to getSuccessMessage(indexName), "state" to status.state.name) + info = mapOf("message" to getSuccessMessage(indexName), "state" to status.state().toString()) } else -> { // State.FAILED, State.ABORTED val message = getFailedExistsMessage(indexName) logger.warn(message) stepStatus = StepStatus.FAILED - info = mapOf("message" to message, "state" to status.state.name) + info = mapOf("message" to message, "state" to status.state().toString()) } } } else { @@ -97,23 +97,26 @@ class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { return actionProperties.snapshotName } - override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData { - return currentMetadata.copy( - stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), - transitionTo = null, - info = info, - ) - } + override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData = currentMetadata.copy( + stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus), + transitionTo = null, + info = info, + ) override fun isIdempotent(): Boolean = true companion object { const val name = "wait_for_snapshot" + fun getFailedMessage(index: String) = "Failed to get status of snapshot [index=$index]" + fun getFailedExistsMessage(index: String) = "Snapshot doesn't exist [index=$index]" + fun getFailedActionPropertiesMessage(index: String, actionProperties: ActionProperties?) = "Unable to retrieve [${ActionProperties.Properties.SNAPSHOT_NAME.key}] from ActionProperties=$actionProperties [index=$index]" + fun getSuccessMessage(index: String) = "Successfully created snapshot [index=$index]" + fun getSnapshotInProgressMessage(index: String) = "Snapshot currently in progress [index=$index]" } } 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..829a5678c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt @@ -339,10 +339,11 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() "$key" : "$value" } """.trimIndent() - val res = client().makeRequest( - "PUT", "$index/_settings", emptyMap(), - StringEntity(body, APPLICATION_JSON), - ) + val res = + adminClient().makeRequest( + "PUT", "$index/_settings", emptyMap(), + StringEntity(body, APPLICATION_JSON), + ) assertEquals("Update index setting failed", RestStatus.OK, res.restStatus()) } @@ -451,26 +452,28 @@ 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()) } protected fun updateManagedIndexConfigPolicySeqNo(update: ManagedIndexConfig) { - val response = client().makeRequest( - "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}", - StringEntity( - "{\"doc\":{\"managed_index\":{\"policy_seq_no\":\"${update.policySeqNo}\"}}}", - APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}", + StringEntity( + "{\"doc\":{\"managed_index\":{\"policy_seq_no\":\"${update.policySeqNo}\"}}}", + APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt index 940ab1192..bb1214841 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/MetadataServiceTests.kt @@ -53,7 +53,7 @@ class MetadataServiceTests : OpenSearchTestCase() { ), ), ) - val skipFlag = SkipExecution(client) + val skipFlag = SkipExecution() val metadataService = MetadataService(client, clusterService, skipFlag, imIndices) metadataService.moveMetadata() @@ -74,7 +74,7 @@ class MetadataServiceTests : OpenSearchTestCase() { ), ) - val skipFlag = SkipExecution(client) + val skipFlag = SkipExecution() val metadataService = MetadataService(client, clusterService, skipFlag, imIndices) metadataService.moveMetadata() assertEquals(metadataService.runTimeCounter, 2) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt index a48510298..cfd2209b9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt @@ -770,21 +770,22 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { assertEquals("Index did not rollover.", AttemptRolloverStep.getSuccessMessage(firstIndex), info["message"]) } // Manually produce transaction failure - val response = client().makeRequest( - "POST", "$INDEX_MANAGEMENT_INDEX/_update/${managedIndexConfig.id}%23metadata", - StringEntity( - "{\n" + - " \"script\": {\n" + - " \"source\": \"ctx._source.managed_index_metadata.step.step_status = params.step_status\",\n" + - " \"lang\": \"painless\",\n" + - " \"params\": {\n" + - " \"step_status\": \"starting\"\n" + - " }\n" + - " }\n" + - "}", - ContentType.APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", "$INDEX_MANAGEMENT_INDEX/_update/${managedIndexConfig.id}%23metadata", + StringEntity( + "{\n" + + " \"script\": {\n" + + " \"source\": \"ctx._source.managed_index_metadata.step.step_status = params.step_status\",\n" + + " \"lang\": \"painless\",\n" + + " \"params\": {\n" + + " \"step_status\": \"starting\"\n" + + " }\n" + + " }\n" + + "}", + ContentType.APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) // Execute again to see the transaction failure diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/SkipExecutionTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/SkipExecutionTests.kt index 8f3ea4f71..e1937be19 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/SkipExecutionTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/coordinator/SkipExecutionTests.kt @@ -5,30 +5,89 @@ package org.opensearch.indexmanagement.indexstatemanagement.coordinator +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.whenever import org.junit.Before -import org.mockito.Mockito -import org.opensearch.action.admin.cluster.node.info.NodesInfoAction -import org.opensearch.client.Client -import org.opensearch.cluster.ClusterChangedEvent -import org.opensearch.cluster.OpenSearchAllocationTestCase +import org.opensearch.Version +import org.opensearch.cluster.ClusterState +import org.opensearch.cluster.node.DiscoveryNode +import org.opensearch.cluster.node.DiscoveryNodes +import org.opensearch.cluster.service.ClusterService +import org.opensearch.core.common.transport.TransportAddress import org.opensearch.indexmanagement.indexstatemanagement.SkipExecution +import org.opensearch.test.OpenSearchTestCase -class SkipExecutionTests : OpenSearchAllocationTestCase() { +class SkipExecutionTests : OpenSearchTestCase() { + private var clusterService: ClusterService = mock() - private lateinit var client: Client + private lateinit var clusterState: ClusterState private lateinit var skip: SkipExecution @Before - @Throws(Exception::class) fun setup() { - client = Mockito.mock(Client::class.java) - skip = SkipExecution(client) + skip = SkipExecution() } - fun `test cluster change event`() { - val event = Mockito.mock(ClusterChangedEvent::class.java) - Mockito.`when`(event.nodesChanged()).thenReturn(true) - skip.sweepISMPluginVersion() - Mockito.verify(client).execute(Mockito.eq(NodesInfoAction.INSTANCE), Mockito.any(), Mockito.any()) + fun `test sweepISMPluginVersion should set flag to false and hasLegacyPlugin to false when all nodes have the same version`() { + val version = Version.CURRENT + val node1 = DiscoveryNode("node1", TransportAddress(TransportAddress.META_ADDRESS, 9300), version) + val node2 = DiscoveryNode("node2", TransportAddress(TransportAddress.META_ADDRESS, 9301), version) + val discoveryNodes = DiscoveryNodes.builder().add(node1).add(node2).build() + clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoveryNodes).build() + whenever(clusterService.state()).thenReturn(clusterState) + + skip.sweepISMPluginVersion(clusterService) + + assertFalse(skip.flag) + assertFalse(skip.hasLegacyPlugin) + } + + fun `test sweepISMPluginVersion should set flag to true and hasLegacyPlugin to false when all nodes have the different versions`() { + val version1 = Version.CURRENT + val version2 = Version.V_2_0_0 + val node1 = DiscoveryNode("node1", TransportAddress(TransportAddress.META_ADDRESS, 9300), version1) + val node2 = DiscoveryNode("node2", TransportAddress(TransportAddress.META_ADDRESS, 9301), version2) + val node3 = DiscoveryNode("node3", TransportAddress(TransportAddress.META_ADDRESS, 9302), version2) + val discoveryNodes = DiscoveryNodes.builder().add(node1).add(node2).add(node3).build() + clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoveryNodes).build() + whenever(clusterService.state()).thenReturn(clusterState) + + skip.sweepISMPluginVersion(clusterService) + + assertTrue(skip.flag) + assertFalse(skip.hasLegacyPlugin) + } + + fun `test sweepISMPluginVersion should set flag to true and hasLegacyPlugin to true when there are different versions including current version`() { + val minVersion = Version.fromString("7.10.0") + val maxVersion = Version.CURRENT + val node1 = DiscoveryNode("node1", TransportAddress(TransportAddress.META_ADDRESS, 9300), minVersion) + val node2 = DiscoveryNode("node2", TransportAddress(TransportAddress.META_ADDRESS, 9301), maxVersion) + val node3 = DiscoveryNode("node3", TransportAddress(TransportAddress.META_ADDRESS, 9302), maxVersion) + val discoveryNodes = DiscoveryNodes.builder().add(node1).add(node2).add(node3).build() + clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoveryNodes).build() + whenever(clusterService.state()).thenReturn(clusterState) + + skip.sweepISMPluginVersion(clusterService) + + assertTrue(skip.flag) + assertTrue(skip.hasLegacyPlugin) + } + + fun `test sweepISMPluginVersion should set flag to true and hasLegacyPlugin to true with different versions`() { + val minVersion = Version.fromString("7.10.0") + val maxVersion = Version.V_2_0_0 + val node1 = DiscoveryNode("node1", TransportAddress(TransportAddress.META_ADDRESS, 9300), minVersion) + val node2 = DiscoveryNode("node2", TransportAddress(TransportAddress.META_ADDRESS, 9301), maxVersion) + val node3 = DiscoveryNode("node3", TransportAddress(TransportAddress.META_ADDRESS, 9302), maxVersion) + + val discoveryNodes = DiscoveryNodes.builder().add(node1).add(node2).add(node3).build() + clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoveryNodes).build() + whenever(clusterService.state()).thenReturn(clusterState) + + skip.sweepISMPluginVersion(clusterService) + + assertTrue(skip.flag) + assertTrue(skip.hasLegacyPlugin) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt index c7cafb343..ccbaf5c29 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestChangePolicyActionIT.kt @@ -6,6 +6,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.junit.Before +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings import org.opensearch.core.rest.RestStatus @@ -87,7 +88,10 @@ class RestChangePolicyActionIT : IndexStateManagementRestTestCase() { } fun `test nonexistent ism config index`() { - if (indexExists(INDEX_MANAGEMENT_INDEX)) deleteIndex(INDEX_MANAGEMENT_INDEX) + if (indexExists(INDEX_MANAGEMENT_INDEX)) { + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) + } try { val changePolicy = ChangePolicy("some_id", null, emptyList(), false) client().makeRequest( diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt index 416512c7a..faed2f2f1 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt @@ -11,17 +11,17 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus -import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse +import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client import org.opensearch.client.ClusterAdminClient -import org.opensearch.cluster.SnapshotsInProgress import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.WaitForSnapshotStep +import org.opensearch.indexmanagement.snapshotmanagement.mockInProgressSnapshotInfo +import org.opensearch.indexmanagement.snapshotmanagement.mockSnapshotInfo import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties @@ -29,13 +29,12 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService -import org.opensearch.snapshots.Snapshot -import org.opensearch.snapshots.SnapshotId +import org.opensearch.snapshots.SnapshotInfo +import org.opensearch.snapshots.SnapshotState import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException class WaitForSnapshotStepTests : OpenSearchTestCase() { - private val clusterService: ClusterService = mock() private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY @@ -71,13 +70,10 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { } fun `test snapshot status states`() { - val snapshotStatus: SnapshotStatus = mock() - val response: SnapshotsStatusResponse = mock() - whenever(response.snapshots).doReturn(listOf(snapshotStatus)) - whenever(snapshotStatus.snapshot).doReturn(Snapshot("repo", SnapshotId("snapshot-name", "some_uuid"))) + val snapshotInfo: SnapshotInfo = mockInProgressSnapshotInfo(snapshot) + val response: GetSnapshotsResponse = mock() + whenever(response.snapshots).doReturn(listOf(snapshotInfo)) val client = getClient(getAdminClient(getClusterAdminClient(response, null))) - - whenever(snapshotStatus.state).doReturn(SnapshotsInProgress.State.INIT) runBlocking { val snapshotAction = SnapshotAction("repo", snapshot, 0) val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) @@ -89,7 +85,8 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { assertEquals("Did not get snapshot in progress message", WaitForSnapshotStep.getSnapshotInProgressMessage("test"), updatedManagedIndexMetaData.info!!["message"]) } - whenever(snapshotStatus.state).doReturn(SnapshotsInProgress.State.STARTED) + val snapshotInfo2: SnapshotInfo = mockSnapshotInfo(snapshot, SnapshotState.SUCCESS) + whenever(response.snapshots).doReturn(listOf(snapshotInfo2)) runBlocking { val snapshotAction = SnapshotAction("repo", snapshot, 0) val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) @@ -97,11 +94,12 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) - assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) - assertEquals("Did not get snapshot in progress message", WaitForSnapshotStep.getSnapshotInProgressMessage("test"), updatedManagedIndexMetaData.info!!["message"]) + assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + assertEquals("Did not get snapshot completed message", WaitForSnapshotStep.getSuccessMessage("test"), updatedManagedIndexMetaData.info!!["message"]) } - whenever(snapshotStatus.state).doReturn(SnapshotsInProgress.State.SUCCESS) + val snapshotInfo3: SnapshotInfo = mockSnapshotInfo(snapshot, SnapshotState.FAILED) + whenever(response.snapshots).doReturn(listOf(snapshotInfo3)) runBlocking { val snapshotAction = SnapshotAction("repo", snapshot, 0) val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) @@ -109,11 +107,12 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) - assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) - assertEquals("Did not get snapshot completed message", WaitForSnapshotStep.getSuccessMessage("test"), updatedManagedIndexMetaData.info!!["message"]) + assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + assertEquals("Did not get snapshot failed message", WaitForSnapshotStep.getFailedExistsMessage("test"), updatedManagedIndexMetaData.info!!["message"]) } - whenever(snapshotStatus.state).doReturn(SnapshotsInProgress.State.ABORTED) + val snapshotInfo4: SnapshotInfo = mockSnapshotInfo(snapshot, SnapshotState.PARTIAL) + whenever(response.snapshots).doReturn(listOf(snapshotInfo4)) runBlocking { val snapshotAction = SnapshotAction("repo", snapshot, 0) val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) @@ -125,7 +124,8 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { assertEquals("Did not get snapshot failed message", WaitForSnapshotStep.getFailedExistsMessage("test"), updatedManagedIndexMetaData.info!!["message"]) } - whenever(snapshotStatus.state).doReturn(SnapshotsInProgress.State.FAILED) + val snapshotInfo5: SnapshotInfo = mockSnapshotInfo(snapshot, SnapshotState.INCOMPATIBLE) + whenever(response.snapshots).doReturn(listOf(snapshotInfo5)) runBlocking { val snapshotAction = SnapshotAction("repo", snapshot, 0) val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) @@ -139,10 +139,9 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { } fun `test snapshot not in response list`() { - val snapshotStatus: SnapshotStatus = mock() - val response: SnapshotsStatusResponse = mock() - whenever(response.snapshots).doReturn(listOf(snapshotStatus)) - whenever(snapshotStatus.snapshot).doReturn(Snapshot("repo", SnapshotId("snapshot-different-name", "some_uuid"))) + val snapshotInfo: SnapshotInfo = mockSnapshotInfo("snapshot-different-name") + val response: GetSnapshotsResponse = mock() + whenever(response.snapshots).doReturn(listOf(snapshotInfo)) val client = getClient(getAdminClient(getClusterAdminClient(response, null))) runBlocking { @@ -188,18 +187,20 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { } private fun getClient(adminClient: AdminClient): Client = mock { on { admin() } doReturn adminClient } + private fun getAdminClient(clusterAdminClient: ClusterAdminClient): AdminClient = mock { on { cluster() } doReturn clusterAdminClient } - private fun getClusterAdminClient(snapshotsStatusResponse: SnapshotsStatusResponse?, exception: Exception?): ClusterAdminClient { - assertTrue("Must provide one and only one response or exception", (snapshotsStatusResponse != null).xor(exception != null)) + + private fun getClusterAdminClient(getSnapshotsResponse: GetSnapshotsResponse?, exception: Exception?): ClusterAdminClient { + assertTrue("Must provide one and only one response or exception", (getSnapshotsResponse != null).xor(exception != null)) return mock { doAnswer { invocationOnMock -> - val listener = invocationOnMock.getArgument>(1) - if (snapshotsStatusResponse != null) { - listener.onResponse(snapshotsStatusResponse) + val listener = invocationOnMock.getArgument>(1) + if (getSnapshotsResponse != null) { + listener.onResponse(getSnapshotsResponse) } else { listener.onFailure(exception) } - }.whenever(this.mock).snapshotsStatus(any(), any()) + }.whenever(this.mock).getSnapshots(any(), any()) } } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt index e0b87a1cb..45e739eda 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt @@ -5,11 +5,13 @@ package org.opensearch.indexmanagement.rollup.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN @@ -199,7 +201,8 @@ class RestStartRollupActionIT : RollupRestAPITestCase() { fun `test start rollup when multiple shards configured for IM config index`() { // setup ism-config index with multiple primary shards - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) val mapping = IndexManagementIndices.indexManagementMappings.trim().trimStart('{').trimEnd('}') val settings = Settings.builder() .put(INDEX_HIDDEN, true) @@ -250,7 +253,7 @@ class RestStartRollupActionIT : RollupRestAPITestCase() { // clearing the config index to prevent other tests using this multi shard index Thread.sleep(2000L) - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + adminClient().performRequest(deleteISMIndexRequest) Thread.sleep(2000L) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt index a49d5933c..4b7608d35 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt @@ -5,11 +5,13 @@ package org.opensearch.indexmanagement.rollup.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementIndices import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.common.model.dimension.Terms @@ -252,7 +254,8 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { fun `test stop rollup when multiple shards configured for IM config index`() { // setup ism-config index with multiple primary shards - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) val mapping = IndexManagementIndices.indexManagementMappings.trim().trimStart('{').trimEnd('}') val settings = Settings.builder() .put(INDEX_HIDDEN, true) @@ -306,7 +309,7 @@ class RestStopRollupActionIT : RollupRestAPITestCase() { // clearing the config index to prevent other tests using this multi shard index Thread.sleep(2000L) - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + adminClient().performRequest(deleteISMIndexRequest) Thread.sleep(2000L) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt index f4b2bf8a1..61b75b8be 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt @@ -1394,7 +1394,7 @@ class RollupRunnerIT : RollupRestTestCase() { // - Source index with pattern mapping to some closed indices private fun deleteRollupMetadata(metadataId: String) { - val response = client().makeRequest("DELETE", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_doc/$metadataId") + val response = adminClient().makeRequest("DELETE", "${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}/_doc/$metadataId") assertEquals("Unable to delete rollup metadata $metadataId", RestStatus.OK, response.restStatus()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt index deeee184f..3a2f83089 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/SnapshotManagementRestTestCase.kt @@ -138,13 +138,14 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { val millis = Duration.of(intervalSchedule.interval.toLong(), intervalSchedule.unit).minusSeconds(2).toMillis() val startTimeMillis = desiredStartTimeMillis ?: (now().toEpochMilli() - millis) val waitForActiveShards = if (isMultiNode) "all" else "1" - val response = client().makeRequest( - "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}?wait_for_active_shards=$waitForActiveShards", - StringEntity( - "{\"doc\":{\"sm_policy\":{\"schedule\":{\"interval\":{\"start_time\":\"$startTimeMillis\"}}}}}", - APPLICATION_JSON, - ), - ) + val response = + adminClient().makeRequest( + "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.id}?wait_for_active_shards=$waitForActiveShards", + StringEntity( + "{\"doc\":{\"sm_policy\":{\"schedule\":{\"interval\":{\"start_time\":\"$startTimeMillis\"}}}}}", + APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } @@ -169,10 +170,11 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { val millis = Duration.of(intervalSchedule.interval.toLong(), intervalSchedule.unit).minusSeconds(2).toMillis() val startTimeMillis = desiredStartTimeMillis ?: (now().toEpochMilli() - millis) val waitForActiveShards = if (isMultiNode) "all" else "1" - val response = client().makeRequest( - "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.metadataID}?wait_for_active_shards=$waitForActiveShards", - StringEntity( - """ + val response = + adminClient().makeRequest( + "POST", "$INDEX_MANAGEMENT_INDEX/_update/${update.metadataID}?wait_for_active_shards=$waitForActiveShards", + StringEntity( + """ { "doc": { "sm_metadata": { @@ -186,10 +188,10 @@ abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() { } } } - """.trimIndent(), - APPLICATION_JSON, - ), - ) + """.trimIndent(), + APPLICATION_JSON, + ), + ) assertEquals("Request failed", RestStatus.OK, response.restStatus()) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt index c7c366c6c..8392e6bee 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/TestUtils.kt @@ -37,6 +37,7 @@ import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule import org.opensearch.snapshots.Snapshot import org.opensearch.snapshots.SnapshotId import org.opensearch.snapshots.SnapshotInfo +import org.opensearch.snapshots.SnapshotState import org.opensearch.test.OpenSearchTestCase.randomAlphaOfLength import org.opensearch.test.OpenSearchTestCase.randomBoolean import org.opensearch.test.OpenSearchTestCase.randomIntBetween @@ -169,11 +170,14 @@ fun randomSMState(): SMState = SMState.values()[randomIntBetween(0, SMState.valu fun randomNotificationConfig(): NotificationConfig = NotificationConfig(randomChannel(), randomConditions()) -fun randomConditions(): NotificationConfig.Conditions = NotificationConfig.Conditions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()) +fun randomConditions(): NotificationConfig.Conditions = + NotificationConfig.Conditions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()) -fun ToXContent.toJsonString(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): String = this.toXContent(XContentFactory.jsonBuilder(), params).string() +fun ToXContent.toJsonString(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): String = + this.toXContent(XContentFactory.jsonBuilder(), params).string() -fun ToXContent.toMap(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): Map = this.toXContent(XContentFactory.jsonBuilder(), params).toMap() +fun ToXContent.toMap(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): Map = + this.toXContent(XContentFactory.jsonBuilder(), params).toMap() fun mockIndexResponse(status: RestStatus = RestStatus.OK): IndexResponse { val indexResponse: IndexResponse = mock() @@ -253,6 +257,18 @@ fun mockInProgressSnapshotInfo( return SnapshotInfo(entry) } +fun mockSnapshotInfo( + name: String = randomAlphaOfLength(10), + snapshotState: SnapshotState, +): SnapshotInfo { + return SnapshotInfo( + SnapshotId(name, UUIDs.randomBase64UUID()), + emptyList(), + emptyList(), + snapshotState, + ) +} + fun mockGetSnapshotResponse(num: Int): GetSnapshotsResponse { val getSnapshotsRes: GetSnapshotsResponse = mock() whenever(getSnapshotsRes.snapshots).doReturn(mockSnapshotInfoList(num)) @@ -271,4 +287,5 @@ fun mockSnapshotInfoList(num: Int, namePrefix: String = randomAlphaOfLength(10)) return result.toList() } -fun String.parser(): XContentParser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, this) +fun String.parser(): XContentParser = + XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, this) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt index c8e1f9d89..fe313db03 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestDeleteSnapshotManagementIT.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin @@ -39,7 +40,8 @@ class RestDeleteSnapshotManagementIT : SnapshotManagementRestTestCase() { fun `test deleting a snapshot management policy that doesn't exist and config index doesnt exist`() { try { - deleteIndex(INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) client().makeRequest("DELETE", "${IndexManagementPlugin.SM_POLICIES_URI}/nonexistent_policy") fail("expected 404 ResponseException") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt index 3d94d3bd9..b697e421a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestExplainSnapshotManagementIT.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType import org.opensearch.core.rest.RestStatus @@ -139,7 +140,8 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() { fun `test explain sm policy when config index doesn't exist`() { try { - deleteIndex(INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) explainSMPolicy(randomAlphaOfLength(10)) fail("expected response exception") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt index 938ccf3f4..49e80065e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestGetSnapshotManagementIT.kt @@ -7,9 +7,11 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler import org.apache.http.HttpHeaders import org.apache.http.message.BasicHeader +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase @@ -48,7 +50,8 @@ class RestGetSnapshotManagementIT : SnapshotManagementRestTestCase() { @Throws(Exception::class) fun `test getting a snapshot management policy that doesn't exist and config index doesnt exist`() { try { - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) getSMPolicy(randomAlphaOfLength(20)) fail("expected response exception") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt index 80dbd3550..f7c03c48e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestIndexSnapshotManagementIT.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.common.xcontent.XContentType import org.opensearch.core.rest.RestStatus @@ -129,7 +130,8 @@ class RestIndexSnapshotManagementIT : SnapshotManagementRestTestCase() { @Throws(Exception::class) @Suppress("UNCHECKED_CAST") fun `test mappings after sm policy creation`() { - deleteIndex(INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) createSMPolicy(randomSMPolicy()) val response = client().makeRequest("GET", "/$INDEX_MANAGEMENT_INDEX/_mapping") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt index 038d20a71..cb4003439 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStartSnapshotManagementIT.kt @@ -5,9 +5,11 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy @@ -60,7 +62,8 @@ class RestStartSnapshotManagementIT : SnapshotManagementRestTestCase() { fun `test starting a snapshot management policy with no config index fails`() { try { - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val request = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(request) client().makeRequest("POST", "${IndexManagementPlugin.SM_POLICIES_URI}/nonexistent_foo/_start") fail("expected response exception") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt index d75f1c858..108066950 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/snapshotmanagement/resthandler/RestStopSnapshotManagementIT.kt @@ -5,9 +5,11 @@ package org.opensearch.indexmanagement.snapshotmanagement.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.snapshotmanagement.SnapshotManagementRestTestCase import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy @@ -60,7 +62,8 @@ class RestStopSnapshotManagementIT : SnapshotManagementRestTestCase() { fun `test stopping a snapshot management policy with no config index fails`() { try { - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) client().makeRequest("POST", "${IndexManagementPlugin.SM_POLICIES_URI}/nonexistent_foo/_stop") fail("expected response exception") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt index 478f8af44..9aeba5f78 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/TransformRestTestCase.kt @@ -116,9 +116,10 @@ abstract class TransformRestTestCase : IndexManagementRestTestCase() { } protected fun getTransformMetadata(metadataId: String): TransformMetadata { - val response = client().makeRequest( - "GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), - ) + val response = + adminClient().makeRequest( + "GET", "$INDEX_MANAGEMENT_INDEX/_doc/$metadataId", null, BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), + ) assertEquals("Unable to get transform metadata $metadataId", RestStatus.OK, response.restStatus()) val parser = createParser(XContentType.JSON.xContent(), response.entity.content) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt index 5d033e059..d6ce8cb45 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestDeleteTransformActionIT.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.transform.resthandler +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX @@ -75,7 +76,10 @@ class RestDeleteTransformActionIT : TransformRestTestCase() { @Throws(Exception::class) fun `test deleting a transform that doesn't exist and config index doesn't exist`() { try { - if (indexExists(INDEX_MANAGEMENT_INDEX)) deleteIndex(INDEX_MANAGEMENT_INDEX) + if (indexExists(INDEX_MANAGEMENT_INDEX)) { + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) + } val res = client().makeRequest("DELETE", "$TRANSFORM_BASE_URI/foobarbaz") fail("expected 404 ResponseException: ${res.asMap()}") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt index 7a7fbf1c2..afd7762a4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/transform/resthandler/RestExplainTransformActionIT.kt @@ -6,9 +6,10 @@ package org.opensearch.indexmanagement.transform.resthandler import org.junit.Assert +import org.opensearch.client.Request import org.opensearch.client.ResponseException import org.opensearch.core.rest.RestStatus -import org.opensearch.indexmanagement.IndexManagementPlugin +import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.transform.TransformRestTestCase @@ -158,7 +159,8 @@ class RestExplainTransformActionIT : TransformRestTestCase() { @Throws(Exception::class) fun `test explain transform when config doesnt exist`() { - deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + val deleteISMIndexRequest = Request("DELETE", "/$INDEX_MANAGEMENT_INDEX") + adminClient().performRequest(deleteISMIndexRequest) val responseExplicit = client().makeRequest("GET", "$TRANSFORM_BASE_URI/no_config_some_transform/_explain") val expectedResponse = mapOf("no_config_some_transform" to "Failed to search transform metadata") assertEquals("Non-existent transform didn't return null", expectedResponse, responseExplicit.asMap())