
software.amazon.awssdk.services.ec2.model.CreateFleetRequest Maven / Gradle / Ivy
/*
* 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.ec2.model;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
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 java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
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.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class CreateFleetRequest extends Ec2Request implements
ToCopyableBuilder {
private static final SdkField CLIENT_TOKEN_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("ClientToken")
.getter(getter(CreateFleetRequest::clientToken))
.setter(setter(Builder::clientToken))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ClientToken")
.unmarshallLocationName("ClientToken").build()).build();
private static final SdkField SPOT_OPTIONS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("SpotOptions")
.getter(getter(CreateFleetRequest::spotOptions))
.setter(setter(Builder::spotOptions))
.constructor(SpotOptionsRequest::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("SpotOptions")
.unmarshallLocationName("SpotOptions").build()).build();
private static final SdkField ON_DEMAND_OPTIONS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("OnDemandOptions")
.getter(getter(CreateFleetRequest::onDemandOptions))
.setter(setter(Builder::onDemandOptions))
.constructor(OnDemandOptionsRequest::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("OnDemandOptions")
.unmarshallLocationName("OnDemandOptions").build()).build();
private static final SdkField EXCESS_CAPACITY_TERMINATION_POLICY_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("ExcessCapacityTerminationPolicy")
.getter(getter(CreateFleetRequest::excessCapacityTerminationPolicyAsString))
.setter(setter(Builder::excessCapacityTerminationPolicy))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExcessCapacityTerminationPolicy")
.unmarshallLocationName("ExcessCapacityTerminationPolicy").build()).build();
private static final SdkField> LAUNCH_TEMPLATE_CONFIGS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("LaunchTemplateConfigs")
.getter(getter(CreateFleetRequest::launchTemplateConfigs))
.setter(setter(Builder::launchTemplateConfigs))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LaunchTemplateConfigs")
.unmarshallLocationName("LaunchTemplateConfigs").build(),
ListTrait
.builder()
.memberLocationName("item")
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(FleetLaunchTemplateConfigRequest::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("Item").unmarshallLocationName("item").build()).build())
.build()).build();
private static final SdkField TARGET_CAPACITY_SPECIFICATION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("TargetCapacitySpecification")
.getter(getter(CreateFleetRequest::targetCapacitySpecification))
.setter(setter(Builder::targetCapacitySpecification))
.constructor(TargetCapacitySpecificationRequest::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TargetCapacitySpecification")
.unmarshallLocationName("TargetCapacitySpecification").build()).build();
private static final SdkField TERMINATE_INSTANCES_WITH_EXPIRATION_FIELD = SdkField
. builder(MarshallingType.BOOLEAN)
.memberName("TerminateInstancesWithExpiration")
.getter(getter(CreateFleetRequest::terminateInstancesWithExpiration))
.setter(setter(Builder::terminateInstancesWithExpiration))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TerminateInstancesWithExpiration")
.unmarshallLocationName("TerminateInstancesWithExpiration").build()).build();
private static final SdkField TYPE_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("Type")
.getter(getter(CreateFleetRequest::typeAsString))
.setter(setter(Builder::type))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Type")
.unmarshallLocationName("Type").build()).build();
private static final SdkField VALID_FROM_FIELD = SdkField
. builder(MarshallingType.INSTANT)
.memberName("ValidFrom")
.getter(getter(CreateFleetRequest::validFrom))
.setter(setter(Builder::validFrom))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ValidFrom")
.unmarshallLocationName("ValidFrom").build()).build();
private static final SdkField VALID_UNTIL_FIELD = SdkField
. builder(MarshallingType.INSTANT)
.memberName("ValidUntil")
.getter(getter(CreateFleetRequest::validUntil))
.setter(setter(Builder::validUntil))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ValidUntil")
.unmarshallLocationName("ValidUntil").build()).build();
private static final SdkField REPLACE_UNHEALTHY_INSTANCES_FIELD = SdkField
. builder(MarshallingType.BOOLEAN)
.memberName("ReplaceUnhealthyInstances")
.getter(getter(CreateFleetRequest::replaceUnhealthyInstances))
.setter(setter(Builder::replaceUnhealthyInstances))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ReplaceUnhealthyInstances")
.unmarshallLocationName("ReplaceUnhealthyInstances").build()).build();
private static final SdkField> TAG_SPECIFICATIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("TagSpecifications")
.getter(getter(CreateFleetRequest::tagSpecifications))
.setter(setter(Builder::tagSpecifications))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TagSpecification")
.unmarshallLocationName("TagSpecification").build(),
ListTrait
.builder()
.memberLocationName("item")
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(TagSpecification::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("Item").unmarshallLocationName("item").build()).build())
.build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(CLIENT_TOKEN_FIELD,
SPOT_OPTIONS_FIELD, ON_DEMAND_OPTIONS_FIELD, EXCESS_CAPACITY_TERMINATION_POLICY_FIELD, LAUNCH_TEMPLATE_CONFIGS_FIELD,
TARGET_CAPACITY_SPECIFICATION_FIELD, TERMINATE_INSTANCES_WITH_EXPIRATION_FIELD, TYPE_FIELD, VALID_FROM_FIELD,
VALID_UNTIL_FIELD, REPLACE_UNHEALTHY_INSTANCES_FIELD, TAG_SPECIFICATIONS_FIELD));
private final String clientToken;
private final SpotOptionsRequest spotOptions;
private final OnDemandOptionsRequest onDemandOptions;
private final String excessCapacityTerminationPolicy;
private final List launchTemplateConfigs;
private final TargetCapacitySpecificationRequest targetCapacitySpecification;
private final Boolean terminateInstancesWithExpiration;
private final String type;
private final Instant validFrom;
private final Instant validUntil;
private final Boolean replaceUnhealthyInstances;
private final List tagSpecifications;
private CreateFleetRequest(BuilderImpl builder) {
super(builder);
this.clientToken = builder.clientToken;
this.spotOptions = builder.spotOptions;
this.onDemandOptions = builder.onDemandOptions;
this.excessCapacityTerminationPolicy = builder.excessCapacityTerminationPolicy;
this.launchTemplateConfigs = builder.launchTemplateConfigs;
this.targetCapacitySpecification = builder.targetCapacitySpecification;
this.terminateInstancesWithExpiration = builder.terminateInstancesWithExpiration;
this.type = builder.type;
this.validFrom = builder.validFrom;
this.validUntil = builder.validUntil;
this.replaceUnhealthyInstances = builder.replaceUnhealthyInstances;
this.tagSpecifications = builder.tagSpecifications;
}
/**
*
* Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more
* information, see Ensuring
* Idempotency.
*
*
* @return Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more
* information, see Ensuring
* Idempotency.
*/
public String clientToken() {
return clientToken;
}
/**
*
* Describes the configuration of Spot Instances in an EC2 Fleet.
*
*
* @return Describes the configuration of Spot Instances in an EC2 Fleet.
*/
public SpotOptionsRequest spotOptions() {
return spotOptions;
}
/**
*
* Describes the configuration of On-Demand Instances in an EC2 Fleet.
*
*
* @return Describes the configuration of On-Demand Instances in an EC2 Fleet.
*/
public OnDemandOptionsRequest onDemandOptions() {
return onDemandOptions;
}
/**
*
* Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is
* decreased below the current size of the EC2 Fleet.
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #excessCapacityTerminationPolicy} will return
* {@link FleetExcessCapacityTerminationPolicy#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #excessCapacityTerminationPolicyAsString}.
*
*
* @return Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is
* decreased below the current size of the EC2 Fleet.
* @see FleetExcessCapacityTerminationPolicy
*/
public FleetExcessCapacityTerminationPolicy excessCapacityTerminationPolicy() {
return FleetExcessCapacityTerminationPolicy.fromValue(excessCapacityTerminationPolicy);
}
/**
*
* Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is
* decreased below the current size of the EC2 Fleet.
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #excessCapacityTerminationPolicy} will return
* {@link FleetExcessCapacityTerminationPolicy#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #excessCapacityTerminationPolicyAsString}.
*
*
* @return Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is
* decreased below the current size of the EC2 Fleet.
* @see FleetExcessCapacityTerminationPolicy
*/
public String excessCapacityTerminationPolicyAsString() {
return excessCapacityTerminationPolicy;
}
/**
* Returns true if the LaunchTemplateConfigs property was specified by the sender (it may be empty), or false if the
* sender did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS
* service.
*/
public boolean hasLaunchTemplateConfigs() {
return launchTemplateConfigs != null && !(launchTemplateConfigs instanceof SdkAutoConstructList);
}
/**
*
* The configuration for the EC2 Fleet.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasLaunchTemplateConfigs()} to see if a value was sent in this field.
*
*
* @return The configuration for the EC2 Fleet.
*/
public List launchTemplateConfigs() {
return launchTemplateConfigs;
}
/**
*
* The number of units to request.
*
*
* @return The number of units to request.
*/
public TargetCapacitySpecificationRequest targetCapacitySpecification() {
return targetCapacitySpecification;
}
/**
*
* Indicates whether running instances should be terminated when the EC2 Fleet expires.
*
*
* @return Indicates whether running instances should be terminated when the EC2 Fleet expires.
*/
public Boolean terminateInstancesWithExpiration() {
return terminateInstancesWithExpiration;
}
/**
*
* The type of the request. By default, the EC2 Fleet places an asynchronous request for your desired capacity, and
* maintains it by replenishing interrupted Spot Instances (maintain
). A value of instant
* places a synchronous one-time request, and returns errors for any instances that could not be launched. A value
* of request
places an asynchronous one-time request without maintaining capacity or submitting
* requests in alternative capacity pools if capacity is unavailable. For more information, see EC2 Fleet Request Types in the Amazon Elastic Compute Cloud User Guide.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #type} will return
* {@link FleetType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #typeAsString}.
*
*
* @return The type of the request. By default, the EC2 Fleet places an asynchronous request for your desired
* capacity, and maintains it by replenishing interrupted Spot Instances (maintain
). A value of
* instant
places a synchronous one-time request, and returns errors for any instances that
* could not be launched. A value of request
places an asynchronous one-time request without
* maintaining capacity or submitting requests in alternative capacity pools if capacity is unavailable. For
* more information, see EC2 Fleet Request Types in the Amazon Elastic Compute Cloud User Guide.
* @see FleetType
*/
public FleetType type() {
return FleetType.fromValue(type);
}
/**
*
* The type of the request. By default, the EC2 Fleet places an asynchronous request for your desired capacity, and
* maintains it by replenishing interrupted Spot Instances (maintain
). A value of instant
* places a synchronous one-time request, and returns errors for any instances that could not be launched. A value
* of request
places an asynchronous one-time request without maintaining capacity or submitting
* requests in alternative capacity pools if capacity is unavailable. For more information, see EC2 Fleet Request Types in the Amazon Elastic Compute Cloud User Guide.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #type} will return
* {@link FleetType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #typeAsString}.
*
*
* @return The type of the request. By default, the EC2 Fleet places an asynchronous request for your desired
* capacity, and maintains it by replenishing interrupted Spot Instances (maintain
). A value of
* instant
places a synchronous one-time request, and returns errors for any instances that
* could not be launched. A value of request
places an asynchronous one-time request without
* maintaining capacity or submitting requests in alternative capacity pools if capacity is unavailable. For
* more information, see EC2 Fleet Request Types in the Amazon Elastic Compute Cloud User Guide.
* @see FleetType
*/
public String typeAsString() {
return type;
}
/**
*
* The start date and time of the request, in UTC format (for example,
* YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request
* immediately.
*
*
* @return The start date and time of the request, in UTC format (for example,
* YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the
* request immediately.
*/
public Instant validFrom() {
return validFrom;
}
/**
*
* The end date and time of the request, in UTC format (for example,
* YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests are
* placed or able to fulfill the request. If no value is specified, the request remains until you cancel it.
*
*
* @return The end date and time of the request, in UTC format (for example,
* YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests
* are placed or able to fulfill the request. If no value is specified, the request remains until you cancel
* it.
*/
public Instant validUntil() {
return validUntil;
}
/**
*
* Indicates whether EC2 Fleet should replace unhealthy instances.
*
*
* @return Indicates whether EC2 Fleet should replace unhealthy instances.
*/
public Boolean replaceUnhealthyInstances() {
return replaceUnhealthyInstances;
}
/**
* Returns true if the TagSpecifications property was specified by the sender (it may be empty), or false if the
* sender did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS
* service.
*/
public boolean hasTagSpecifications() {
return tagSpecifications != null && !(tagSpecifications instanceof SdkAutoConstructList);
}
/**
*
* The key-value pair for tagging the EC2 Fleet request on creation. The value for ResourceType
must be
* fleet
, otherwise the fleet request fails. To tag instances at launch, specify the tags in the launch
* template. For information about tagging after launch, see Tagging Your
* Resources.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasTagSpecifications()} to see if a value was sent in this field.
*
*
* @return The key-value pair for tagging the EC2 Fleet request on creation. The value for ResourceType
* must be fleet
, otherwise the fleet request fails. To tag instances at launch, specify the
* tags in the launch template. For information about tagging after launch, see Tagging Your
* Resources.
*/
public List tagSpecifications() {
return tagSpecifications;
}
@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 int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(clientToken());
hashCode = 31 * hashCode + Objects.hashCode(spotOptions());
hashCode = 31 * hashCode + Objects.hashCode(onDemandOptions());
hashCode = 31 * hashCode + Objects.hashCode(excessCapacityTerminationPolicyAsString());
hashCode = 31 * hashCode + Objects.hashCode(launchTemplateConfigs());
hashCode = 31 * hashCode + Objects.hashCode(targetCapacitySpecification());
hashCode = 31 * hashCode + Objects.hashCode(terminateInstancesWithExpiration());
hashCode = 31 * hashCode + Objects.hashCode(typeAsString());
hashCode = 31 * hashCode + Objects.hashCode(validFrom());
hashCode = 31 * hashCode + Objects.hashCode(validUntil());
hashCode = 31 * hashCode + Objects.hashCode(replaceUnhealthyInstances());
hashCode = 31 * hashCode + Objects.hashCode(tagSpecifications());
return hashCode;
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CreateFleetRequest)) {
return false;
}
CreateFleetRequest other = (CreateFleetRequest) obj;
return Objects.equals(clientToken(), other.clientToken()) && Objects.equals(spotOptions(), other.spotOptions())
&& Objects.equals(onDemandOptions(), other.onDemandOptions())
&& Objects.equals(excessCapacityTerminationPolicyAsString(), other.excessCapacityTerminationPolicyAsString())
&& Objects.equals(launchTemplateConfigs(), other.launchTemplateConfigs())
&& Objects.equals(targetCapacitySpecification(), other.targetCapacitySpecification())
&& Objects.equals(terminateInstancesWithExpiration(), other.terminateInstancesWithExpiration())
&& Objects.equals(typeAsString(), other.typeAsString()) && Objects.equals(validFrom(), other.validFrom())
&& Objects.equals(validUntil(), other.validUntil())
&& Objects.equals(replaceUnhealthyInstances(), other.replaceUnhealthyInstances())
&& Objects.equals(tagSpecifications(), other.tagSpecifications());
}
/**
* 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 String toString() {
return ToString.builder("CreateFleetRequest").add("ClientToken", clientToken()).add("SpotOptions", spotOptions())
.add("OnDemandOptions", onDemandOptions())
.add("ExcessCapacityTerminationPolicy", excessCapacityTerminationPolicyAsString())
.add("LaunchTemplateConfigs", launchTemplateConfigs())
.add("TargetCapacitySpecification", targetCapacitySpecification())
.add("TerminateInstancesWithExpiration", terminateInstancesWithExpiration()).add("Type", typeAsString())
.add("ValidFrom", validFrom()).add("ValidUntil", validUntil())
.add("ReplaceUnhealthyInstances", replaceUnhealthyInstances()).add("TagSpecifications", tagSpecifications())
.build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ClientToken":
return Optional.ofNullable(clazz.cast(clientToken()));
case "SpotOptions":
return Optional.ofNullable(clazz.cast(spotOptions()));
case "OnDemandOptions":
return Optional.ofNullable(clazz.cast(onDemandOptions()));
case "ExcessCapacityTerminationPolicy":
return Optional.ofNullable(clazz.cast(excessCapacityTerminationPolicyAsString()));
case "LaunchTemplateConfigs":
return Optional.ofNullable(clazz.cast(launchTemplateConfigs()));
case "TargetCapacitySpecification":
return Optional.ofNullable(clazz.cast(targetCapacitySpecification()));
case "TerminateInstancesWithExpiration":
return Optional.ofNullable(clazz.cast(terminateInstancesWithExpiration()));
case "Type":
return Optional.ofNullable(clazz.cast(typeAsString()));
case "ValidFrom":
return Optional.ofNullable(clazz.cast(validFrom()));
case "ValidUntil":
return Optional.ofNullable(clazz.cast(validUntil()));
case "ReplaceUnhealthyInstances":
return Optional.ofNullable(clazz.cast(replaceUnhealthyInstances()));
case "TagSpecifications":
return Optional.ofNullable(clazz.cast(tagSpecifications()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function