io.cloudshiftdev.awscdk.services.autoscaling.MetricTargetTrackingProps.kt Maven / Gradle / Ivy
The newest version!
@file:Suppress("RedundantVisibilityModifier","RedundantUnitReturnType","RemoveRedundantQualifierName","unused","UnusedImport","ClassName","REDUNDANT_PROJECTION","DEPRECATION")
package io.cloudshiftdev.awscdk.services.autoscaling
import io.cloudshiftdev.awscdk.Duration
import io.cloudshiftdev.awscdk.common.CdkDslMarker
import io.cloudshiftdev.awscdk.common.CdkObject
import io.cloudshiftdev.awscdk.common.CdkObjectWrappers
import io.cloudshiftdev.awscdk.services.cloudwatch.IMetric
import kotlin.Boolean
import kotlin.Number
import kotlin.Unit
/**
* Properties for enabling tracking of an arbitrary metric.
*
* Example:
*
* ```
* // The code below shows an example of how to instantiate this type.
* // The values are placeholders you should change.
* import io.cloudshiftdev.awscdk.*;
* import io.cloudshiftdev.awscdk.services.autoscaling.*;
* import io.cloudshiftdev.awscdk.services.cloudwatch.*;
* Metric metric;
* MetricTargetTrackingProps metricTargetTrackingProps = MetricTargetTrackingProps.builder()
* .metric(metric)
* .targetValue(123)
* // the properties below are optional
* .cooldown(Duration.minutes(30))
* .disableScaleIn(false)
* .estimatedInstanceWarmup(Duration.minutes(30))
* .build();
* ```
*/
public interface MetricTargetTrackingProps : BaseTargetTrackingProps {
/**
* Metric to track.
*
* The metric must represent a utilization, so that if it's higher than the
* target value, your ASG should scale out, and if it's lower it should
* scale in.
*/
public fun metric(): IMetric
/**
* Value to keep the metric around.
*/
public fun targetValue(): Number
/**
* A builder for [MetricTargetTrackingProps]
*/
@CdkDslMarker
public interface Builder {
/**
* @param cooldown Period after a scaling completes before another scaling activity can start.
*/
public fun cooldown(cooldown: Duration)
/**
* @param disableScaleIn Indicates whether scale in by the target tracking policy is disabled.
* If the value is true, scale in is disabled and the target tracking policy
* won't remove capacity from the autoscaling group. Otherwise, scale in is
* enabled and the target tracking policy can remove capacity from the
* group.
*/
public fun disableScaleIn(disableScaleIn: Boolean)
/**
* @param estimatedInstanceWarmup Estimated time until a newly launched instance can send
* metrics to CloudWatch.
*/
public fun estimatedInstanceWarmup(estimatedInstanceWarmup: Duration)
/**
* @param metric Metric to track.
* The metric must represent a utilization, so that if it's higher than the
* target value, your ASG should scale out, and if it's lower it should
* scale in.
*/
public fun metric(metric: IMetric)
/**
* @param targetValue Value to keep the metric around.
*/
public fun targetValue(targetValue: Number)
}
private class BuilderImpl : Builder {
private val cdkBuilder:
software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps.Builder =
software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps.builder()
/**
* @param cooldown Period after a scaling completes before another scaling activity can start.
*/
override fun cooldown(cooldown: Duration) {
cdkBuilder.cooldown(cooldown.let(Duration.Companion::unwrap))
}
/**
* @param disableScaleIn Indicates whether scale in by the target tracking policy is disabled.
* If the value is true, scale in is disabled and the target tracking policy
* won't remove capacity from the autoscaling group. Otherwise, scale in is
* enabled and the target tracking policy can remove capacity from the
* group.
*/
override fun disableScaleIn(disableScaleIn: Boolean) {
cdkBuilder.disableScaleIn(disableScaleIn)
}
/**
* @param estimatedInstanceWarmup Estimated time until a newly launched instance can send
* metrics to CloudWatch.
*/
override fun estimatedInstanceWarmup(estimatedInstanceWarmup: Duration) {
cdkBuilder.estimatedInstanceWarmup(estimatedInstanceWarmup.let(Duration.Companion::unwrap))
}
/**
* @param metric Metric to track.
* The metric must represent a utilization, so that if it's higher than the
* target value, your ASG should scale out, and if it's lower it should
* scale in.
*/
override fun metric(metric: IMetric) {
cdkBuilder.metric(metric.let(IMetric.Companion::unwrap))
}
/**
* @param targetValue Value to keep the metric around.
*/
override fun targetValue(targetValue: Number) {
cdkBuilder.targetValue(targetValue)
}
public fun build(): software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps =
cdkBuilder.build()
}
private class Wrapper(
cdkObject: software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps,
) : CdkObject(cdkObject),
MetricTargetTrackingProps {
/**
* Period after a scaling completes before another scaling activity can start.
*
* Default: - The default cooldown configured on the AutoScalingGroup.
*/
override fun cooldown(): Duration? = unwrap(this).getCooldown()?.let(Duration::wrap)
/**
* Indicates whether scale in by the target tracking policy is disabled.
*
* If the value is true, scale in is disabled and the target tracking policy
* won't remove capacity from the autoscaling group. Otherwise, scale in is
* enabled and the target tracking policy can remove capacity from the
* group.
*
* Default: false
*/
override fun disableScaleIn(): Boolean? = unwrap(this).getDisableScaleIn()
/**
* Estimated time until a newly launched instance can send metrics to CloudWatch.
*
* Default: - Same as the cooldown.
*/
override fun estimatedInstanceWarmup(): Duration? =
unwrap(this).getEstimatedInstanceWarmup()?.let(Duration::wrap)
/**
* Metric to track.
*
* The metric must represent a utilization, so that if it's higher than the
* target value, your ASG should scale out, and if it's lower it should
* scale in.
*/
override fun metric(): IMetric = unwrap(this).getMetric().let(IMetric::wrap)
/**
* Value to keep the metric around.
*/
override fun targetValue(): Number = unwrap(this).getTargetValue()
}
public companion object {
public operator fun invoke(block: Builder.() -> Unit = {}): MetricTargetTrackingProps {
val builderImpl = BuilderImpl()
return Wrapper(builderImpl.apply(block).build())
}
internal
fun wrap(cdkObject: software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps):
MetricTargetTrackingProps = CdkObjectWrappers.wrap(cdkObject) as? MetricTargetTrackingProps
?: Wrapper(cdkObject)
internal fun unwrap(wrapped: MetricTargetTrackingProps):
software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps = (wrapped as
CdkObject).cdkObject as
software.amazon.awscdk.services.autoscaling.MetricTargetTrackingProps
}
}