Skip to content

Commit

Permalink
added exception handing.
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kravchuk <[email protected]>
  • Loading branch information
ikibo committed Oct 24, 2023
1 parent 1b7b2e2 commit f629a7d
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down

0 comments on commit f629a7d

Please sign in to comment.