override suspend fun execute()

in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt [37:80]


    override suspend fun execute(): WaitForSnapshotStep {
        try {
            val snapshotName = getSnapshotName() ?: return this
            val request = SnapshotsStatusRequest()
                .snapshots(arrayOf(snapshotName))
                .repository(config.repository)
            val response: SnapshotsStatusResponse = client.admin().cluster().suspendUntil { snapshotsStatus(request, it) }
            val status: SnapshotStatus? = response
                .snapshots
                .find { snapshotStatus ->
                    snapshotStatus.snapshot.snapshotId.name == snapshotName &&
                        snapshotStatus.snapshot.repository == config.repository
                }
            if (status != null) {
                when (status.state) {
                    State.INIT, State.STARTED -> {
                        stepStatus = StepStatus.CONDITION_NOT_MET
                        info = mapOf("message" to getSnapshotInProgressMessage(indexName), "state" to status.state.name)
                    }
                    State.SUCCESS -> {
                        stepStatus = StepStatus.COMPLETED
                        info = mapOf("message" to getSuccessMessage(indexName), "state" to status.state.name)
                    }
                    else -> { // State.FAILED, State.ABORTED
                        val message = getFailedExistsMessage(indexName)
                        logger.warn(message)
                        stepStatus = StepStatus.FAILED
                        info = mapOf("message" to message, "state" to status.state.name)
                    }
                }
            } else {
                val message = getFailedExistsMessage(indexName)
                logger.warn(message)
                stepStatus = StepStatus.FAILED
                info = mapOf("message" to message)
            }
        } catch (e: RemoteTransportException) {
            handleException(ExceptionsHelper.unwrapCause(e) as Exception)
        } catch (e: Exception) {
            handleException(e)
        }

        return this
    }