software.amazon.awssdk.services.batch.model.EksContainer Maven / Gradle / Ivy
Show all versions of batch 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.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;
/**
*
* EKS container properties are used in job definitions for Amazon EKS based job definitions to describe the properties
* for a container node in the pod that's launched as part of a job. This can't be specified for Amazon ECS based job
* definitions.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class EksContainer implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField NAME_FIELD = SdkField. builder(MarshallingType.STRING).memberName("name")
.getter(getter(EksContainer::name)).setter(setter(Builder::name))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("name").build()).build();
private static final SdkField IMAGE_FIELD = SdkField. builder(MarshallingType.STRING).memberName("image")
.getter(getter(EksContainer::image)).setter(setter(Builder::image))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("image").build()).build();
private static final SdkField IMAGE_PULL_POLICY_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("imagePullPolicy").getter(getter(EksContainer::imagePullPolicy)).setter(setter(Builder::imagePullPolicy))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("imagePullPolicy").build()).build();
private static final SdkField> COMMAND_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("command")
.getter(getter(EksContainer::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> ARGS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("args")
.getter(getter(EksContainer::args))
.setter(setter(Builder::args))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("args").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> ENV_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("env")
.getter(getter(EksContainer::env))
.setter(setter(Builder::env))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("env").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(EksContainerEnvironmentVariable::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField RESOURCES_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("resources")
.getter(getter(EksContainer::resources)).setter(setter(Builder::resources))
.constructor(EksContainerResourceRequirements::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("resources").build()).build();
private static final SdkField> VOLUME_MOUNTS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("volumeMounts")
.getter(getter(EksContainer::volumeMounts))
.setter(setter(Builder::volumeMounts))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("volumeMounts").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(EksContainerVolumeMount::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField SECURITY_CONTEXT_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("securityContext")
.getter(getter(EksContainer::securityContext)).setter(setter(Builder::securityContext))
.constructor(EksContainerSecurityContext::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("securityContext").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(NAME_FIELD, IMAGE_FIELD,
IMAGE_PULL_POLICY_FIELD, COMMAND_FIELD, ARGS_FIELD, ENV_FIELD, RESOURCES_FIELD, VOLUME_MOUNTS_FIELD,
SECURITY_CONTEXT_FIELD));
private static final long serialVersionUID = 1L;
private final String name;
private final String image;
private final String imagePullPolicy;
private final List command;
private final List args;
private final List env;
private final EksContainerResourceRequirements resources;
private final List volumeMounts;
private final EksContainerSecurityContext securityContext;
private EksContainer(BuilderImpl builder) {
this.name = builder.name;
this.image = builder.image;
this.imagePullPolicy = builder.imagePullPolicy;
this.command = builder.command;
this.args = builder.args;
this.env = builder.env;
this.resources = builder.resources;
this.volumeMounts = builder.volumeMounts;
this.securityContext = builder.securityContext;
}
/**
*
* The name of the container. If the name isn't specified, the default name "Default
" is used. Each
* container in a pod must have a unique name.
*
*
* @return The name of the container. If the name isn't specified, the default name "Default
" is used.
* Each container in a pod must have a unique name.
*/
public final String name() {
return name;
}
/**
*
* The Docker image used to start the container.
*
*
* @return The Docker image used to start the container.
*/
public final String image() {
return image;
}
/**
*
* The image pull policy for the container. Supported values are Always
, IfNotPresent
, and
* Never
. This parameter defaults to IfNotPresent
. However, if the :latest
* tag is specified, it defaults to Always
. For more information, see Updating images in the
* Kubernetes documentation.
*
*
* @return The image pull policy for the container. Supported values are Always
,
* IfNotPresent
, and Never
. This parameter defaults to IfNotPresent
.
* However, if the :latest
tag is specified, it defaults to Always
. For more
* information, see Updating images in the
* Kubernetes documentation.
*/
public final String imagePullPolicy() {
return imagePullPolicy;
}
/**
* For responses, this returns true if the service returned a value for the Command property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasCommand() {
return command != null && !(command instanceof SdkAutoConstructList);
}
/**
*
* The entrypoint for the container. This isn't run within a shell. If this isn't specified, the
* ENTRYPOINT
of the container image is used. Environment variable references are expanded using the
* container's environment.
*
*
* If the referenced environment variable doesn't exist, the reference in the command isn't changed. For example, if
* the reference is to "$(NAME1)
" and the NAME1
environment variable doesn't exist, the
* command string will remain "$(NAME1)
." $$
is replaced with $
and the
* resulting string isn't expanded. For example, $$(VAR_NAME)
will be passed as
* $(VAR_NAME)
whether or not the VAR_NAME
environment variable exists. The entrypoint
* can't be updated. For more information, see ENTRYPOINT in the Dockerfile
* reference and Define a
* command and arguments for a container and Entrypoint
* in the Kubernetes documentation.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasCommand} method.
*
*
* @return The entrypoint for the container. This isn't run within a shell. If this isn't specified, the
* ENTRYPOINT
of the container image is used. Environment variable references are expanded
* using the container's environment.
*
* If the referenced environment variable doesn't exist, the reference in the command isn't changed. For
* example, if the reference is to "$(NAME1)
" and the NAME1
environment variable
* doesn't exist, the command string will remain "$(NAME1)
." $$
is replaced with
* $
and the resulting string isn't expanded. For example, $$(VAR_NAME)
will be
* passed as $(VAR_NAME)
whether or not the VAR_NAME
environment variable exists.
* The entrypoint can't be updated. For more information, see ENTRYPOINT in the Dockerfile
* reference and Define
* a command and arguments for a container and Entrypoint in the Kubernetes documentation.
*/
public final List command() {
return command;
}
/**
* For responses, this returns true if the service returned a value for the Args property. This DOES NOT check that
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
* if a value for the property was specified in the request builder, and false if a value was not specified.
*/
public final boolean hasArgs() {
return args != null && !(args instanceof SdkAutoConstructList);
}
/**
*
* An array of arguments to the entrypoint. If this isn't specified, the CMD
of the container image is
* used. This corresponds to the args
member in the Entrypoint
* portion of the Pod
* in Kubernetes. Environment variable references are expanded using the container's environment.
*
*
* If the referenced environment variable doesn't exist, the reference in the command isn't changed. For example, if
* the reference is to "$(NAME1)
" and the NAME1
environment variable doesn't exist, the
* command string will remain "$(NAME1)
." $$
is replaced with $
, and the
* resulting string isn't expanded. For example, $$(VAR_NAME)
is passed as $(VAR_NAME)
* whether or not the VAR_NAME
environment variable exists. For more information, see Dockerfile reference: CMD and Define a
* command and arguments for a pod in the Kubernetes documentation.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasArgs} method.
*
*
* @return An array of arguments to the entrypoint. If this isn't specified, the CMD
of the container
* image is used. This corresponds to the args
member in the Entrypoint portion of the Pod in
* Kubernetes. Environment variable references are expanded using the container's environment.
*
* If the referenced environment variable doesn't exist, the reference in the command isn't changed. For
* example, if the reference is to "$(NAME1)
" and the NAME1
environment variable
* doesn't exist, the command string will remain "$(NAME1)
." $$
is replaced with
* $
, and the resulting string isn't expanded. For example, $$(VAR_NAME)
is passed
* as $(VAR_NAME)
whether or not the VAR_NAME
environment variable exists. For
* more information, see Dockerfile
* reference: CMD and Define
* a command and arguments for a pod in the Kubernetes documentation.
*/
public final List args() {
return args;
}
/**
* For responses, this returns true if the service returned a value for the Env property. This DOES NOT check that
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
* if a value for the property was specified in the request builder, and false if a value was not specified.
*/
public final boolean hasEnv() {
return env != null && !(env instanceof SdkAutoConstructList);
}
/**
*
* The environment variables to pass to a container.
*
*
*
* Environment variables cannot start with "AWS_BATCH
". This naming convention is reserved for
* variables that Batch sets.
*
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasEnv} method.
*
*
* @return The environment variables to pass to a container.
*
* Environment variables cannot start with "AWS_BATCH
". This naming convention is reserved for
* variables that Batch sets.
*
*/
public final List env() {
return env;
}
/**
*
* The type and amount of resources to assign to a container. The supported resources include memory
,
* cpu
, and nvidia.com/gpu
. For more information, see Resource management for
* pods and containers in the Kubernetes documentation.
*
*
* @return The type and amount of resources to assign to a container. The supported resources include
* memory
, cpu
, and nvidia.com/gpu
. For more information, see Resource management
* for pods and containers in the Kubernetes documentation.
*/
public final EksContainerResourceRequirements resources() {
return resources;
}
/**
* For responses, this returns true if the service returned a value for the VolumeMounts property. This DOES NOT
* check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasVolumeMounts() {
return volumeMounts != null && !(volumeMounts instanceof SdkAutoConstructList);
}
/**
*
* The volume mounts for the container. Batch supports emptyDir
, hostPath
, and
* secret
volume types. For more information about volumes and volume mounts in Kubernetes, see Volumes in the Kubernetes documentation.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasVolumeMounts} method.
*
*
* @return The volume mounts for the container. Batch supports emptyDir
, hostPath
, and
* secret
volume types. For more information about volumes and volume mounts in Kubernetes, see
* Volumes in the Kubernetes
* documentation.
*/
public final List volumeMounts() {
return volumeMounts;
}
/**
*
* The security context for a job. For more information, see Configure a security context
* for a pod or container in the Kubernetes documentation.
*
*
* @return The security context for a job. For more information, see Configure a security
* context for a pod or container in the Kubernetes documentation.
*/
public final EksContainerSecurityContext securityContext() {
return securityContext;
}
@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(name());
hashCode = 31 * hashCode + Objects.hashCode(image());
hashCode = 31 * hashCode + Objects.hashCode(imagePullPolicy());
hashCode = 31 * hashCode + Objects.hashCode(hasCommand() ? command() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasArgs() ? args() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasEnv() ? env() : null);
hashCode = 31 * hashCode + Objects.hashCode(resources());
hashCode = 31 * hashCode + Objects.hashCode(hasVolumeMounts() ? volumeMounts() : null);
hashCode = 31 * hashCode + Objects.hashCode(securityContext());
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 EksContainer)) {
return false;
}
EksContainer other = (EksContainer) obj;
return Objects.equals(name(), other.name()) && Objects.equals(image(), other.image())
&& Objects.equals(imagePullPolicy(), other.imagePullPolicy()) && hasCommand() == other.hasCommand()
&& Objects.equals(command(), other.command()) && hasArgs() == other.hasArgs()
&& Objects.equals(args(), other.args()) && hasEnv() == other.hasEnv() && Objects.equals(env(), other.env())
&& Objects.equals(resources(), other.resources()) && hasVolumeMounts() == other.hasVolumeMounts()
&& Objects.equals(volumeMounts(), other.volumeMounts())
&& Objects.equals(securityContext(), other.securityContext());
}
/**
* 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("EksContainer").add("Name", name()).add("Image", image())
.add("ImagePullPolicy", imagePullPolicy()).add("Command", hasCommand() ? command() : null)
.add("Args", hasArgs() ? args() : null).add("Env", hasEnv() ? env() : null).add("Resources", resources())
.add("VolumeMounts", hasVolumeMounts() ? volumeMounts() : null).add("SecurityContext", securityContext()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "name":
return Optional.ofNullable(clazz.cast(name()));
case "image":
return Optional.ofNullable(clazz.cast(image()));
case "imagePullPolicy":
return Optional.ofNullable(clazz.cast(imagePullPolicy()));
case "command":
return Optional.ofNullable(clazz.cast(command()));
case "args":
return Optional.ofNullable(clazz.cast(args()));
case "env":
return Optional.ofNullable(clazz.cast(env()));
case "resources":
return Optional.ofNullable(clazz.cast(resources()));
case "volumeMounts":
return Optional.ofNullable(clazz.cast(volumeMounts()));
case "securityContext":
return Optional.ofNullable(clazz.cast(securityContext()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function