diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt index bd7ce82f0..6769ac4f7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt @@ -330,7 +330,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { } else { stepStatus = StepStatus.FAILED info = listOfNotNull( - "message" to getFailedCopyAliasMessage(indexName, rolledOverIndexName), + "message" to getCopyAliasNotAckMessage(indexName, rolledOverIndexName), if (conditions != null) "conditions" to conditions else null ).toMap() } @@ -389,6 +389,8 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "Successfully rolled over and copied alias from [index=$index] to [index=$newIndex]" fun getFailedCopyAliasMessage(index: String, newIndex: String) = "Successfully rolled over but failed to copied alias from [index=$index] to [index=$newIndex]" + fun getCopyAliasNotAckMessage(index: String, newIndex: String) = + "Successfully rolled over but copy alias from [index=$index] to [index=$newIndex] is not acknowledged" fun getCopyAliasIndexNotFoundMessage(newIndex: String?) = "Successfully rolled over but new index [index=$newIndex] not found during copy alias" fun getCopyAliasRolledOverIndexNotFoundMessage(index: String?) = diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt index 76c45d637..845d7d429 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -65,6 +65,30 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { whenever(metadata.index(oldIndexName).rolloverInfos).thenReturn(mapOf(alias to mock())) } + fun `test copy alias in rollover step is not acknowledged`() { + val rolloverResponse = RolloverResponse(oldIndexName, newIndexName, mapOf(), false, true, true, true) + val aliasResponse = AcknowledgedResponse(false) + // val exception = Exception("test exception") + val client = getClient(getAdminClient(getIndicesAdminClient(rolloverResponse, aliasResponse, null, null))) + + runBlocking { + val rolloverAction = RolloverAction(null, null, null, null, true, 0) + val managedIndexMetaData = ManagedIndexMetaData( + oldIndexName, "indexUuid", "policy_id", + null, null, null, + null, null, null, + null, null, null, + null, null, rolledOverIndexName = newIndexName + ) + val attemptRolloverStep = AttemptRolloverStep(rolloverAction) + val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) + attemptRolloverStep.preExecute(logger, context).execute() + val updatedManagedIndexMetaData = attemptRolloverStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) + assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + assertEquals("message info is not matched", AttemptRolloverStep.getCopyAliasNotAckMessage(oldIndexName, newIndexName), updatedManagedIndexMetaData.info?.get("message")) + } + } + fun `test copy alias in rollover step failed`() { val rolloverResponse = RolloverResponse(oldIndexName, newIndexName, mapOf(), false, true, true, true) // val aliasResponse = AcknowledgedResponse(true)