From b8adc3e5a50c999ac3f8e9597d7b67462302a709 Mon Sep 17 00:00:00 2001 From: Ronnak Saxena Date: Thu, 20 Jul 2023 14:29:32 -0700 Subject: [PATCH] Changed if statement to make it more readable Signed-off-by: Ronnak Saxena --- .../step/rollover/AttemptRolloverStep.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 95c0d0908..1bf98c5ca 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 @@ -296,15 +296,18 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { client.admin().cluster().state(ClusterStateRequest(), it) } // If the index was rolled over, this is a transient failure - isTransientFailure = response.state.metadata.index(indexName).rolloverInfos.containsKey(aliasName) - val result = ManagedIndexRunner.updateManagedIndexMetaData( - managedIndexMetaData.copy( - stepMetaData = managedIndexMetaData.stepMetaData?.copy(stepStatus = StepStatus.COMPLETED), - info = mapOf("message" to getAlreadyRolledOverMessage(indexName, aliasName)) + val wasRolledOver: Boolean = response.state.metadata.index(indexName).rolloverInfos.containsKey(aliasName) + if (wasRolledOver) { + isTransientFailure = true + val result = ManagedIndexRunner.updateManagedIndexMetaData( + managedIndexMetaData.copy( + stepMetaData = managedIndexMetaData.stepMetaData?.copy(stepStatus = StepStatus.COMPLETED), + info = mapOf("message" to getAlreadyRolledOverMessage(indexName, aliasName)) + ) ) - ) - if (!result.metadataSaved) { - logger.error("Not able to update managed index meta data for index ${managedIndexMetaData.index}") + if (!result.metadataSaved) { + logger.error("Not able to update managed index meta data for index ${managedIndexMetaData.index}") + } } } catch (e: Exception) { logger.error("Failed to request index ${stepContext.metadata.index} cluster data when checking for transient failure", e)