in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt [52:112]
override suspend fun execute(): AttemptSnapshotStep {
try {
val mutableInfo = mutableMapOf<String, String>()
if (isDenied(denyList, config.repository)) {
stepStatus = StepStatus.FAILED
mutableInfo["message"] = getBlockedMessage(denyList, config.repository, indexName)
info = mutableInfo.toMap()
return this
}
val snapshotNameSuffix = "-".plus(
LocalDateTime.now(ZoneId.of("UTC"))
.format(DateTimeFormatter.ofPattern("uuuu.MM.dd-HH:mm:ss.SSS", Locale.ROOT))
)
val snapshotScript = Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, config.snapshot, mapOf())
// If user intentionally set the snapshot name empty then we are going to honor it
val defaultSnapshotName = if (config.snapshot.isBlank()) config.snapshot else indexName
snapshotName = compileTemplate(snapshotScript, managedIndexMetaData, defaultSnapshotName).plus(snapshotNameSuffix)
val createSnapshotRequest = CreateSnapshotRequest()
.userMetadata(mapOf("snapshot_created" to "Open Distro for Elasticsearch Index Management"))
.indices(indexName)
.snapshot(snapshotName)
.repository(config.repository)
.waitForCompletion(false)
val response: CreateSnapshotResponse = client.admin().cluster().suspendUntil { createSnapshot(createSnapshotRequest, it) }
when (response.status()) {
RestStatus.ACCEPTED -> {
stepStatus = StepStatus.COMPLETED
mutableInfo["message"] = getSuccessMessage(indexName)
}
RestStatus.OK -> {
stepStatus = StepStatus.COMPLETED
mutableInfo["message"] = getSuccessMessage(indexName)
}
else -> {
val message = getFailedMessage(indexName)
logger.warn("$message - $response")
stepStatus = StepStatus.FAILED
mutableInfo["message"] = getFailedMessage(indexName)
mutableInfo["cause"] = response.toString()
}
}
info = mutableInfo.toMap()
} catch (e: RemoteTransportException) {
val cause = ExceptionsHelper.unwrapCause(e)
if (cause is ConcurrentSnapshotExecutionException) {
handleSnapshotException(cause)
} else {
handleException(cause as Exception)
}
} catch (e: ConcurrentSnapshotExecutionException) {
handleSnapshotException(e)
} catch (e: Exception) {
handleException(e)
}
return this
}