software.amazon.awssdk.services.autoscaling.model.PredictiveScalingMetricSpecification Maven / Gradle / Ivy
Show all versions of autoscaling Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.autoscaling.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* This structure specifies the metrics and target utilization settings for a predictive scaling policy.
*
*
* You must specify either a metric pair, or a load metric and a scaling metric individually. Specifying a metric pair
* instead of individual metrics provides a simpler way to configure metrics for a scaling policy. You choose the metric
* pair, and the policy automatically knows the correct sum and average statistics to use for the load metric and the
* scaling metric.
*
*
* Example
*
*
* -
*
* You create a predictive scaling policy and specify ALBRequestCount
as the value for the metric pair and
* 1000.0
as the target value. For this type of metric, you must provide the metric dimension for the
* corresponding target group, so you also provide a resource label for the Application Load Balancer target group that
* is attached to your Auto Scaling group.
*
*
* -
*
* The number of requests the target group receives per minute provides the load metric, and the request count averaged
* between the members of the target group provides the scaling metric. In CloudWatch, this refers to the
* RequestCount
and RequestCountPerTarget
metrics, respectively.
*
*
* -
*
* For optimal use of predictive scaling, you adhere to the best practice of using a dynamic scaling policy to
* automatically scale between the minimum capacity and maximum capacity in response to real-time changes in resource
* utilization.
*
*
* -
*
* Amazon EC2 Auto Scaling consumes data points for the load metric over the last 14 days and creates an hourly load
* forecast for predictive scaling. (A minimum of 24 hours of data is required.)
*
*
* -
*
* After creating the load forecast, Amazon EC2 Auto Scaling determines when to reduce or increase the capacity of your
* Auto Scaling group in each hour of the forecast period so that the average number of requests received by each
* instance is as close to 1000 requests per minute as possible at all times.
*
*
*
*
* For information about using custom metrics with predictive scaling, see Advanced predictive scaling policy configurations using custom metrics in the Amazon EC2 Auto Scaling User
* Guide.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class PredictiveScalingMetricSpecification implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField TARGET_VALUE_FIELD = SdkField. builder(MarshallingType.DOUBLE)
.memberName("TargetValue").getter(getter(PredictiveScalingMetricSpecification::targetValue))
.setter(setter(Builder::targetValue))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TargetValue").build()).build();
private static final SdkField PREDEFINED_METRIC_PAIR_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("PredefinedMetricPairSpecification")
.getter(getter(PredictiveScalingMetricSpecification::predefinedMetricPairSpecification))
.setter(setter(Builder::predefinedMetricPairSpecification))
.constructor(PredictiveScalingPredefinedMetricPair::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PredefinedMetricPairSpecification")
.build()).build();
private static final SdkField PREDEFINED_SCALING_METRIC_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("PredefinedScalingMetricSpecification")
.getter(getter(PredictiveScalingMetricSpecification::predefinedScalingMetricSpecification))
.setter(setter(Builder::predefinedScalingMetricSpecification))
.constructor(PredictiveScalingPredefinedScalingMetric::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("PredefinedScalingMetricSpecification").build()).build();
private static final SdkField PREDEFINED_LOAD_METRIC_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("PredefinedLoadMetricSpecification")
.getter(getter(PredictiveScalingMetricSpecification::predefinedLoadMetricSpecification))
.setter(setter(Builder::predefinedLoadMetricSpecification))
.constructor(PredictiveScalingPredefinedLoadMetric::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PredefinedLoadMetricSpecification")
.build()).build();
private static final SdkField CUSTOMIZED_SCALING_METRIC_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("CustomizedScalingMetricSpecification")
.getter(getter(PredictiveScalingMetricSpecification::customizedScalingMetricSpecification))
.setter(setter(Builder::customizedScalingMetricSpecification))
.constructor(PredictiveScalingCustomizedScalingMetric::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("CustomizedScalingMetricSpecification").build()).build();
private static final SdkField CUSTOMIZED_LOAD_METRIC_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("CustomizedLoadMetricSpecification")
.getter(getter(PredictiveScalingMetricSpecification::customizedLoadMetricSpecification))
.setter(setter(Builder::customizedLoadMetricSpecification))
.constructor(PredictiveScalingCustomizedLoadMetric::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("CustomizedLoadMetricSpecification")
.build()).build();
private static final SdkField CUSTOMIZED_CAPACITY_METRIC_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("CustomizedCapacityMetricSpecification")
.getter(getter(PredictiveScalingMetricSpecification::customizedCapacityMetricSpecification))
.setter(setter(Builder::customizedCapacityMetricSpecification))
.constructor(PredictiveScalingCustomizedCapacityMetric::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("CustomizedCapacityMetricSpecification").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(TARGET_VALUE_FIELD,
PREDEFINED_METRIC_PAIR_SPECIFICATION_FIELD, PREDEFINED_SCALING_METRIC_SPECIFICATION_FIELD,
PREDEFINED_LOAD_METRIC_SPECIFICATION_FIELD, CUSTOMIZED_SCALING_METRIC_SPECIFICATION_FIELD,
CUSTOMIZED_LOAD_METRIC_SPECIFICATION_FIELD, CUSTOMIZED_CAPACITY_METRIC_SPECIFICATION_FIELD));
private static final Map> SDK_NAME_TO_FIELD = Collections
.unmodifiableMap(new HashMap>() {
{
put("TargetValue", TARGET_VALUE_FIELD);
put("PredefinedMetricPairSpecification", PREDEFINED_METRIC_PAIR_SPECIFICATION_FIELD);
put("PredefinedScalingMetricSpecification", PREDEFINED_SCALING_METRIC_SPECIFICATION_FIELD);
put("PredefinedLoadMetricSpecification", PREDEFINED_LOAD_METRIC_SPECIFICATION_FIELD);
put("CustomizedScalingMetricSpecification", CUSTOMIZED_SCALING_METRIC_SPECIFICATION_FIELD);
put("CustomizedLoadMetricSpecification", CUSTOMIZED_LOAD_METRIC_SPECIFICATION_FIELD);
put("CustomizedCapacityMetricSpecification", CUSTOMIZED_CAPACITY_METRIC_SPECIFICATION_FIELD);
}
});
private static final long serialVersionUID = 1L;
private final Double targetValue;
private final PredictiveScalingPredefinedMetricPair predefinedMetricPairSpecification;
private final PredictiveScalingPredefinedScalingMetric predefinedScalingMetricSpecification;
private final PredictiveScalingPredefinedLoadMetric predefinedLoadMetricSpecification;
private final PredictiveScalingCustomizedScalingMetric customizedScalingMetricSpecification;
private final PredictiveScalingCustomizedLoadMetric customizedLoadMetricSpecification;
private final PredictiveScalingCustomizedCapacityMetric customizedCapacityMetricSpecification;
private PredictiveScalingMetricSpecification(BuilderImpl builder) {
this.targetValue = builder.targetValue;
this.predefinedMetricPairSpecification = builder.predefinedMetricPairSpecification;
this.predefinedScalingMetricSpecification = builder.predefinedScalingMetricSpecification;
this.predefinedLoadMetricSpecification = builder.predefinedLoadMetricSpecification;
this.customizedScalingMetricSpecification = builder.customizedScalingMetricSpecification;
this.customizedLoadMetricSpecification = builder.customizedLoadMetricSpecification;
this.customizedCapacityMetricSpecification = builder.customizedCapacityMetricSpecification;
}
/**
*
* Specifies the target utilization.
*
*
*
* Some metrics are based on a count instead of a percentage, such as the request count for an Application Load
* Balancer or the number of messages in an SQS queue. If the scaling policy specifies one of these metrics, specify
* the target utilization as the optimal average request or message count per instance during any one-minute
* interval.
*
*
*
* @return Specifies the target utilization.
*
* Some metrics are based on a count instead of a percentage, such as the request count for an Application
* Load Balancer or the number of messages in an SQS queue. If the scaling policy specifies one of these
* metrics, specify the target utilization as the optimal average request or message count per instance
* during any one-minute interval.
*
*/
public final Double targetValue() {
return targetValue;
}
/**
*
* The predefined metric pair specification from which Amazon EC2 Auto Scaling determines the appropriate scaling
* metric and load metric to use.
*
*
* @return The predefined metric pair specification from which Amazon EC2 Auto Scaling determines the appropriate
* scaling metric and load metric to use.
*/
public final PredictiveScalingPredefinedMetricPair predefinedMetricPairSpecification() {
return predefinedMetricPairSpecification;
}
/**
*
* The predefined scaling metric specification.
*
*
* @return The predefined scaling metric specification.
*/
public final PredictiveScalingPredefinedScalingMetric predefinedScalingMetricSpecification() {
return predefinedScalingMetricSpecification;
}
/**
*
* The predefined load metric specification.
*
*
* @return The predefined load metric specification.
*/
public final PredictiveScalingPredefinedLoadMetric predefinedLoadMetricSpecification() {
return predefinedLoadMetricSpecification;
}
/**
*
* The customized scaling metric specification.
*
*
* @return The customized scaling metric specification.
*/
public final PredictiveScalingCustomizedScalingMetric customizedScalingMetricSpecification() {
return customizedScalingMetricSpecification;
}
/**
*
* The customized load metric specification.
*
*
* @return The customized load metric specification.
*/
public final PredictiveScalingCustomizedLoadMetric customizedLoadMetricSpecification() {
return customizedLoadMetricSpecification;
}
/**
*
* The customized capacity metric specification.
*
*
* @return The customized capacity metric specification.
*/
public final PredictiveScalingCustomizedCapacityMetric customizedCapacityMetricSpecification() {
return customizedCapacityMetricSpecification;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(targetValue());
hashCode = 31 * hashCode + Objects.hashCode(predefinedMetricPairSpecification());
hashCode = 31 * hashCode + Objects.hashCode(predefinedScalingMetricSpecification());
hashCode = 31 * hashCode + Objects.hashCode(predefinedLoadMetricSpecification());
hashCode = 31 * hashCode + Objects.hashCode(customizedScalingMetricSpecification());
hashCode = 31 * hashCode + Objects.hashCode(customizedLoadMetricSpecification());
hashCode = 31 * hashCode + Objects.hashCode(customizedCapacityMetricSpecification());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof PredictiveScalingMetricSpecification)) {
return false;
}
PredictiveScalingMetricSpecification other = (PredictiveScalingMetricSpecification) obj;
return Objects.equals(targetValue(), other.targetValue())
&& Objects.equals(predefinedMetricPairSpecification(), other.predefinedMetricPairSpecification())
&& Objects.equals(predefinedScalingMetricSpecification(), other.predefinedScalingMetricSpecification())
&& Objects.equals(predefinedLoadMetricSpecification(), other.predefinedLoadMetricSpecification())
&& Objects.equals(customizedScalingMetricSpecification(), other.customizedScalingMetricSpecification())
&& Objects.equals(customizedLoadMetricSpecification(), other.customizedLoadMetricSpecification())
&& Objects.equals(customizedCapacityMetricSpecification(), other.customizedCapacityMetricSpecification());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("PredictiveScalingMetricSpecification").add("TargetValue", targetValue())
.add("PredefinedMetricPairSpecification", predefinedMetricPairSpecification())
.add("PredefinedScalingMetricSpecification", predefinedScalingMetricSpecification())
.add("PredefinedLoadMetricSpecification", predefinedLoadMetricSpecification())
.add("CustomizedScalingMetricSpecification", customizedScalingMetricSpecification())
.add("CustomizedLoadMetricSpecification", customizedLoadMetricSpecification())
.add("CustomizedCapacityMetricSpecification", customizedCapacityMetricSpecification()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "TargetValue":
return Optional.ofNullable(clazz.cast(targetValue()));
case "PredefinedMetricPairSpecification":
return Optional.ofNullable(clazz.cast(predefinedMetricPairSpecification()));
case "PredefinedScalingMetricSpecification":
return Optional.ofNullable(clazz.cast(predefinedScalingMetricSpecification()));
case "PredefinedLoadMetricSpecification":
return Optional.ofNullable(clazz.cast(predefinedLoadMetricSpecification()));
case "CustomizedScalingMetricSpecification":
return Optional.ofNullable(clazz.cast(customizedScalingMetricSpecification()));
case "CustomizedLoadMetricSpecification":
return Optional.ofNullable(clazz.cast(customizedLoadMetricSpecification()));
case "CustomizedCapacityMetricSpecification":
return Optional.ofNullable(clazz.cast(customizedCapacityMetricSpecification()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Function