
software.amazon.awssdk.services.batch.model.ContainerOverrides 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.batch.model;
import java.io.Serializable;
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.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;
/**
*
* The overrides that should be sent to a container.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class ContainerOverrides implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField VCPUS_FIELD = SdkField. builder(MarshallingType.INTEGER).memberName("vcpus")
.getter(getter(ContainerOverrides::vcpus)).setter(setter(Builder::vcpus))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("vcpus").build()).build();
private static final SdkField MEMORY_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("memory").getter(getter(ContainerOverrides::memory)).setter(setter(Builder::memory))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("memory").build()).build();
private static final SdkField> COMMAND_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("command")
.getter(getter(ContainerOverrides::command))
.setter(setter(Builder::command))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("command").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField INSTANCE_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("instanceType").getter(getter(ContainerOverrides::instanceType)).setter(setter(Builder::instanceType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("instanceType").build()).build();
private static final SdkField> ENVIRONMENT_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("environment")
.getter(getter(ContainerOverrides::environment))
.setter(setter(Builder::environment))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("environment").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(KeyValuePair::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> RESOURCE_REQUIREMENTS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("resourceRequirements")
.getter(getter(ContainerOverrides::resourceRequirements))
.setter(setter(Builder::resourceRequirements))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("resourceRequirements").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(ResourceRequirement::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(VCPUS_FIELD, MEMORY_FIELD,
COMMAND_FIELD, INSTANCE_TYPE_FIELD, ENVIRONMENT_FIELD, RESOURCE_REQUIREMENTS_FIELD));
private static final long serialVersionUID = 1L;
private final Integer vcpus;
private final Integer memory;
private final List command;
private final String instanceType;
private final List environment;
private final List resourceRequirements;
private ContainerOverrides(BuilderImpl builder) {
this.vcpus = builder.vcpus;
this.memory = builder.memory;
this.command = builder.command;
this.instanceType = builder.instanceType;
this.environment = builder.environment;
this.resourceRequirements = builder.resourceRequirements;
}
/**
*
* This parameter is deprecated and not supported for jobs run on Fargate resources, see
* resourceRequirement
. For jobs run on EC2 resources, the number of vCPUs to reserve for the
* container. This value overrides the value set in the job definition. Jobs run on EC2 resources can specify the
* vCPU requirement using resourceRequirement
but the vCPU requirements can't be specified both here
* and in resourceRequirement
. This parameter maps to CpuShares
in the Create a container section of the Docker Remote API and the --cpu-shares
option
* to docker run. Each vCPU is equivalent to 1,024 CPU
* shares. You must specify at least one vCPU.
*
*
*
* This parameter isn't applicable to jobs running on Fargate resources and shouldn't be provided. Jobs running on
* Fargate resources must specify the vCPU requirement for the job using resourceRequirements
.
*
*
*
* @return This parameter is deprecated and not supported for jobs run on Fargate resources, see
* resourceRequirement
. For jobs run on EC2 resources, the number of vCPUs to reserve for the
* container. This value overrides the value set in the job definition. Jobs run on EC2 resources can
* specify the vCPU requirement using resourceRequirement
but the vCPU requirements can't be
* specified both here and in resourceRequirement
. This parameter maps to
* CpuShares
in the Create a container section of the
* Docker Remote API and the
* --cpu-shares
option to docker
* run. Each vCPU is equivalent to 1,024 CPU shares. You must specify at least one vCPU.
*
* This parameter isn't applicable to jobs running on Fargate resources and shouldn't be provided. Jobs
* running on Fargate resources must specify the vCPU requirement for the job using
* resourceRequirements
.
*
*/
public final Integer vcpus() {
return vcpus;
}
/**
*
* This parameter is deprecated and not supported for jobs run on Fargate resources, use
* ResourceRequirement
. For jobs run on EC2 resource, the number of MiB of memory reserved for the job.
* This value overrides the value set in the job definition.
*
*
* @return This parameter is deprecated and not supported for jobs run on Fargate resources, use
* ResourceRequirement
. For jobs run on EC2 resource, the number of MiB of memory reserved for
* the job. This value overrides the value set in the job definition.
*/
public final Integer memory() {
return memory;
}
/**
* Returns true if the Command 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 final boolean hasCommand() {
return command != null && !(command instanceof SdkAutoConstructList);
}
/**
*
* The command to send to the container that overrides the default command from the Docker image or the job
* definition.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasCommand()} to see if a value was sent in this field.
*
*
* @return The command to send to the container that overrides the default command from the Docker image or the job
* definition.
*/
public final List command() {
return command;
}
/**
*
* The instance type to use for a multi-node parallel job.
*
*
*
* This parameter isn't applicable to single-node container jobs or for jobs running on Fargate resources and
* shouldn't be provided.
*
*
*
* @return The instance type to use for a multi-node parallel job.
*
* This parameter isn't applicable to single-node container jobs or for jobs running on Fargate resources
* and shouldn't be provided.
*
*/
public final String instanceType() {
return instanceType;
}
/**
* Returns true if the Environment 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 final boolean hasEnvironment() {
return environment != null && !(environment instanceof SdkAutoConstructList);
}
/**
*
* The environment variables to send to the container. You can add new environment variables, which are added to the
* container at launch, or you can override the existing environment variables from the Docker image or the job
* definition.
*
*
*
* Environment variables must not start with AWS_BATCH
; this naming convention is reserved for
* variables that are set by the AWS Batch service.
*
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasEnvironment()} to see if a value was sent in this field.
*
*
* @return The environment variables to send to the container. You can add new environment variables, which are
* added to the container at launch, or you can override the existing environment variables from the Docker
* image or the job definition.
*
* Environment variables must not start with AWS_BATCH
; this naming convention is reserved for
* variables that are set by the AWS Batch service.
*
*/
public final List environment() {
return environment;
}
/**
* Returns true if the ResourceRequirements 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 final boolean hasResourceRequirements() {
return resourceRequirements != null && !(resourceRequirements instanceof SdkAutoConstructList);
}
/**
*
* The type and amount of resources to assign to a container. This overrides the settings in the job definition. The
* supported resources include GPU
, MEMORY
, and VCPU
.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasResourceRequirements()} to see if a value was sent in this field.
*
*
* @return The type and amount of resources to assign to a container. This overrides the settings in the job
* definition. The supported resources include GPU
, MEMORY
, and VCPU
.
*/
public final List resourceRequirements() {
return resourceRequirements;
}
@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(vcpus());
hashCode = 31 * hashCode + Objects.hashCode(memory());
hashCode = 31 * hashCode + Objects.hashCode(hasCommand() ? command() : null);
hashCode = 31 * hashCode + Objects.hashCode(instanceType());
hashCode = 31 * hashCode + Objects.hashCode(hasEnvironment() ? environment() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasResourceRequirements() ? resourceRequirements() : null);
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 ContainerOverrides)) {
return false;
}
ContainerOverrides other = (ContainerOverrides) obj;
return Objects.equals(vcpus(), other.vcpus()) && Objects.equals(memory(), other.memory())
&& hasCommand() == other.hasCommand() && Objects.equals(command(), other.command())
&& Objects.equals(instanceType(), other.instanceType()) && hasEnvironment() == other.hasEnvironment()
&& Objects.equals(environment(), other.environment())
&& hasResourceRequirements() == other.hasResourceRequirements()
&& Objects.equals(resourceRequirements(), other.resourceRequirements());
}
/**
* 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("ContainerOverrides").add("Vcpus", vcpus()).add("Memory", memory())
.add("Command", hasCommand() ? command() : null).add("InstanceType", instanceType())
.add("Environment", hasEnvironment() ? environment() : null)
.add("ResourceRequirements", hasResourceRequirements() ? resourceRequirements() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "vcpus":
return Optional.ofNullable(clazz.cast(vcpus()));
case "memory":
return Optional.ofNullable(clazz.cast(memory()));
case "command":
return Optional.ofNullable(clazz.cast(command()));
case "instanceType":
return Optional.ofNullable(clazz.cast(instanceType()));
case "environment":
return Optional.ofNullable(clazz.cast(environment()));
case "resourceRequirements":
return Optional.ofNullable(clazz.cast(resourceRequirements()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function