Skip to content

Commit e1ff04c

Browse files
committed
Handles remote transport exceptions in rollover (opendistro-for-elasticsearch#325)
1 parent a8b726c commit e1ff04c

File tree

1 file changed

+8
-9
lines changed
  • src/main/kotlin/com/amazon/opendistroforelasticsearch/indexstatemanagement/step/rollover

1 file changed

+8
-9
lines changed

src/main/kotlin/com/amazon/opendistroforelasticsearch/indexstatemanagement/step/rollover/AttemptRolloverStep.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.amazon.opendistroforelasticsearch.indexstatemanagement.model.managedi
2424
import com.amazon.opendistroforelasticsearch.indexstatemanagement.step.Step
2525
import com.amazon.opendistroforelasticsearch.indexstatemanagement.util.evaluateConditions
2626
import org.apache.logging.log4j.LogManager
27+
import org.elasticsearch.ExceptionsHelper
2728
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest
2829
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse
2930
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest
@@ -33,6 +34,7 @@ import org.elasticsearch.cluster.service.ClusterService
3334
import org.elasticsearch.common.unit.ByteSizeValue
3435
import org.elasticsearch.common.unit.TimeValue
3536
import org.elasticsearch.rest.RestStatus
37+
import org.elasticsearch.transport.RemoteTransportException
3638
import java.time.Instant
3739

3840
@Suppress("ReturnCount", "TooGenericExceptionCaught")
@@ -138,6 +140,8 @@ class AttemptRolloverStep(
138140
if (conditions.isEmpty()) null else "conditions" to conditions // don't show empty conditions object if no conditions specified
139141
).toMap()
140142
}
143+
} catch (e: RemoteTransportException) {
144+
handleException(ExceptionsHelper.unwrapCause(e) as Exception)
141145
} catch (e: Exception) {
142146
handleException(e)
143147
}
@@ -173,21 +177,16 @@ class AttemptRolloverStep(
173177
"message" to message,
174178
"shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }
175179
)
180+
} catch (e: RemoteTransportException) {
181+
handleException(ExceptionsHelper.unwrapCause(e) as Exception)
176182
} catch (e: Exception) {
177-
val message = getFailedEvaluateMessage(indexName)
178-
logger.error(message, e)
179-
stepStatus = StepStatus.FAILED
180-
val mutableInfo = mutableMapOf("message" to message)
181-
val errorMessage = e.message
182-
if (errorMessage != null) mutableInfo["cause"] = errorMessage
183-
info = mutableInfo.toMap()
183+
handleException(e, getFailedEvaluateMessage(indexName))
184184
}
185185

186186
return null
187187
}
188188

189-
private fun handleException(e: Exception) {
190-
val message = getFailedMessage(indexName)
189+
private fun handleException(e: Exception, message: String = getFailedMessage(indexName)) {
191190
logger.error(message, e)
192191
stepStatus = StepStatus.FAILED
193192
val mutableInfo = mutableMapOf("message" to message)

0 commit comments

Comments
 (0)