software.amazon.awssdk.services.batch.model.TaskContainerOverrides 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;
/**
*
* The overrides that should be sent to a container.
*
*
* For information about using Batch overrides when you connect event sources to targets, see BatchContainerOverrides.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class TaskContainerOverrides implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField> COMMAND_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("command")
.getter(getter(TaskContainerOverrides::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> ENVIRONMENT_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("environment")
.getter(getter(TaskContainerOverrides::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 NAME_FIELD = SdkField. builder(MarshallingType.STRING).memberName("name")
.getter(getter(TaskContainerOverrides::name)).setter(setter(Builder::name))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("name").build()).build();
private static final SdkField> RESOURCE_REQUIREMENTS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("resourceRequirements")
.getter(getter(TaskContainerOverrides::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(COMMAND_FIELD,
ENVIRONMENT_FIELD, NAME_FIELD, RESOURCE_REQUIREMENTS_FIELD));
private static final long serialVersionUID = 1L;
private final List command;
private final List environment;
private final String name;
private final List resourceRequirements;
private TaskContainerOverrides(BuilderImpl builder) {
this.command = builder.command;
this.environment = builder.environment;
this.name = builder.name;
this.resourceRequirements = builder.resourceRequirements;
}
/**
* 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 command to send to the container that overrides the default command from the Docker image or the job
* definition.
*
*
*
* This parameter can't contain an empty string.
*
*
*
* 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 command to send to the container that overrides the default command from the Docker image or the job
* definition.
*
* This parameter can't contain an empty string.
*
*/
public final List command() {
return command;
}
/**
* For responses, this returns true if the service returned a value for the Environment 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 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 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 #hasEnvironment} method.
*
*
* @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 cannot start with AWS_BATCH
. This naming convention is reserved for
* variables that Batch sets.
*
*/
public final List environment() {
return environment;
}
/**
*
* A pointer to the container that you want to override. The container's name provides a unique identifier for the
* container being used.
*
*
* @return A pointer to the container that you want to override. The container's name provides a unique identifier
* for the container being used.
*/
public final String name() {
return name;
}
/**
* For responses, this returns true if the service returned a value for the ResourceRequirements 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 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.
*
*
* 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 #hasResourceRequirements} method.
*
*
* @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(hasCommand() ? command() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasEnvironment() ? environment() : null);
hashCode = 31 * hashCode + Objects.hashCode(name());
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 TaskContainerOverrides)) {
return false;
}
TaskContainerOverrides other = (TaskContainerOverrides) obj;
return hasCommand() == other.hasCommand() && Objects.equals(command(), other.command())
&& hasEnvironment() == other.hasEnvironment() && Objects.equals(environment(), other.environment())
&& Objects.equals(name(), other.name()) && 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("TaskContainerOverrides").add("Command", hasCommand() ? command() : null)
.add("Environment", hasEnvironment() ? environment() : null).add("Name", name())
.add("ResourceRequirements", hasResourceRequirements() ? resourceRequirements() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "command":
return Optional.ofNullable(clazz.cast(command()));
case "environment":
return Optional.ofNullable(clazz.cast(environment()));
case "name":
return Optional.ofNullable(clazz.cast(name()));
case "resourceRequirements":
return Optional.ofNullable(clazz.cast(resourceRequirements()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function