diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt index c150a5a66..d3095641c 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/WaitForShrinkStep.kt @@ -134,7 +134,7 @@ class WaitForShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru sourceIndexAliases .filterNot { targetIndexAliasesNames.contains(it.alias) } .map { - AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD) + AliasActions(AliasActions.Type.ADD) .index(targetIndexName) .alias(it.alias) .filter(it.filter?.string()) @@ -145,15 +145,18 @@ class WaitForShrinkStep(private val action: ShrinkAction) : ShrinkStep(name, tru } .forEach { req.addAliasAction(it) } - val aliasesAcked = context.client.admin().indices().suspendUntil { aliases(req, it) }.isAcknowledged - - if (aliasesAcked) { - logger.info("Aliases switched successfully from [$sourceIndexName] to [$targetIndexName].") - } else { - logger.warn("Switching aliases from [$sourceIndexName] to [$targetIndexName] failed.") + return try { + val response: AcknowledgedResponse = context.client.admin().indices().suspendUntil { aliases(req, it) } + if (response.isAcknowledged) { + logger.info("Aliases switched successfully from [$sourceIndexName] to [$targetIndexName].") + return true + } + logger.error("Switching aliases from [$sourceIndexName] to [$targetIndexName] failed.") + return false + } catch (e: Exception) { + logger.error("Switching aliases from [$sourceIndexName] to [$targetIndexName] failed due to exception.", e) + false } - - return aliasesAcked } override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData {