Skip to content

Commit

Permalink
Improve not acknowledge call scenario
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Aug 16, 2023
1 parent a0a42de commit f763453
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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?) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f763453

Please sign in to comment.