software.amazon.awssdk.services.ecs.model.NetworkBinding Maven / Gradle / Ivy
Show all versions of ecs 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.ecs.model;
import java.io.Serializable;
import java.util.Arrays;
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.Function;
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.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Details on the network bindings between a container and its host container instance. After a task reaches the
* RUNNING
status, manual and automatic host and container port assignments are visible in the
* networkBindings
section of DescribeTasks API responses.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class NetworkBinding implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField BIND_IP_FIELD = SdkField. builder(MarshallingType.STRING).memberName("bindIP")
.getter(getter(NetworkBinding::bindIP)).setter(setter(Builder::bindIP))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("bindIP").build()).build();
private static final SdkField CONTAINER_PORT_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("containerPort").getter(getter(NetworkBinding::containerPort)).setter(setter(Builder::containerPort))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("containerPort").build()).build();
private static final SdkField HOST_PORT_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("hostPort").getter(getter(NetworkBinding::hostPort)).setter(setter(Builder::hostPort))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("hostPort").build()).build();
private static final SdkField PROTOCOL_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("protocol").getter(getter(NetworkBinding::protocolAsString)).setter(setter(Builder::protocol))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("protocol").build()).build();
private static final SdkField CONTAINER_PORT_RANGE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("containerPortRange").getter(getter(NetworkBinding::containerPortRange))
.setter(setter(Builder::containerPortRange))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("containerPortRange").build())
.build();
private static final SdkField HOST_PORT_RANGE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("hostPortRange").getter(getter(NetworkBinding::hostPortRange)).setter(setter(Builder::hostPortRange))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("hostPortRange").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(BIND_IP_FIELD,
CONTAINER_PORT_FIELD, HOST_PORT_FIELD, PROTOCOL_FIELD, CONTAINER_PORT_RANGE_FIELD, HOST_PORT_RANGE_FIELD));
private static final long serialVersionUID = 1L;
private final String bindIP;
private final Integer containerPort;
private final Integer hostPort;
private final String protocol;
private final String containerPortRange;
private final String hostPortRange;
private NetworkBinding(BuilderImpl builder) {
this.bindIP = builder.bindIP;
this.containerPort = builder.containerPort;
this.hostPort = builder.hostPort;
this.protocol = builder.protocol;
this.containerPortRange = builder.containerPortRange;
this.hostPortRange = builder.hostPortRange;
}
/**
*
* The IP address that the container is bound to on the container instance.
*
*
* @return The IP address that the container is bound to on the container instance.
*/
public final String bindIP() {
return bindIP;
}
/**
*
* The port number on the container that's used with the network binding.
*
*
* @return The port number on the container that's used with the network binding.
*/
public final Integer containerPort() {
return containerPort;
}
/**
*
* The port number on the host that's used with the network binding.
*
*
* @return The port number on the host that's used with the network binding.
*/
public final Integer hostPort() {
return hostPort;
}
/**
*
* The protocol used for the network binding.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #protocol} will
* return {@link TransportProtocol#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #protocolAsString}.
*
*
* @return The protocol used for the network binding.
* @see TransportProtocol
*/
public final TransportProtocol protocol() {
return TransportProtocol.fromValue(protocol);
}
/**
*
* The protocol used for the network binding.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #protocol} will
* return {@link TransportProtocol#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #protocolAsString}.
*
*
* @return The protocol used for the network binding.
* @see TransportProtocol
*/
public final String protocolAsString() {
return protocol;
}
/**
*
* The port number range on the container that's bound to the dynamically mapped host port range.
*
*
* The following rules apply when you specify a containerPortRange
:
*
*
* -
*
* You must use either the bridge
network mode or the awsvpc
network mode.
*
*
* -
*
* This parameter is available for both the EC2 and Fargate launch types.
*
*
* -
*
* This parameter is available for both the Linux and Windows operating systems.
*
*
* -
*
* The container instance must have at least version 1.67.0 of the container agent and at least version 1.67.0-1 of
* the ecs-init
package
*
*
* -
*
* You can specify a maximum of 100 port ranges per container.
*
*
* -
*
* You do not specify a hostPortRange
. The value of the hostPortRange
is set as follows:
*
*
* -
*
* For containers in a task with the awsvpc
network mode, the hostPortRange
is set to the
* same value as the containerPortRange
. This is a static mapping strategy.
*
*
* -
*
* For containers in a task with the bridge
network mode, the Amazon ECS agent finds open host ports
* from the default ephemeral range and passes it to docker to bind them to the container ports.
*
*
*
*
* -
*
* The containerPortRange
valid values are between 1 and 65535.
*
*
* -
*
* A port can only be included in one port mapping per container.
*
*
* -
*
* You cannot specify overlapping port ranges.
*
*
* -
*
* The first port in the range must be less than last port in the range.
*
*
* -
*
* Docker recommends that you turn off the docker-proxy in the Docker daemon config file when you have a large
* number of ports.
*
*
* For more information, see Issue #11185 on the Github
* website.
*
*
* For information about how to turn off the docker-proxy in the Docker daemon config file, see Docker daemon in the Amazon ECS Developer Guide.
*
*
*
*
* You can call
* DescribeTasks
to view the hostPortRange
which are the host ports that are bound to
* the container ports.
*
*
* @return The port number range on the container that's bound to the dynamically mapped host port range.
*
* The following rules apply when you specify a containerPortRange
:
*
*
* -
*
* You must use either the bridge
network mode or the awsvpc
network mode.
*
*
* -
*
* This parameter is available for both the EC2 and Fargate launch types.
*
*
* -
*
* This parameter is available for both the Linux and Windows operating systems.
*
*
* -
*
* The container instance must have at least version 1.67.0 of the container agent and at least version
* 1.67.0-1 of the ecs-init
package
*
*
* -
*
* You can specify a maximum of 100 port ranges per container.
*
*
* -
*
* You do not specify a hostPortRange
. The value of the hostPortRange
is set as
* follows:
*
*
* -
*
* For containers in a task with the awsvpc
network mode, the hostPortRange
is set
* to the same value as the containerPortRange
. This is a static mapping strategy.
*
*
* -
*
* For containers in a task with the bridge
network mode, the Amazon ECS agent finds open host
* ports from the default ephemeral range and passes it to docker to bind them to the container ports.
*
*
*
*
* -
*
* The containerPortRange
valid values are between 1 and 65535.
*
*
* -
*
* A port can only be included in one port mapping per container.
*
*
* -
*
* You cannot specify overlapping port ranges.
*
*
* -
*
* The first port in the range must be less than last port in the range.
*
*
* -
*
* Docker recommends that you turn off the docker-proxy in the Docker daemon config file when you have a
* large number of ports.
*
*
* For more information, see Issue #11185 on the
* Github website.
*
*
* For information about how to turn off the docker-proxy in the Docker daemon config file, see Docker daemon in the Amazon ECS Developer Guide.
*
*
*
*
* You can call
* DescribeTasks
to view the hostPortRange
which are the host ports that are
* bound to the container ports.
*/
public final String containerPortRange() {
return containerPortRange;
}
/**
*
* The port number range on the host that's used with the network binding. This is assigned is assigned by Docker
* and delivered by the Amazon ECS agent.
*
*
* @return The port number range on the host that's used with the network binding. This is assigned is assigned by
* Docker and delivered by the Amazon ECS agent.
*/
public final String hostPortRange() {
return hostPortRange;
}
@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(bindIP());
hashCode = 31 * hashCode + Objects.hashCode(containerPort());
hashCode = 31 * hashCode + Objects.hashCode(hostPort());
hashCode = 31 * hashCode + Objects.hashCode(protocolAsString());
hashCode = 31 * hashCode + Objects.hashCode(containerPortRange());
hashCode = 31 * hashCode + Objects.hashCode(hostPortRange());
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 NetworkBinding)) {
return false;
}
NetworkBinding other = (NetworkBinding) obj;
return Objects.equals(bindIP(), other.bindIP()) && Objects.equals(containerPort(), other.containerPort())
&& Objects.equals(hostPort(), other.hostPort()) && Objects.equals(protocolAsString(), other.protocolAsString())
&& Objects.equals(containerPortRange(), other.containerPortRange())
&& Objects.equals(hostPortRange(), other.hostPortRange());
}
/**
* 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("NetworkBinding").add("BindIP", bindIP()).add("ContainerPort", containerPort())
.add("HostPort", hostPort()).add("Protocol", protocolAsString()).add("ContainerPortRange", containerPortRange())
.add("HostPortRange", hostPortRange()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "bindIP":
return Optional.ofNullable(clazz.cast(bindIP()));
case "containerPort":
return Optional.ofNullable(clazz.cast(containerPort()));
case "hostPort":
return Optional.ofNullable(clazz.cast(hostPort()));
case "protocol":
return Optional.ofNullable(clazz.cast(protocolAsString()));
case "containerPortRange":
return Optional.ofNullable(clazz.cast(containerPortRange()));
case "hostPortRange":
return Optional.ofNullable(clazz.cast(hostPortRange()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function