All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 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 getter(Function g) { return obj -> g.apply((ContainerOverrides) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* 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. *

*
* * @param vcpus * 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 Returns a reference to this object so that method calls can be chained together. */ Builder vcpus(Integer 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. *

* * @param memory * 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 Returns a reference to this object so that method calls can be chained together. */ Builder memory(Integer memory); /** *

* The command to send to the container that overrides the default command from the Docker image or the job * definition. *

* * @param command * The command to send to the container that overrides the default command from the Docker image or the * job definition. * @return Returns a reference to this object so that method calls can be chained together. */ Builder command(Collection command); /** *

* The command to send to the container that overrides the default command from the Docker image or the job * definition. *

* * @param command * The command to send to the container that overrides the default command from the Docker image or the * job definition. * @return Returns a reference to this object so that method calls can be chained together. */ Builder command(String... 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. *

*
* * @param instanceType * 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 Returns a reference to this object so that method calls can be chained together. */ Builder instanceType(String instanceType); /** *

* 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. *

*
* * @param environment * 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. *

* @return Returns a reference to this object so that method calls can be chained together. */ Builder environment(Collection environment); /** *

* 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. *

*
* * @param environment * 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. *

* @return Returns a reference to this object so that method calls can be chained together. */ Builder environment(KeyValuePair... environment); /** *

* 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. *

*
This is a convenience that creates an instance of the {@link List.Builder} avoiding the * need to create one manually via {@link List#builder()}. * * When the {@link Consumer} completes, {@link List.Builder#build()} is called immediately and its * result is passed to {@link #environment(List)}. * * @param environment * a consumer that will call methods on {@link List.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #environment(List) */ Builder environment(Consumer... environment); /** *

* 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. *

* * @param resourceRequirements * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder resourceRequirements(Collection resourceRequirements); /** *

* 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. *

* * @param resourceRequirements * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder resourceRequirements(ResourceRequirement... resourceRequirements); /** *

* 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. *

* This is a convenience that creates an instance of the {@link List.Builder} avoiding the * need to create one manually via {@link List#builder()}. * * When the {@link Consumer} completes, {@link List.Builder#build()} is called immediately * and its result is passed to {@link #resourceRequirements(List)}. * * @param resourceRequirements * a consumer that will call methods on {@link List.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #resourceRequirements(List) */ Builder resourceRequirements(Consumer... resourceRequirements); } static final class BuilderImpl implements Builder { private Integer vcpus; private Integer memory; private List command = DefaultSdkAutoConstructList.getInstance(); private String instanceType; private List environment = DefaultSdkAutoConstructList.getInstance(); private List resourceRequirements = DefaultSdkAutoConstructList.getInstance(); private BuilderImpl() { } private BuilderImpl(ContainerOverrides model) { vcpus(model.vcpus); memory(model.memory); command(model.command); instanceType(model.instanceType); environment(model.environment); resourceRequirements(model.resourceRequirements); } public final Integer getVcpus() { return vcpus; } @Override public final Builder vcpus(Integer vcpus) { this.vcpus = vcpus; return this; } public final void setVcpus(Integer vcpus) { this.vcpus = vcpus; } public final Integer getMemory() { return memory; } @Override public final Builder memory(Integer memory) { this.memory = memory; return this; } public final void setMemory(Integer memory) { this.memory = memory; } public final Collection getCommand() { if (command instanceof SdkAutoConstructList) { return null; } return command; } @Override public final Builder command(Collection command) { this.command = StringListCopier.copy(command); return this; } @Override @SafeVarargs public final Builder command(String... command) { command(Arrays.asList(command)); return this; } public final void setCommand(Collection command) { this.command = StringListCopier.copy(command); } public final String getInstanceType() { return instanceType; } @Override public final Builder instanceType(String instanceType) { this.instanceType = instanceType; return this; } public final void setInstanceType(String instanceType) { this.instanceType = instanceType; } public final Collection getEnvironment() { if (environment instanceof SdkAutoConstructList) { return null; } return environment != null ? environment.stream().map(KeyValuePair::toBuilder).collect(Collectors.toList()) : null; } @Override public final Builder environment(Collection environment) { this.environment = EnvironmentVariablesCopier.copy(environment); return this; } @Override @SafeVarargs public final Builder environment(KeyValuePair... environment) { environment(Arrays.asList(environment)); return this; } @Override @SafeVarargs public final Builder environment(Consumer... environment) { environment(Stream.of(environment).map(c -> KeyValuePair.builder().applyMutation(c).build()) .collect(Collectors.toList())); return this; } public final void setEnvironment(Collection environment) { this.environment = EnvironmentVariablesCopier.copyFromBuilder(environment); } public final Collection getResourceRequirements() { if (resourceRequirements instanceof SdkAutoConstructList) { return null; } return resourceRequirements != null ? resourceRequirements.stream().map(ResourceRequirement::toBuilder) .collect(Collectors.toList()) : null; } @Override public final Builder resourceRequirements(Collection resourceRequirements) { this.resourceRequirements = ResourceRequirementsCopier.copy(resourceRequirements); return this; } @Override @SafeVarargs public final Builder resourceRequirements(ResourceRequirement... resourceRequirements) { resourceRequirements(Arrays.asList(resourceRequirements)); return this; } @Override @SafeVarargs public final Builder resourceRequirements(Consumer... resourceRequirements) { resourceRequirements(Stream.of(resourceRequirements).map(c -> ResourceRequirement.builder().applyMutation(c).build()) .collect(Collectors.toList())); return this; } public final void setResourceRequirements(Collection resourceRequirements) { this.resourceRequirements = ResourceRequirementsCopier.copyFromBuilder(resourceRequirements); } @Override public ContainerOverrides build() { return new ContainerOverrides(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy