Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Updates Allocation step with message and execute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbbaughe committed Aug 3, 2020
1 parent 4d141f7 commit ad4a976
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@ class AttemptAllocationStep(

override fun isIdempotent() = true

override suspend fun execute() {
override suspend fun execute(): AttemptAllocationStep {
try {
val response: AcknowledgedResponse = client.admin()
.indices()
.suspendUntil { updateSettings(UpdateSettingsRequest(buildSettings(), managedIndexMetaData.index), it) }
handleResponse(response)
} catch (e: Exception) {
logger.error(ERROR_MESSAGE, e)
stepStatus = StepStatus.FAILED
val mutableInfo = mutableMapOf("message" to ERROR_MESSAGE)
val errorMessage = e.message
if (errorMessage != null) mutableInfo["cause"] = errorMessage
info = mutableInfo.toMap()
resolveException(e)
}

return this
}

private fun buildSettings(): Settings {
Expand All @@ -63,13 +60,23 @@ class AttemptAllocationStep(
return builder.build()
}

private fun resolveException(e: Exception) {
val message = getFailedMessage(indexName)
logger.error(message, e)
stepStatus = StepStatus.FAILED
val mutableInfo = mutableMapOf("message" to message)
val errorMessage = e.message
if (errorMessage != null) mutableInfo["cause"] = errorMessage
info = mutableInfo.toMap()
}

private fun handleResponse(response: AcknowledgedResponse) {
if (response.isAcknowledged) {
stepStatus = StepStatus.COMPLETED
info = mapOf("message" to "Updated settings with allocation.")
info = mapOf("message" to getSuccessMessage(indexName))
} else {
stepStatus = StepStatus.FAILED
info = mapOf("message" to ERROR_MESSAGE)
info = mapOf("message" to getFailedMessage(indexName))
}
}

Expand All @@ -82,7 +89,8 @@ class AttemptAllocationStep(
}

companion object {
private const val ERROR_MESSAGE = "Failed to update settings with allocation."
private const val SETTINGS_PREFIX = "index.routing.allocation."
fun getFailedMessage(index: String) = "Failed to update allocation setting [index=$index]"
fun getSuccessMessage(index: String) = "Successfully updated allocation setting [index=$index]"
}
}

0 comments on commit ad4a976

Please sign in to comment.