All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.autoscaling.waiters.Waiters.kt Maven / Gradle / Ivy

There is a newer version: 1.3.76
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.autoscaling.waiters

import aws.sdk.kotlin.services.autoscaling.AutoScalingClient
import aws.sdk.kotlin.services.autoscaling.model.DescribeAutoScalingGroupsRequest
import aws.sdk.kotlin.services.autoscaling.model.DescribeAutoScalingGroupsResponse
import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy
import aws.smithy.kotlin.runtime.retries.delay.InfiniteTokenBucket
import aws.smithy.kotlin.runtime.retries.policy.Acceptor
import aws.smithy.kotlin.runtime.retries.policy.AcceptorRetryPolicy
import aws.smithy.kotlin.runtime.retries.policy.OutputAcceptor
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
import aws.smithy.kotlin.runtime.retries.policy.RetryErrorType
import aws.smithy.kotlin.runtime.util.flattenIfPossible
import aws.smithy.kotlin.runtime.util.length
import kotlin.time.Duration.Companion.milliseconds


public suspend fun AutoScalingClient.waitUntilGroupExists(request: DescribeAutoScalingGroupsRequest = DescribeAutoScalingGroupsRequest { }): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 5_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val autoScalingGroups = it.autoScalingGroups
            val length = autoScalingGroups?.length ?: 0
            val number = 0.0
            val comparison = if (length == null) null else length.compareTo(number) > 0
            comparison == true
        },
        OutputAcceptor(RetryDirective.RetryError(RetryErrorType.ServerSide)) {
            val autoScalingGroups = it.autoScalingGroups
            val length = autoScalingGroups?.length ?: 0
            val number = 0.0
            val comparison = if (length == null) null else length.compareTo(number) > 0
            comparison == false
        },
    )

    val policy = AcceptorRetryPolicy(request, acceptors)
    return strategy.retry(policy) { describeAutoScalingGroups(request) }
}

public suspend fun AutoScalingClient.waitUntilGroupExists(block: DescribeAutoScalingGroupsRequest.Builder.() -> Unit): Outcome =
    waitUntilGroupExists(DescribeAutoScalingGroupsRequest.Builder().apply(block).build())

public suspend fun AutoScalingClient.waitUntilGroupInService(request: DescribeAutoScalingGroupsRequest = DescribeAutoScalingGroupsRequest { }): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 15_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val autoScalingGroups = it.autoScalingGroups
            val autoScalingGroupsOrEmpty = autoScalingGroups?.flattenIfPossible()
            val projection = autoScalingGroupsOrEmpty?.flatMap {
                val multiSelect = listOfNotNull(
                    listOfNotNull(
                        run {
                            val instances = it?.instances
                            val instancesFiltered = instances?.filter {
                                val lifecycleState = it?.lifecycleState?.value
                                val string = "InService"
                                val comparison = if (lifecycleState == null) null else lifecycleState.compareTo(string) == 0
                                comparison == true
                            }
                            val length = instancesFiltered?.length ?: 0
                            val minSize = it?.minSize
                            val comparison2 = if (length == null || minSize == null) null else length.compareTo(minSize) >= 0
                            comparison2
                        },
                    )
                )
                multiSelect
            }
            val projectionOrEmpty = projection?.flattenIfPossible()
            val bool = false
            val contains = projectionOrEmpty?.contains(bool) ?: false
            contains == false
        },
        OutputAcceptor(RetryDirective.RetryError(RetryErrorType.ServerSide)) {
            val autoScalingGroups = it.autoScalingGroups
            val autoScalingGroupsOrEmpty = autoScalingGroups?.flattenIfPossible()
            val projection = autoScalingGroupsOrEmpty?.flatMap {
                val multiSelect = listOfNotNull(
                    listOfNotNull(
                        run {
                            val instances = it?.instances
                            val instancesFiltered = instances?.filter {
                                val lifecycleState = it?.lifecycleState?.value
                                val string = "InService"
                                val comparison = if (lifecycleState == null) null else lifecycleState.compareTo(string) == 0
                                comparison == true
                            }
                            val length = instancesFiltered?.length ?: 0
                            val minSize = it?.minSize
                            val comparison2 = if (length == null || minSize == null) null else length.compareTo(minSize) >= 0
                            comparison2
                        },
                    )
                )
                multiSelect
            }
            val projectionOrEmpty = projection?.flattenIfPossible()
            val bool = false
            val contains = projectionOrEmpty?.contains(bool) ?: false
            contains == true
        },
    )

    val policy = AcceptorRetryPolicy(request, acceptors)
    return strategy.retry(policy) { describeAutoScalingGroups(request) }
}

public suspend fun AutoScalingClient.waitUntilGroupInService(block: DescribeAutoScalingGroupsRequest.Builder.() -> Unit): Outcome =
    waitUntilGroupInService(DescribeAutoScalingGroupsRequest.Builder().apply(block).build())

public suspend fun AutoScalingClient.waitUntilGroupNotExists(request: DescribeAutoScalingGroupsRequest = DescribeAutoScalingGroupsRequest { }): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 15_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val autoScalingGroups = it.autoScalingGroups
            val length = autoScalingGroups?.length ?: 0
            val number = 0.0
            val comparison = if (length == null) null else length.compareTo(number) > 0
            comparison == false
        },
        OutputAcceptor(RetryDirective.RetryError(RetryErrorType.ServerSide)) {
            val autoScalingGroups = it.autoScalingGroups
            val length = autoScalingGroups?.length ?: 0
            val number = 0.0
            val comparison = if (length == null) null else length.compareTo(number) > 0
            comparison == true
        },
    )

    val policy = AcceptorRetryPolicy(request, acceptors)
    return strategy.retry(policy) { describeAutoScalingGroups(request) }
}

public suspend fun AutoScalingClient.waitUntilGroupNotExists(block: DescribeAutoScalingGroupsRequest.Builder.() -> Unit): Outcome =
    waitUntilGroupNotExists(DescribeAutoScalingGroupsRequest.Builder().apply(block).build())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy