software.amazon.awssdk.services.autoscaling.model.LaunchTemplateOverrides 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.List;
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;
/**
*
* Use this structure to let Amazon EC2 Auto Scaling do the following when the Auto Scaling group has a mixed instances
* policy:
*
*
* -
*
* Override the instance type that is specified in the launch template.
*
*
* -
*
* Use multiple instance types.
*
*
*
*
* Specify the instance types that you want, or define your instance requirements instead and let Amazon EC2 Auto
* Scaling provision the available instance types that meet your requirements. This can provide Amazon EC2 Auto Scaling
* with a larger selection of instance types to choose from when fulfilling Spot and On-Demand capacities. You can view
* which instance types are matched before you apply the instance requirements to your Auto Scaling group.
*
*
* After you define your instance requirements, you don't have to keep updating these settings to get new EC2 instance
* types automatically. Amazon EC2 Auto Scaling uses the instance requirements of the Auto Scaling group to determine
* whether a new EC2 instance type can be used.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class LaunchTemplateOverrides implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField INSTANCE_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("InstanceType").getter(getter(LaunchTemplateOverrides::instanceType))
.setter(setter(Builder::instanceType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("InstanceType").build()).build();
private static final SdkField WEIGHTED_CAPACITY_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("WeightedCapacity").getter(getter(LaunchTemplateOverrides::weightedCapacity))
.setter(setter(Builder::weightedCapacity))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("WeightedCapacity").build()).build();
private static final SdkField LAUNCH_TEMPLATE_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("LaunchTemplateSpecification")
.getter(getter(LaunchTemplateOverrides::launchTemplateSpecification))
.setter(setter(Builder::launchTemplateSpecification))
.constructor(LaunchTemplateSpecification::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LaunchTemplateSpecification")
.build()).build();
private static final SdkField INSTANCE_REQUIREMENTS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("InstanceRequirements")
.getter(getter(LaunchTemplateOverrides::instanceRequirements)).setter(setter(Builder::instanceRequirements))
.constructor(InstanceRequirements::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("InstanceRequirements").build())
.build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(INSTANCE_TYPE_FIELD,
WEIGHTED_CAPACITY_FIELD, LAUNCH_TEMPLATE_SPECIFICATION_FIELD, INSTANCE_REQUIREMENTS_FIELD));
private static final long serialVersionUID = 1L;
private final String instanceType;
private final String weightedCapacity;
private final LaunchTemplateSpecification launchTemplateSpecification;
private final InstanceRequirements instanceRequirements;
private LaunchTemplateOverrides(BuilderImpl builder) {
this.instanceType = builder.instanceType;
this.weightedCapacity = builder.weightedCapacity;
this.launchTemplateSpecification = builder.launchTemplateSpecification;
this.instanceRequirements = builder.instanceRequirements;
}
/**
*
* The instance type, such as m3.xlarge
. You must specify an instance type that is supported in your
* requested Region and Availability Zones. For more information, see Instance types in the
* Amazon EC2 User Guide for Linux Instances.
*
*
* You can specify up to 40 instance types per Auto Scaling group.
*
*
* @return The instance type, such as m3.xlarge
. You must specify an instance type that is supported in
* your requested Region and Availability Zones. For more information, see Instance types in the
* Amazon EC2 User Guide for Linux Instances.
*
* You can specify up to 40 instance types per Auto Scaling group.
*/
public final String instanceType() {
return instanceType;
}
/**
*
* If you provide a list of instance types to use, you can specify the number of capacity units provided by each
* instance type in terms of virtual CPUs, memory, storage, throughput, or other relative performance
* characteristic. When a Spot or On-Demand Instance is launched, the capacity units count toward the desired
* capacity. Amazon EC2 Auto Scaling launches instances until the desired capacity is totally fulfilled, even if
* this results in an overage. For example, if there are two units remaining to fulfill capacity, and Amazon EC2
* Auto Scaling can only launch an instance with a WeightedCapacity
of five units, the instance is
* launched, and the desired capacity is exceeded by three units. For more information, see Configure an Auto Scaling group to use instance weights in the Amazon EC2 Auto Scaling User Guide.
* Value must be in the range of 1–999.
*
*
* If you specify a value for WeightedCapacity
for one instance type, you must specify a value for
* WeightedCapacity
for all of them.
*
*
*
* Every Auto Scaling group has three size parameters (DesiredCapacity
, MaxSize
, and
* MinSize
). Usually, you set these sizes based on a specific number of instances. However, if you
* configure a mixed instances policy that defines weights for the instance types, you must specify these sizes with
* the same units that you use for weighting instances.
*
*
*
* @return If you provide a list of instance types to use, you can specify the number of capacity units provided by
* each instance type in terms of virtual CPUs, memory, storage, throughput, or other relative performance
* characteristic. When a Spot or On-Demand Instance is launched, the capacity units count toward the
* desired capacity. Amazon EC2 Auto Scaling launches instances until the desired capacity is totally
* fulfilled, even if this results in an overage. For example, if there are two units remaining to fulfill
* capacity, and Amazon EC2 Auto Scaling can only launch an instance with a WeightedCapacity
of
* five units, the instance is launched, and the desired capacity is exceeded by three units. For more
* information, see Configure an Auto Scaling group to use instance weights in the Amazon EC2 Auto Scaling User
* Guide. Value must be in the range of 1–999.
*
* If you specify a value for WeightedCapacity
for one instance type, you must specify a value
* for WeightedCapacity
for all of them.
*
*
*
* Every Auto Scaling group has three size parameters (DesiredCapacity
, MaxSize
,
* and MinSize
). Usually, you set these sizes based on a specific number of instances. However,
* if you configure a mixed instances policy that defines weights for the instance types, you must specify
* these sizes with the same units that you use for weighting instances.
*
*/
public final String weightedCapacity() {
return weightedCapacity;
}
/**
*
* Provides a launch template for the specified instance type or set of instance requirements. For example, some
* instance types might require a launch template with a different AMI. If not provided, Amazon EC2 Auto Scaling
* uses the launch template that's specified in the LaunchTemplate
definition. For more information,
* see Specifying a different launch template for an instance type in the Amazon EC2 Auto Scaling User
* Guide.
*
*
* You can specify up to 20 launch templates per Auto Scaling group. The launch templates specified in the overrides
* and in the LaunchTemplate
definition count towards this limit.
*
*
* @return Provides a launch template for the specified instance type or set of instance requirements. For example,
* some instance types might require a launch template with a different AMI. If not provided, Amazon EC2
* Auto Scaling uses the launch template that's specified in the LaunchTemplate
definition. For
* more information, see Specifying a different launch template for an instance type in the Amazon EC2 Auto Scaling User
* Guide.
*
* You can specify up to 20 launch templates per Auto Scaling group. The launch templates specified in the
* overrides and in the LaunchTemplate
definition count towards this limit.
*/
public final LaunchTemplateSpecification launchTemplateSpecification() {
return launchTemplateSpecification;
}
/**
*
* The instance requirements. Amazon EC2 Auto Scaling uses your specified requirements to identify instance types.
* Then, it uses your On-Demand and Spot allocation strategies to launch instances from these instance types.
*
*
* You can specify up to four separate sets of instance requirements per Auto Scaling group. This is useful for
* provisioning instances from different Amazon Machine Images (AMIs) in the same Auto Scaling group. To do this,
* create the AMIs and create a new launch template for each AMI. Then, create a compatible set of instance
* requirements for each launch template.
*
*
*
* If you specify InstanceRequirements
, you can't specify InstanceType
.
*
*
*
* @return The instance requirements. Amazon EC2 Auto Scaling uses your specified requirements to identify instance
* types. Then, it uses your On-Demand and Spot allocation strategies to launch instances from these
* instance types.
*
* You can specify up to four separate sets of instance requirements per Auto Scaling group. This is useful
* for provisioning instances from different Amazon Machine Images (AMIs) in the same Auto Scaling group. To
* do this, create the AMIs and create a new launch template for each AMI. Then, create a compatible set of
* instance requirements for each launch template.
*
*
*
* If you specify InstanceRequirements
, you can't specify InstanceType
.
*
*/
public final InstanceRequirements instanceRequirements() {
return instanceRequirements;
}
@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(instanceType());
hashCode = 31 * hashCode + Objects.hashCode(weightedCapacity());
hashCode = 31 * hashCode + Objects.hashCode(launchTemplateSpecification());
hashCode = 31 * hashCode + Objects.hashCode(instanceRequirements());
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 LaunchTemplateOverrides)) {
return false;
}
LaunchTemplateOverrides other = (LaunchTemplateOverrides) obj;
return Objects.equals(instanceType(), other.instanceType())
&& Objects.equals(weightedCapacity(), other.weightedCapacity())
&& Objects.equals(launchTemplateSpecification(), other.launchTemplateSpecification())
&& Objects.equals(instanceRequirements(), other.instanceRequirements());
}
/**
* 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("LaunchTemplateOverrides").add("InstanceType", instanceType())
.add("WeightedCapacity", weightedCapacity()).add("LaunchTemplateSpecification", launchTemplateSpecification())
.add("InstanceRequirements", instanceRequirements()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "InstanceType":
return Optional.ofNullable(clazz.cast(instanceType()));
case "WeightedCapacity":
return Optional.ofNullable(clazz.cast(weightedCapacity()));
case "LaunchTemplateSpecification":
return Optional.ofNullable(clazz.cast(launchTemplateSpecification()));
case "InstanceRequirements":
return Optional.ofNullable(clazz.cast(instanceRequirements()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function