mirror of https://github.com/grpc/grpc-java.git
xds: migrate EnvoyServerProtoData.Listener data types to AutoValue
This commit is contained in:
parent
da617e6ecd
commit
f987de7497
|
|
@ -111,7 +111,6 @@ import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
@ -398,7 +397,7 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FilterChain> filterChains = new ArrayList<>();
|
ImmutableList.Builder<FilterChain> filterChains = ImmutableList.builder();
|
||||||
Set<FilterChainMatch> uniqueSet = new HashSet<>();
|
Set<FilterChainMatch> uniqueSet = new HashSet<>();
|
||||||
for (io.envoyproxy.envoy.config.listener.v3.FilterChain fc : proto.getFilterChainsList()) {
|
for (io.envoyproxy.envoy.config.listener.v3.FilterChain fc : proto.getFilterChainsList()) {
|
||||||
filterChains.add(
|
filterChains.add(
|
||||||
|
|
@ -412,8 +411,8 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
null, certProviderInstances, parseHttpFilter);
|
null, certProviderInstances, parseHttpFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EnvoyServerProtoData.Listener(
|
return EnvoyServerProtoData.Listener.create(
|
||||||
proto.getName(), address, Collections.unmodifiableList(filterChains), defaultFilterChain);
|
proto.getName(), address, filterChains.build(), defaultFilterChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|
@ -470,7 +469,7 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
|
|
||||||
FilterChainMatch filterChainMatch = parseFilterChainMatch(proto.getFilterChainMatch());
|
FilterChainMatch filterChainMatch = parseFilterChainMatch(proto.getFilterChainMatch());
|
||||||
checkForUniqueness(uniqueSet, filterChainMatch);
|
checkForUniqueness(uniqueSet, filterChainMatch);
|
||||||
return new FilterChain(
|
return FilterChain.create(
|
||||||
proto.getName(),
|
proto.getName(),
|
||||||
filterChainMatch,
|
filterChainMatch,
|
||||||
httpConnectionManager,
|
httpConnectionManager,
|
||||||
|
|
@ -673,18 +672,18 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
|
|
||||||
private static List<FilterChainMatch> expandOnPrefixRange(FilterChainMatch filterChainMatch) {
|
private static List<FilterChainMatch> expandOnPrefixRange(FilterChainMatch filterChainMatch) {
|
||||||
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
||||||
if (filterChainMatch.getPrefixRanges().isEmpty()) {
|
if (filterChainMatch.prefixRanges().isEmpty()) {
|
||||||
expandedList.add(filterChainMatch);
|
expandedList.add(filterChainMatch);
|
||||||
} else {
|
} else {
|
||||||
for (EnvoyServerProtoData.CidrRange cidrRange : filterChainMatch.getPrefixRanges()) {
|
for (EnvoyServerProtoData.CidrRange cidrRange : filterChainMatch.prefixRanges()) {
|
||||||
expandedList.add(new FilterChainMatch(filterChainMatch.getDestinationPort(),
|
expandedList.add(FilterChainMatch.create(filterChainMatch.destinationPort(),
|
||||||
Arrays.asList(cidrRange),
|
ImmutableList.of(cidrRange),
|
||||||
Collections.unmodifiableList(filterChainMatch.getApplicationProtocols()),
|
filterChainMatch.applicationProtocols(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePrefixRanges()),
|
filterChainMatch.sourcePrefixRanges(),
|
||||||
filterChainMatch.getConnectionSourceType(),
|
filterChainMatch.connectionSourceType(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePorts()),
|
filterChainMatch.sourcePorts(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getServerNames()),
|
filterChainMatch.serverNames(),
|
||||||
filterChainMatch.getTransportProtocol()));
|
filterChainMatch.transportProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return expandedList;
|
return expandedList;
|
||||||
|
|
@ -694,18 +693,18 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
Collection<FilterChainMatch> set) {
|
Collection<FilterChainMatch> set) {
|
||||||
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
||||||
for (FilterChainMatch filterChainMatch : set) {
|
for (FilterChainMatch filterChainMatch : set) {
|
||||||
if (filterChainMatch.getApplicationProtocols().isEmpty()) {
|
if (filterChainMatch.applicationProtocols().isEmpty()) {
|
||||||
expandedList.add(filterChainMatch);
|
expandedList.add(filterChainMatch);
|
||||||
} else {
|
} else {
|
||||||
for (String applicationProtocol : filterChainMatch.getApplicationProtocols()) {
|
for (String applicationProtocol : filterChainMatch.applicationProtocols()) {
|
||||||
expandedList.add(new FilterChainMatch(filterChainMatch.getDestinationPort(),
|
expandedList.add(FilterChainMatch.create(filterChainMatch.destinationPort(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getPrefixRanges()),
|
filterChainMatch.prefixRanges(),
|
||||||
Arrays.asList(applicationProtocol),
|
ImmutableList.of(applicationProtocol),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePrefixRanges()),
|
filterChainMatch.sourcePrefixRanges(),
|
||||||
filterChainMatch.getConnectionSourceType(),
|
filterChainMatch.connectionSourceType(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePorts()),
|
filterChainMatch.sourcePorts(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getServerNames()),
|
filterChainMatch.serverNames(),
|
||||||
filterChainMatch.getTransportProtocol()));
|
filterChainMatch.transportProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -716,18 +715,18 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
Collection<FilterChainMatch> set) {
|
Collection<FilterChainMatch> set) {
|
||||||
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
||||||
for (FilterChainMatch filterChainMatch : set) {
|
for (FilterChainMatch filterChainMatch : set) {
|
||||||
if (filterChainMatch.getSourcePrefixRanges().isEmpty()) {
|
if (filterChainMatch.sourcePrefixRanges().isEmpty()) {
|
||||||
expandedList.add(filterChainMatch);
|
expandedList.add(filterChainMatch);
|
||||||
} else {
|
} else {
|
||||||
for (EnvoyServerProtoData.CidrRange cidrRange : filterChainMatch.getSourcePrefixRanges()) {
|
for (EnvoyServerProtoData.CidrRange cidrRange : filterChainMatch.sourcePrefixRanges()) {
|
||||||
expandedList.add(new FilterChainMatch(filterChainMatch.getDestinationPort(),
|
expandedList.add(FilterChainMatch.create(filterChainMatch.destinationPort(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getPrefixRanges()),
|
filterChainMatch.prefixRanges(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getApplicationProtocols()),
|
filterChainMatch.applicationProtocols(),
|
||||||
Arrays.asList(cidrRange),
|
ImmutableList.of(cidrRange),
|
||||||
filterChainMatch.getConnectionSourceType(),
|
filterChainMatch.connectionSourceType(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePorts()),
|
filterChainMatch.sourcePorts(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getServerNames()),
|
filterChainMatch.serverNames(),
|
||||||
filterChainMatch.getTransportProtocol()));
|
filterChainMatch.transportProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -737,18 +736,18 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
private static List<FilterChainMatch> expandOnSourcePorts(Collection<FilterChainMatch> set) {
|
private static List<FilterChainMatch> expandOnSourcePorts(Collection<FilterChainMatch> set) {
|
||||||
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
||||||
for (FilterChainMatch filterChainMatch : set) {
|
for (FilterChainMatch filterChainMatch : set) {
|
||||||
if (filterChainMatch.getSourcePorts().isEmpty()) {
|
if (filterChainMatch.sourcePorts().isEmpty()) {
|
||||||
expandedList.add(filterChainMatch);
|
expandedList.add(filterChainMatch);
|
||||||
} else {
|
} else {
|
||||||
for (Integer sourcePort : filterChainMatch.getSourcePorts()) {
|
for (Integer sourcePort : filterChainMatch.sourcePorts()) {
|
||||||
expandedList.add(new FilterChainMatch(filterChainMatch.getDestinationPort(),
|
expandedList.add(FilterChainMatch.create(filterChainMatch.destinationPort(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getPrefixRanges()),
|
filterChainMatch.prefixRanges(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getApplicationProtocols()),
|
filterChainMatch.applicationProtocols(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePrefixRanges()),
|
filterChainMatch.sourcePrefixRanges(),
|
||||||
filterChainMatch.getConnectionSourceType(),
|
filterChainMatch.connectionSourceType(),
|
||||||
Arrays.asList(sourcePort),
|
ImmutableList.of(sourcePort),
|
||||||
Collections.unmodifiableList(filterChainMatch.getServerNames()),
|
filterChainMatch.serverNames(),
|
||||||
filterChainMatch.getTransportProtocol()));
|
filterChainMatch.transportProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -758,18 +757,18 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
private static List<FilterChainMatch> expandOnServerNames(Collection<FilterChainMatch> set) {
|
private static List<FilterChainMatch> expandOnServerNames(Collection<FilterChainMatch> set) {
|
||||||
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
ArrayList<FilterChainMatch> expandedList = new ArrayList<>();
|
||||||
for (FilterChainMatch filterChainMatch : set) {
|
for (FilterChainMatch filterChainMatch : set) {
|
||||||
if (filterChainMatch.getServerNames().isEmpty()) {
|
if (filterChainMatch.serverNames().isEmpty()) {
|
||||||
expandedList.add(filterChainMatch);
|
expandedList.add(filterChainMatch);
|
||||||
} else {
|
} else {
|
||||||
for (String serverName : filterChainMatch.getServerNames()) {
|
for (String serverName : filterChainMatch.serverNames()) {
|
||||||
expandedList.add(new FilterChainMatch(filterChainMatch.getDestinationPort(),
|
expandedList.add(FilterChainMatch.create(filterChainMatch.destinationPort(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getPrefixRanges()),
|
filterChainMatch.prefixRanges(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getApplicationProtocols()),
|
filterChainMatch.applicationProtocols(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePrefixRanges()),
|
filterChainMatch.sourcePrefixRanges(),
|
||||||
filterChainMatch.getConnectionSourceType(),
|
filterChainMatch.connectionSourceType(),
|
||||||
Collections.unmodifiableList(filterChainMatch.getSourcePorts()),
|
filterChainMatch.sourcePorts(),
|
||||||
Arrays.asList(serverName),
|
ImmutableList.of(serverName),
|
||||||
filterChainMatch.getTransportProtocol()));
|
filterChainMatch.transportProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -779,16 +778,17 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
private static FilterChainMatch parseFilterChainMatch(
|
private static FilterChainMatch parseFilterChainMatch(
|
||||||
io.envoyproxy.envoy.config.listener.v3.FilterChainMatch proto)
|
io.envoyproxy.envoy.config.listener.v3.FilterChainMatch proto)
|
||||||
throws ResourceInvalidException {
|
throws ResourceInvalidException {
|
||||||
List<CidrRange> prefixRanges = new ArrayList<>();
|
ImmutableList.Builder<CidrRange> prefixRanges = ImmutableList.builder();
|
||||||
List<CidrRange> sourcePrefixRanges = new ArrayList<>();
|
ImmutableList.Builder<CidrRange> sourcePrefixRanges = ImmutableList.builder();
|
||||||
try {
|
try {
|
||||||
for (io.envoyproxy.envoy.config.core.v3.CidrRange range : proto.getPrefixRangesList()) {
|
for (io.envoyproxy.envoy.config.core.v3.CidrRange range : proto.getPrefixRangesList()) {
|
||||||
prefixRanges.add(new CidrRange(range.getAddressPrefix(), range.getPrefixLen().getValue()));
|
prefixRanges.add(
|
||||||
|
CidrRange.create(range.getAddressPrefix(), range.getPrefixLen().getValue()));
|
||||||
}
|
}
|
||||||
for (io.envoyproxy.envoy.config.core.v3.CidrRange range
|
for (io.envoyproxy.envoy.config.core.v3.CidrRange range
|
||||||
: proto.getSourcePrefixRangesList()) {
|
: proto.getSourcePrefixRangesList()) {
|
||||||
sourcePrefixRanges.add(
|
sourcePrefixRanges.add(
|
||||||
new CidrRange(range.getAddressPrefix(), range.getPrefixLen().getValue()));
|
CidrRange.create(range.getAddressPrefix(), range.getPrefixLen().getValue()));
|
||||||
}
|
}
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw new ResourceInvalidException("Failed to create CidrRange", e);
|
throw new ResourceInvalidException("Failed to create CidrRange", e);
|
||||||
|
|
@ -807,14 +807,14 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
|
||||||
default:
|
default:
|
||||||
throw new ResourceInvalidException("Unknown source-type: " + proto.getSourceType());
|
throw new ResourceInvalidException("Unknown source-type: " + proto.getSourceType());
|
||||||
}
|
}
|
||||||
return new FilterChainMatch(
|
return FilterChainMatch.create(
|
||||||
proto.getDestinationPort().getValue(),
|
proto.getDestinationPort().getValue(),
|
||||||
prefixRanges,
|
prefixRanges.build(),
|
||||||
proto.getApplicationProtocolsList(),
|
ImmutableList.copyOf(proto.getApplicationProtocolsList()),
|
||||||
sourcePrefixRanges,
|
sourcePrefixRanges.build(),
|
||||||
sourceType,
|
sourceType,
|
||||||
proto.getSourcePortsList(),
|
ImmutableList.copyOf(proto.getSourcePortsList()),
|
||||||
proto.getServerNamesList(),
|
ImmutableList.copyOf(proto.getServerNamesList()),
|
||||||
proto.getTransportProtocol());
|
proto.getTransportProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,14 @@
|
||||||
|
|
||||||
package io.grpc.xds;
|
package io.grpc.xds;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.collect.ImmutableList;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
import io.grpc.Internal;
|
import io.grpc.Internal;
|
||||||
import io.grpc.xds.internal.sds.SslContextProviderSupplier;
|
import io.grpc.xds.internal.sds.SslContextProviderSupplier;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -142,47 +139,16 @@ public final class EnvoyServerProtoData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class CidrRange {
|
@AutoValue
|
||||||
private final InetAddress addressPrefix;
|
abstract static class CidrRange {
|
||||||
private final int prefixLen;
|
|
||||||
|
|
||||||
CidrRange(String addressPrefix, int prefixLen) throws UnknownHostException {
|
abstract InetAddress addressPrefix();
|
||||||
this.addressPrefix = InetAddress.getByName(addressPrefix);
|
|
||||||
this.prefixLen = prefixLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getAddressPrefix() {
|
abstract int prefixLen();
|
||||||
return addressPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPrefixLen() {
|
static CidrRange create(String addressPrefix, int prefixLen) throws UnknownHostException {
|
||||||
return prefixLen;
|
return new AutoValue_EnvoyServerProtoData_CidrRange(
|
||||||
}
|
InetAddress.getByName(addressPrefix), prefixLen);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
CidrRange cidrRange = (CidrRange) o;
|
|
||||||
return prefixLen == cidrRange.prefixLen
|
|
||||||
&& java.util.Objects.equals(addressPrefix, cidrRange.addressPrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return java.util.Objects.hash(addressPrefix, prefixLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "CidrRange{"
|
|
||||||
+ "addressPrefix='" + addressPrefix + '\''
|
|
||||||
+ ", prefixLen=" + prefixLen
|
|
||||||
+ '}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,259 +167,91 @@ public final class EnvoyServerProtoData {
|
||||||
* Corresponds to Envoy proto message
|
* Corresponds to Envoy proto message
|
||||||
* {@link io.envoyproxy.envoy.api.v2.listener.FilterChainMatch}.
|
* {@link io.envoyproxy.envoy.api.v2.listener.FilterChainMatch}.
|
||||||
*/
|
*/
|
||||||
static final class FilterChainMatch {
|
@AutoValue
|
||||||
private final int destinationPort;
|
abstract static class FilterChainMatch {
|
||||||
private final List<CidrRange> prefixRanges;
|
|
||||||
private final List<String> applicationProtocols;
|
|
||||||
private final List<CidrRange> sourcePrefixRanges;
|
|
||||||
private final ConnectionSourceType sourceType;
|
|
||||||
private final List<Integer> sourcePorts;
|
|
||||||
private final List<String> serverNames;
|
|
||||||
private final String transportProtocol;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
abstract int destinationPort();
|
||||||
FilterChainMatch(
|
|
||||||
int destinationPort,
|
|
||||||
List<CidrRange> prefixRanges,
|
|
||||||
List<String> applicationProtocols,
|
|
||||||
List<CidrRange> sourcePrefixRanges,
|
|
||||||
ConnectionSourceType sourceType,
|
|
||||||
List<Integer> sourcePorts,
|
|
||||||
List<String> serverNames,
|
|
||||||
String transportProtocol) {
|
|
||||||
this.destinationPort = destinationPort;
|
|
||||||
this.prefixRanges = Collections.unmodifiableList(prefixRanges);
|
|
||||||
this.applicationProtocols = Collections.unmodifiableList(applicationProtocols);
|
|
||||||
this.sourcePrefixRanges = sourcePrefixRanges;
|
|
||||||
this.sourceType = sourceType;
|
|
||||||
this.sourcePorts = sourcePorts;
|
|
||||||
this.serverNames = Collections.unmodifiableList(serverNames);
|
|
||||||
this.transportProtocol = transportProtocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDestinationPort() {
|
abstract ImmutableList<CidrRange> prefixRanges();
|
||||||
return destinationPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CidrRange> getPrefixRanges() {
|
abstract ImmutableList<String> applicationProtocols();
|
||||||
return prefixRanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getApplicationProtocols() {
|
abstract ImmutableList<CidrRange> sourcePrefixRanges();
|
||||||
return applicationProtocols;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CidrRange> getSourcePrefixRanges() {
|
abstract ConnectionSourceType connectionSourceType();
|
||||||
return sourcePrefixRanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionSourceType getConnectionSourceType() {
|
abstract ImmutableList<Integer> sourcePorts();
|
||||||
return sourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getSourcePorts() {
|
abstract ImmutableList<String> serverNames();
|
||||||
return sourcePorts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getServerNames() {
|
abstract String transportProtocol();
|
||||||
return serverNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransportProtocol() {
|
public static FilterChainMatch create(int destinationPort,
|
||||||
return transportProtocol;
|
ImmutableList<CidrRange> prefixRanges,
|
||||||
}
|
ImmutableList<String> applicationProtocols, ImmutableList<CidrRange> sourcePrefixRanges,
|
||||||
|
ConnectionSourceType connectionSourceType, ImmutableList<Integer> sourcePorts,
|
||||||
@Override
|
ImmutableList<String> serverNames, String transportProtocol) {
|
||||||
public boolean equals(Object o) {
|
return new AutoValue_EnvoyServerProtoData_FilterChainMatch(
|
||||||
if (this == o) {
|
destinationPort, prefixRanges, applicationProtocols, sourcePrefixRanges,
|
||||||
return true;
|
connectionSourceType, sourcePorts, serverNames, transportProtocol);
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
FilterChainMatch that = (FilterChainMatch) o;
|
|
||||||
return destinationPort == that.destinationPort
|
|
||||||
&& Objects.equals(prefixRanges, that.prefixRanges)
|
|
||||||
&& Objects.equals(applicationProtocols, that.applicationProtocols)
|
|
||||||
&& Objects.equals(sourcePrefixRanges, that.sourcePrefixRanges)
|
|
||||||
&& sourceType == that.sourceType
|
|
||||||
&& Objects.equals(sourcePorts, that.sourcePorts)
|
|
||||||
&& Objects.equals(serverNames, that.serverNames)
|
|
||||||
&& Objects.equals(transportProtocol, that.transportProtocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(
|
|
||||||
destinationPort,
|
|
||||||
prefixRanges,
|
|
||||||
applicationProtocols,
|
|
||||||
sourcePrefixRanges,
|
|
||||||
sourceType,
|
|
||||||
sourcePorts,
|
|
||||||
serverNames,
|
|
||||||
transportProtocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return MoreObjects.toStringHelper(this)
|
|
||||||
.add("destinationPort", destinationPort)
|
|
||||||
.add("prefixRanges", prefixRanges)
|
|
||||||
.add("applicationProtocols", applicationProtocols)
|
|
||||||
.add("sourcePrefixRanges", sourcePrefixRanges)
|
|
||||||
.add("sourceType", sourceType)
|
|
||||||
.add("sourcePorts", sourcePorts)
|
|
||||||
.add("serverNames", serverNames)
|
|
||||||
.add("transportProtocol", transportProtocol)
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Corresponds to Envoy proto message {@link io.envoyproxy.envoy.api.v2.listener.FilterChain}.
|
* Corresponds to Envoy proto message {@link io.envoyproxy.envoy.api.v2.listener.FilterChain}.
|
||||||
*/
|
*/
|
||||||
static final class FilterChain {
|
@AutoValue
|
||||||
// possibly empty
|
abstract static class FilterChain {
|
||||||
private final String name;
|
|
||||||
// TODO(sanjaypujare): flatten structure by moving FilterChainMatch class members here.
|
|
||||||
private final FilterChainMatch filterChainMatch;
|
|
||||||
private final HttpConnectionManager httpConnectionManager;
|
|
||||||
@Nullable
|
|
||||||
private final SslContextProviderSupplier sslContextProviderSupplier;
|
|
||||||
|
|
||||||
FilterChain(
|
// possibly empty
|
||||||
|
abstract String name();
|
||||||
|
|
||||||
|
// TODO(sanjaypujare): flatten structure by moving FilterChainMatch class members here.
|
||||||
|
abstract FilterChainMatch filterChainMatch();
|
||||||
|
|
||||||
|
abstract HttpConnectionManager httpConnectionManager();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
abstract SslContextProviderSupplier sslContextProviderSupplier();
|
||||||
|
|
||||||
|
static FilterChain create(
|
||||||
String name,
|
String name,
|
||||||
FilterChainMatch filterChainMatch,
|
FilterChainMatch filterChainMatch,
|
||||||
HttpConnectionManager httpConnectionManager,
|
HttpConnectionManager httpConnectionManager,
|
||||||
@Nullable DownstreamTlsContext downstreamTlsContext,
|
@Nullable DownstreamTlsContext downstreamTlsContext,
|
||||||
TlsContextManager tlsContextManager) {
|
TlsContextManager tlsContextManager) {
|
||||||
SslContextProviderSupplier sslContextProviderSupplier1 = downstreamTlsContext == null ? null
|
SslContextProviderSupplier sslContextProviderSupplier =
|
||||||
: new SslContextProviderSupplier(downstreamTlsContext, tlsContextManager);
|
downstreamTlsContext == null
|
||||||
this.name = checkNotNull(name, "name");
|
? null : new SslContextProviderSupplier(downstreamTlsContext, tlsContextManager);
|
||||||
// TODO(chengyuanzhang): enforce non-null, change tests to use a default/empty
|
return new AutoValue_EnvoyServerProtoData_FilterChain(
|
||||||
// FilterChainMatch instead of null, as that's how the proto is converted.
|
|
||||||
this.filterChainMatch = filterChainMatch;
|
|
||||||
this.sslContextProviderSupplier = sslContextProviderSupplier1;
|
|
||||||
this.httpConnectionManager = checkNotNull(httpConnectionManager, "httpConnectionManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterChainMatch getFilterChainMatch() {
|
|
||||||
return filterChainMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpConnectionManager getHttpConnectionManager() {
|
|
||||||
return httpConnectionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public SslContextProviderSupplier getSslContextProviderSupplier() {
|
|
||||||
return sslContextProviderSupplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
FilterChain that = (FilterChain) o;
|
|
||||||
return Objects.equals(name, that.name)
|
|
||||||
&& Objects.equals(filterChainMatch, that.filterChainMatch)
|
|
||||||
&& Objects.equals(httpConnectionManager, that.httpConnectionManager)
|
|
||||||
&& Objects.equals(sslContextProviderSupplier, that.sslContextProviderSupplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(
|
|
||||||
name, filterChainMatch, httpConnectionManager, sslContextProviderSupplier);
|
name, filterChainMatch, httpConnectionManager, sslContextProviderSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return MoreObjects.toStringHelper(this)
|
|
||||||
.add("name", name)
|
|
||||||
.add("filterChainMatch", filterChainMatch)
|
|
||||||
.add("httpConnectionManager", httpConnectionManager)
|
|
||||||
.add("sslContextProviderSupplier", sslContextProviderSupplier)
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Corresponds to Envoy proto message {@link io.envoyproxy.envoy.api.v2.Listener} & related
|
* Corresponds to Envoy proto message {@link io.envoyproxy.envoy.api.v2.Listener} & related
|
||||||
* classes.
|
* classes.
|
||||||
*/
|
*/
|
||||||
public static final class Listener {
|
@AutoValue
|
||||||
private final String name;
|
abstract static class Listener {
|
||||||
@Nullable
|
|
||||||
private final String address;
|
|
||||||
private final List<FilterChain> filterChains;
|
|
||||||
@Nullable
|
|
||||||
private final FilterChain defaultFilterChain;
|
|
||||||
|
|
||||||
/** Construct a Listener. */
|
abstract String name();
|
||||||
public Listener(String name, @Nullable String address,
|
|
||||||
List<FilterChain> filterChains, @Nullable FilterChain defaultFilterChain) {
|
|
||||||
this.name = checkNotNull(name, "name");
|
|
||||||
this.address = address;
|
|
||||||
this.filterChains = Collections.unmodifiableList(checkNotNull(filterChains, "filterChains"));
|
|
||||||
this.defaultFilterChain = defaultFilterChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getAddress() {
|
abstract String address();
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FilterChain> getFilterChains() {
|
abstract ImmutableList<FilterChain> filterChains();
|
||||||
return filterChains;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public FilterChain getDefaultFilterChain() {
|
abstract FilterChain defaultFilterChain();
|
||||||
return defaultFilterChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
static Listener create(
|
||||||
public boolean equals(Object o) {
|
String name,
|
||||||
if (this == o) {
|
@Nullable String address,
|
||||||
return true;
|
ImmutableList<FilterChain> filterChains,
|
||||||
}
|
@Nullable FilterChain defaultFilterChain) {
|
||||||
if (o == null || getClass() != o.getClass()) {
|
return new AutoValue_EnvoyServerProtoData_Listener(name, address, filterChains,
|
||||||
return false;
|
defaultFilterChain);
|
||||||
}
|
|
||||||
Listener listener = (Listener) o;
|
|
||||||
return Objects.equals(name, listener.name)
|
|
||||||
&& Objects.equals(address, listener.address)
|
|
||||||
&& Objects.equals(filterChains, listener.filterChains)
|
|
||||||
&& Objects.equals(defaultFilterChain, listener.defaultFilterChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(name, address, filterChains, defaultFilterChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return MoreObjects.toStringHelper(this)
|
|
||||||
.add("name", name)
|
|
||||||
.add("address", address)
|
|
||||||
.add("filterChains", filterChains)
|
|
||||||
.add("defaultFilterChain", defaultFilterChain)
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ import io.grpc.xds.EnvoyServerProtoData.CidrRange;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.ConnectionSourceType;
|
import io.grpc.xds.EnvoyServerProtoData.ConnectionSourceType;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.FilterChain;
|
import io.grpc.xds.EnvoyServerProtoData.FilterChain;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.FilterChainMatch;
|
import io.grpc.xds.EnvoyServerProtoData.FilterChainMatch;
|
||||||
import io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector;
|
|
||||||
import io.grpc.xds.XdsServerWrapper.ServerRoutingConfig;
|
import io.grpc.xds.XdsServerWrapper.ServerRoutingConfig;
|
||||||
import io.grpc.xds.internal.Matchers.CidrMatcher;
|
import io.grpc.xds.internal.Matchers.CidrMatcher;
|
||||||
import io.grpc.xds.internal.sds.SslContextProviderSupplier;
|
import io.grpc.xds.internal.sds.SslContextProviderSupplier;
|
||||||
|
|
@ -189,7 +188,7 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
if (filterChains.size() == 1) {
|
if (filterChains.size() == 1) {
|
||||||
FilterChain selected = Iterables.getOnlyElement(filterChains);
|
FilterChain selected = Iterables.getOnlyElement(filterChains);
|
||||||
return new SelectedConfig(
|
return new SelectedConfig(
|
||||||
routingConfigs.get(selected), selected.getSslContextProviderSupplier());
|
routingConfigs.get(selected), selected.sslContextProviderSupplier());
|
||||||
}
|
}
|
||||||
if (defaultRoutingConfig.get() != null) {
|
if (defaultRoutingConfig.get() != null) {
|
||||||
return new SelectedConfig(defaultRoutingConfig, defaultSslContextProviderSupplier);
|
return new SelectedConfig(defaultRoutingConfig, defaultSslContextProviderSupplier);
|
||||||
|
|
@ -202,9 +201,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
Collection<FilterChain> filterChains) {
|
Collection<FilterChain> filterChains) {
|
||||||
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
|
|
||||||
if (filterChainMatch.getApplicationProtocols().isEmpty()) {
|
if (filterChainMatch.applicationProtocols().isEmpty()) {
|
||||||
filtered.add(filterChain);
|
filtered.add(filterChain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -216,9 +215,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
Collection<FilterChain> filterChains) {
|
Collection<FilterChain> filterChains) {
|
||||||
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
|
|
||||||
String transportProtocol = filterChainMatch.getTransportProtocol();
|
String transportProtocol = filterChainMatch.transportProtocol();
|
||||||
if (Strings.isNullOrEmpty(transportProtocol) || "raw_buffer".equals(transportProtocol)) {
|
if (Strings.isNullOrEmpty(transportProtocol) || "raw_buffer".equals(transportProtocol)) {
|
||||||
filtered.add(filterChain);
|
filtered.add(filterChain);
|
||||||
}
|
}
|
||||||
|
|
@ -231,9 +230,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
Collection<FilterChain> filterChains) {
|
Collection<FilterChain> filterChains) {
|
||||||
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
|
|
||||||
if (filterChainMatch.getServerNames().isEmpty()) {
|
if (filterChainMatch.serverNames().isEmpty()) {
|
||||||
filtered.add(filterChain);
|
filtered.add(filterChain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -245,9 +244,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
Collection<FilterChain> filterChains) {
|
Collection<FilterChain> filterChains) {
|
||||||
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
|
|
||||||
if (filterChainMatch.getDestinationPort()
|
if (filterChainMatch.destinationPort()
|
||||||
== UInt32Value.getDefaultInstance().getValue()) {
|
== UInt32Value.getDefaultInstance().getValue()) {
|
||||||
filtered.add(filterChain);
|
filtered.add(filterChain);
|
||||||
}
|
}
|
||||||
|
|
@ -260,9 +259,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
ArrayList<FilterChain> filteredOnMatch = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filteredOnMatch = new ArrayList<>(filterChains.size());
|
||||||
ArrayList<FilterChain> filteredOnEmpty = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filteredOnEmpty = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
|
|
||||||
List<Integer> sourcePortsToMatch = filterChainMatch.getSourcePorts();
|
List<Integer> sourcePortsToMatch = filterChainMatch.sourcePorts();
|
||||||
if (sourcePortsToMatch.isEmpty()) {
|
if (sourcePortsToMatch.isEmpty()) {
|
||||||
filteredOnEmpty.add(filterChain);
|
filteredOnEmpty.add(filterChain);
|
||||||
} else if (sourcePortsToMatch.contains(sourcePort)) {
|
} else if (sourcePortsToMatch.contains(sourcePort)) {
|
||||||
|
|
@ -278,9 +277,9 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
InetAddress destAddress) {
|
InetAddress destAddress) {
|
||||||
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
ArrayList<FilterChain> filtered = new ArrayList<>(filterChains.size());
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
FilterChainMatch filterChainMatch = filterChain.filterChainMatch();
|
||||||
ConnectionSourceType sourceType =
|
ConnectionSourceType sourceType =
|
||||||
filterChainMatch.getConnectionSourceType();
|
filterChainMatch.connectionSourceType();
|
||||||
|
|
||||||
boolean matching = false;
|
boolean matching = false;
|
||||||
if (sourceType == ConnectionSourceType.SAME_IP_OR_LOOPBACK) {
|
if (sourceType == ConnectionSourceType.SAME_IP_OR_LOOPBACK) {
|
||||||
|
|
@ -305,18 +304,18 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
boolean isIPv6 = address instanceof Inet6Address;
|
boolean isIPv6 = address instanceof Inet6Address;
|
||||||
List<CidrRange> cidrRanges =
|
List<CidrRange> cidrRanges =
|
||||||
forDestination
|
forDestination
|
||||||
? filterChainMatch.getPrefixRanges()
|
? filterChainMatch.prefixRanges()
|
||||||
: filterChainMatch.getSourcePrefixRanges();
|
: filterChainMatch.sourcePrefixRanges();
|
||||||
int matchingPrefixLength;
|
int matchingPrefixLength;
|
||||||
if (cidrRanges.isEmpty()) { // if there is no CidrRange assume 0-length match
|
if (cidrRanges.isEmpty()) { // if there is no CidrRange assume 0-length match
|
||||||
matchingPrefixLength = 0;
|
matchingPrefixLength = 0;
|
||||||
} else {
|
} else {
|
||||||
matchingPrefixLength = -1;
|
matchingPrefixLength = -1;
|
||||||
for (CidrRange cidrRange : cidrRanges) {
|
for (CidrRange cidrRange : cidrRanges) {
|
||||||
InetAddress cidrAddr = cidrRange.getAddressPrefix();
|
InetAddress cidrAddr = cidrRange.addressPrefix();
|
||||||
boolean cidrIsIpv6 = cidrAddr instanceof Inet6Address;
|
boolean cidrIsIpv6 = cidrAddr instanceof Inet6Address;
|
||||||
if (isIPv6 == cidrIsIpv6) {
|
if (isIPv6 == cidrIsIpv6) {
|
||||||
int prefixLen = cidrRange.getPrefixLen();
|
int prefixLen = cidrRange.prefixLen();
|
||||||
CidrMatcher matcher = CidrMatcher.create(cidrAddr, prefixLen);
|
CidrMatcher matcher = CidrMatcher.create(cidrAddr, prefixLen);
|
||||||
if (matcher.matches(address) && prefixLen > matchingPrefixLength) {
|
if (matcher.matches(address) && prefixLen > matchingPrefixLength) {
|
||||||
matchingPrefixLength = prefixLen;
|
matchingPrefixLength = prefixLen;
|
||||||
|
|
@ -335,7 +334,7 @@ final class FilterChainMatchingProtocolNegotiators {
|
||||||
int topMatchingPrefixLen = -1;
|
int topMatchingPrefixLen = -1;
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
int currentMatchingPrefixLen = getMatchingPrefixLength(
|
int currentMatchingPrefixLen = getMatchingPrefixLength(
|
||||||
filterChain.getFilterChainMatch(), address, forDestination);
|
filterChain.filterChainMatch(), address, forDestination);
|
||||||
|
|
||||||
if (currentMatchingPrefixLen >= 0) {
|
if (currentMatchingPrefixLen >= 0) {
|
||||||
if (currentMatchingPrefixLen < topMatchingPrefixLen) {
|
if (currentMatchingPrefixLen < topMatchingPrefixLen) {
|
||||||
|
|
|
||||||
|
|
@ -386,8 +386,8 @@ final class XdsServerWrapper extends Server {
|
||||||
releaseSuppliersInFlight();
|
releaseSuppliersInFlight();
|
||||||
pendingRds.clear();
|
pendingRds.clear();
|
||||||
}
|
}
|
||||||
filterChains = update.listener().getFilterChains();
|
filterChains = update.listener().filterChains();
|
||||||
defaultFilterChain = update.listener().getDefaultFilterChain();
|
defaultFilterChain = update.listener().defaultFilterChain();
|
||||||
List<FilterChain> allFilterChains = filterChains;
|
List<FilterChain> allFilterChains = filterChains;
|
||||||
if (defaultFilterChain != null) {
|
if (defaultFilterChain != null) {
|
||||||
allFilterChains = new ArrayList<>(filterChains);
|
allFilterChains = new ArrayList<>(filterChains);
|
||||||
|
|
@ -395,7 +395,7 @@ final class XdsServerWrapper extends Server {
|
||||||
}
|
}
|
||||||
Set<String> allRds = new HashSet<>();
|
Set<String> allRds = new HashSet<>();
|
||||||
for (FilterChain filterChain : allFilterChains) {
|
for (FilterChain filterChain : allFilterChains) {
|
||||||
HttpConnectionManager hcm = filterChain.getHttpConnectionManager();
|
HttpConnectionManager hcm = filterChain.httpConnectionManager();
|
||||||
if (hcm.virtualHosts() == null) {
|
if (hcm.virtualHosts() == null) {
|
||||||
RouteDiscoveryState rdsState = routeDiscoveryStates.get(hcm.rdsName());
|
RouteDiscoveryState rdsState = routeDiscoveryStates.get(hcm.rdsName());
|
||||||
if (rdsState == null) {
|
if (rdsState == null) {
|
||||||
|
|
@ -478,7 +478,7 @@ final class XdsServerWrapper extends Server {
|
||||||
}
|
}
|
||||||
FilterChainSelector selector = new FilterChainSelector(
|
FilterChainSelector selector = new FilterChainSelector(
|
||||||
Collections.unmodifiableMap(filterChainRouting),
|
Collections.unmodifiableMap(filterChainRouting),
|
||||||
defaultFilterChain == null ? null : defaultFilterChain.getSslContextProviderSupplier(),
|
defaultFilterChain == null ? null : defaultFilterChain.sslContextProviderSupplier(),
|
||||||
defaultFilterChain == null ? new AtomicReference<ServerRoutingConfig>() :
|
defaultFilterChain == null ? new AtomicReference<ServerRoutingConfig>() :
|
||||||
generateRoutingConfig(defaultFilterChain));
|
generateRoutingConfig(defaultFilterChain));
|
||||||
List<SslContextProviderSupplier> toRelease = getSuppliersInUse();
|
List<SslContextProviderSupplier> toRelease = getSuppliersInUse();
|
||||||
|
|
@ -491,7 +491,7 @@ final class XdsServerWrapper extends Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
private AtomicReference<ServerRoutingConfig> generateRoutingConfig(FilterChain filterChain) {
|
private AtomicReference<ServerRoutingConfig> generateRoutingConfig(FilterChain filterChain) {
|
||||||
HttpConnectionManager hcm = filterChain.getHttpConnectionManager();
|
HttpConnectionManager hcm = filterChain.httpConnectionManager();
|
||||||
if (hcm.virtualHosts() != null) {
|
if (hcm.virtualHosts() != null) {
|
||||||
ImmutableMap<Route, ServerInterceptor> interceptors = generatePerRouteInterceptors(
|
ImmutableMap<Route, ServerInterceptor> interceptors = generatePerRouteInterceptors(
|
||||||
hcm.httpFilterConfigs(), hcm.virtualHosts());
|
hcm.httpFilterConfigs(), hcm.virtualHosts());
|
||||||
|
|
@ -602,8 +602,8 @@ final class XdsServerWrapper extends Server {
|
||||||
FilterChainSelector selector = filterChainSelectorManager.getSelectorToUpdateSelector();
|
FilterChainSelector selector = filterChainSelectorManager.getSelectorToUpdateSelector();
|
||||||
if (selector != null) {
|
if (selector != null) {
|
||||||
for (FilterChain f: selector.getRoutingConfigs().keySet()) {
|
for (FilterChain f: selector.getRoutingConfigs().keySet()) {
|
||||||
if (f.getSslContextProviderSupplier() != null) {
|
if (f.sslContextProviderSupplier() != null) {
|
||||||
toRelease.add(f.getSslContextProviderSupplier());
|
toRelease.add(f.sslContextProviderSupplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SslContextProviderSupplier defaultSupplier =
|
SslContextProviderSupplier defaultSupplier =
|
||||||
|
|
@ -618,13 +618,13 @@ final class XdsServerWrapper extends Server {
|
||||||
private void releaseSuppliersInFlight() {
|
private void releaseSuppliersInFlight() {
|
||||||
SslContextProviderSupplier supplier;
|
SslContextProviderSupplier supplier;
|
||||||
for (FilterChain filterChain : filterChains) {
|
for (FilterChain filterChain : filterChains) {
|
||||||
supplier = filterChain.getSslContextProviderSupplier();
|
supplier = filterChain.sslContextProviderSupplier();
|
||||||
if (supplier != null) {
|
if (supplier != null) {
|
||||||
supplier.close();
|
supplier.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (defaultFilterChain != null
|
if (defaultFilterChain != null
|
||||||
&& (supplier = defaultFilterChain.getSslContextProviderSupplier()) != null) {
|
&& (supplier = defaultFilterChain.sslContextProviderSupplier()) != null) {
|
||||||
supplier.close();
|
supplier.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -689,20 +689,20 @@ final class XdsServerWrapper extends Server {
|
||||||
|
|
||||||
private void updateRdsRoutingConfig() {
|
private void updateRdsRoutingConfig() {
|
||||||
for (FilterChain filterChain : savedRdsRoutingConfigRef.keySet()) {
|
for (FilterChain filterChain : savedRdsRoutingConfigRef.keySet()) {
|
||||||
if (resourceName.equals(filterChain.getHttpConnectionManager().rdsName())) {
|
if (resourceName.equals(filterChain.httpConnectionManager().rdsName())) {
|
||||||
ServerRoutingConfig updatedRoutingConfig;
|
ServerRoutingConfig updatedRoutingConfig;
|
||||||
if (savedVirtualHosts == null) {
|
if (savedVirtualHosts == null) {
|
||||||
updatedRoutingConfig = ServerRoutingConfig.FAILING_ROUTING_CONFIG;
|
updatedRoutingConfig = ServerRoutingConfig.FAILING_ROUTING_CONFIG;
|
||||||
} else {
|
} else {
|
||||||
ImmutableMap<Route, ServerInterceptor> updatedInterceptors =
|
ImmutableMap<Route, ServerInterceptor> updatedInterceptors =
|
||||||
generatePerRouteInterceptors(
|
generatePerRouteInterceptors(
|
||||||
filterChain.getHttpConnectionManager().httpFilterConfigs(),
|
filterChain.httpConnectionManager().httpFilterConfigs(),
|
||||||
savedVirtualHosts);
|
savedVirtualHosts);
|
||||||
updatedRoutingConfig = ServerRoutingConfig.create(savedVirtualHosts,
|
updatedRoutingConfig = ServerRoutingConfig.create(savedVirtualHosts,
|
||||||
updatedInterceptors);
|
updatedInterceptors);
|
||||||
}
|
}
|
||||||
logger.log(Level.FINEST, "Updating filter chain {0} rds routing config: {1}",
|
logger.log(Level.FINEST, "Updating filter chain {0} rds routing config: {1}",
|
||||||
new Object[]{filterChain.getName(), updatedRoutingConfig});
|
new Object[]{filterChain.name(), updatedRoutingConfig});
|
||||||
savedRdsRoutingConfigRef.get(filterChain).set(updatedRoutingConfig);
|
savedRdsRoutingConfigRef.get(filterChain).set(updatedRoutingConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2180,7 +2180,7 @@ public class ClientXdsClientDataTest {
|
||||||
EnvoyServerProtoData.FilterChain parsedFilterChain2 = ClientXdsClient.parseFilterChain(
|
EnvoyServerProtoData.FilterChain parsedFilterChain2 = ClientXdsClient.parseFilterChain(
|
||||||
filterChain2, new HashSet<String>(), null, filterRegistry, null,
|
filterChain2, new HashSet<String>(), null, filterRegistry, null,
|
||||||
null, true /* does not matter */);
|
null, true /* does not matter */);
|
||||||
assertThat(parsedFilterChain1.getName()).isEqualTo(parsedFilterChain2.getName());
|
assertThat(parsedFilterChain1.name()).isEqualTo(parsedFilterChain2.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -1282,10 +1282,10 @@ public abstract class ClientXdsClientTestBase {
|
||||||
call.sendResponse(LDS, packedListener, VERSION_1, "0000");
|
call.sendResponse(LDS, packedListener, VERSION_1, "0000");
|
||||||
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
|
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
|
||||||
|
|
||||||
assertThat(ldsUpdateCaptor.getValue().listener().getFilterChains()).hasSize(1);
|
assertThat(ldsUpdateCaptor.getValue().listener().filterChains()).hasSize(1);
|
||||||
FilterChain parsedFilterChain = Iterables.getOnlyElement(
|
FilterChain parsedFilterChain = Iterables.getOnlyElement(
|
||||||
ldsUpdateCaptor.getValue().listener().getFilterChains());
|
ldsUpdateCaptor.getValue().listener().filterChains());
|
||||||
assertThat(parsedFilterChain.getHttpConnectionManager().rdsName()).isEqualTo(RDS_RESOURCE);
|
assertThat(parsedFilterChain.httpConnectionManager().rdsName()).isEqualTo(RDS_RESOURCE);
|
||||||
verifyResourceMetadataAcked(LDS, LISTENER_RESOURCE, packedListener, VERSION_1, TIME_INCREMENT);
|
verifyResourceMetadataAcked(LDS, LISTENER_RESOURCE, packedListener, VERSION_1, TIME_INCREMENT);
|
||||||
verifyResourceMetadataRequested(RDS, RDS_RESOURCE);
|
verifyResourceMetadataRequested(RDS, RDS_RESOURCE);
|
||||||
verifySubscribedResourcesMetadataSizes(1, 0, 1, 0);
|
verifySubscribedResourcesMetadataSizes(1, 0, 1, 0);
|
||||||
|
|
@ -1310,10 +1310,10 @@ public abstract class ClientXdsClientTestBase {
|
||||||
Any.pack(mf.buildListenerWithFilterChain(LISTENER_RESOURCE, 7000, "0.0.0.0", filterChain));
|
Any.pack(mf.buildListenerWithFilterChain(LISTENER_RESOURCE, 7000, "0.0.0.0", filterChain));
|
||||||
call.sendResponse(LDS, packedListener, VERSION_2, "0001");
|
call.sendResponse(LDS, packedListener, VERSION_2, "0001");
|
||||||
verify(ldsResourceWatcher, times(2)).onChanged(ldsUpdateCaptor.capture());
|
verify(ldsResourceWatcher, times(2)).onChanged(ldsUpdateCaptor.capture());
|
||||||
assertThat(ldsUpdateCaptor.getValue().listener().getFilterChains()).hasSize(1);
|
assertThat(ldsUpdateCaptor.getValue().listener().filterChains()).hasSize(1);
|
||||||
parsedFilterChain = Iterables.getOnlyElement(
|
parsedFilterChain = Iterables.getOnlyElement(
|
||||||
ldsUpdateCaptor.getValue().listener().getFilterChains());
|
ldsUpdateCaptor.getValue().listener().filterChains());
|
||||||
assertThat(parsedFilterChain.getHttpConnectionManager().virtualHosts()).hasSize(VHOST_SIZE);
|
assertThat(parsedFilterChain.httpConnectionManager().virtualHosts()).hasSize(VHOST_SIZE);
|
||||||
verify(rdsResourceWatcher).onResourceDoesNotExist(RDS_RESOURCE);
|
verify(rdsResourceWatcher).onResourceDoesNotExist(RDS_RESOURCE);
|
||||||
verifyResourceMetadataDoesNotExist(RDS, RDS_RESOURCE);
|
verifyResourceMetadataDoesNotExist(RDS, RDS_RESOURCE);
|
||||||
verifyResourceMetadataAcked(
|
verifyResourceMetadataAcked(
|
||||||
|
|
@ -2608,15 +2608,15 @@ public abstract class ClientXdsClientTestBase {
|
||||||
ResourceType.LDS, Collections.singletonList(LISTENER_RESOURCE), "0", "0000", NODE);
|
ResourceType.LDS, Collections.singletonList(LISTENER_RESOURCE), "0", "0000", NODE);
|
||||||
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
|
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
|
||||||
EnvoyServerProtoData.Listener parsedListener = ldsUpdateCaptor.getValue().listener();
|
EnvoyServerProtoData.Listener parsedListener = ldsUpdateCaptor.getValue().listener();
|
||||||
assertThat(parsedListener.getName()).isEqualTo(LISTENER_RESOURCE);
|
assertThat(parsedListener.name()).isEqualTo(LISTENER_RESOURCE);
|
||||||
assertThat(parsedListener.getAddress()).isEqualTo("0.0.0.0:7000");
|
assertThat(parsedListener.address()).isEqualTo("0.0.0.0:7000");
|
||||||
assertThat(parsedListener.getDefaultFilterChain()).isNull();
|
assertThat(parsedListener.defaultFilterChain()).isNull();
|
||||||
assertThat(parsedListener.getFilterChains()).hasSize(1);
|
assertThat(parsedListener.filterChains()).hasSize(1);
|
||||||
FilterChain parsedFilterChain = Iterables.getOnlyElement(parsedListener.getFilterChains());
|
FilterChain parsedFilterChain = Iterables.getOnlyElement(parsedListener.filterChains());
|
||||||
assertThat(parsedFilterChain.getFilterChainMatch().getApplicationProtocols()).isEmpty();
|
assertThat(parsedFilterChain.filterChainMatch().applicationProtocols()).isEmpty();
|
||||||
assertThat(parsedFilterChain.getHttpConnectionManager().rdsName())
|
assertThat(parsedFilterChain.httpConnectionManager().rdsName())
|
||||||
.isEqualTo("route-foo.googleapis.com");
|
.isEqualTo("route-foo.googleapis.com");
|
||||||
assertThat(parsedFilterChain.getHttpConnectionManager().httpFilterConfigs().get(0).filterConfig)
|
assertThat(parsedFilterChain.httpConnectionManager().httpFilterConfigs().get(0).filterConfig)
|
||||||
.isEqualTo(RouterFilter.ROUTER_CONFIG);
|
.isEqualTo(RouterFilter.ROUTER_CONFIG);
|
||||||
|
|
||||||
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -29,6 +29,7 @@ import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import io.grpc.Server;
|
import io.grpc.Server;
|
||||||
import io.grpc.ServerBuilder;
|
import io.grpc.ServerBuilder;
|
||||||
|
|
@ -66,8 +67,6 @@ import io.netty.handler.codec.http2.Http2Settings;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
@ -160,10 +159,10 @@ public class XdsClientWrapperForServerSdsTestMisc {
|
||||||
assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:" + PORT);
|
assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:" + PORT);
|
||||||
|
|
||||||
EnvoyServerProtoData.Listener listener =
|
EnvoyServerProtoData.Listener listener =
|
||||||
new EnvoyServerProtoData.Listener(
|
EnvoyServerProtoData.Listener.create(
|
||||||
"listener1",
|
"listener1",
|
||||||
"10.1.2.3",
|
"10.1.2.3",
|
||||||
Collections.<EnvoyServerProtoData.FilterChain>emptyList(),
|
ImmutableList.of(),
|
||||||
null);
|
null);
|
||||||
LdsUpdate listenerUpdate = LdsUpdate.forTcpListener(listener);
|
LdsUpdate listenerUpdate = LdsUpdate.forTcpListener(listener);
|
||||||
xdsClient.ldsWatcher.onChanged(listenerUpdate);
|
xdsClient.ldsWatcher.onChanged(listenerUpdate);
|
||||||
|
|
@ -268,7 +267,7 @@ public class XdsClientWrapperForServerSdsTestMisc {
|
||||||
assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
|
assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
|
||||||
callUpdateSslContext(returnedSupplier);
|
callUpdateSslContext(returnedSupplier);
|
||||||
XdsServerTestHelper
|
XdsServerTestHelper
|
||||||
.generateListenerUpdate(xdsClient, Arrays.<Integer>asList(1234), tlsContext2,
|
.generateListenerUpdate(xdsClient, ImmutableList.of(1234), tlsContext2,
|
||||||
tlsContext3, tlsContextManager);
|
tlsContext3, tlsContextManager);
|
||||||
returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
|
returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
|
||||||
assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext2);
|
assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext2);
|
||||||
|
|
@ -379,7 +378,7 @@ public class XdsClientWrapperForServerSdsTestMisc {
|
||||||
});
|
});
|
||||||
xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
|
xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
|
||||||
XdsServerTestHelper
|
XdsServerTestHelper
|
||||||
.generateListenerUpdate(xdsClient, Arrays.<Integer>asList(), tlsContext,
|
.generateListenerUpdate(xdsClient, ImmutableList.of(), tlsContext,
|
||||||
tlsContextForDefaultFilterChain, tlsContextManager);
|
tlsContextForDefaultFilterChain, tlsContextManager);
|
||||||
start.get(5, TimeUnit.SECONDS);
|
start.get(5, TimeUnit.SECONDS);
|
||||||
InetAddress ipRemoteAddress = InetAddress.getByName("10.4.5.6");
|
InetAddress ipRemoteAddress = InetAddress.getByName("10.4.5.6");
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import io.grpc.testing.GrpcCleanupRule;
|
||||||
import io.grpc.testing.protobuf.SimpleRequest;
|
import io.grpc.testing.protobuf.SimpleRequest;
|
||||||
import io.grpc.testing.protobuf.SimpleResponse;
|
import io.grpc.testing.protobuf.SimpleResponse;
|
||||||
import io.grpc.testing.protobuf.SimpleServiceGrpc;
|
import io.grpc.testing.protobuf.SimpleServiceGrpc;
|
||||||
|
import io.grpc.xds.EnvoyServerProtoData.ConnectionSourceType;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
import io.grpc.xds.Filter.FilterConfig;
|
import io.grpc.xds.Filter.FilterConfig;
|
||||||
|
|
@ -364,15 +365,15 @@ public class XdsSdsClientServerTest {
|
||||||
String name, String address, DownstreamTlsContext tlsContext,
|
String name, String address, DownstreamTlsContext tlsContext,
|
||||||
TlsContextManager tlsContextManager) {
|
TlsContextManager tlsContextManager) {
|
||||||
EnvoyServerProtoData.FilterChainMatch filterChainMatch =
|
EnvoyServerProtoData.FilterChainMatch filterChainMatch =
|
||||||
new EnvoyServerProtoData.FilterChainMatch(
|
EnvoyServerProtoData.FilterChainMatch.create(
|
||||||
0,
|
0,
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
null,
|
ConnectionSourceType.ANY,
|
||||||
Arrays.<Integer>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
null);
|
"");
|
||||||
String fullPath = "/" + SimpleServiceGrpc.SERVICE_NAME + "/" + "UnaryRpc";
|
String fullPath = "/" + SimpleServiceGrpc.SERVICE_NAME + "/" + "UnaryRpc";
|
||||||
RouteMatch routeMatch =
|
RouteMatch routeMatch =
|
||||||
RouteMatch.create(
|
RouteMatch.create(
|
||||||
|
|
@ -386,11 +387,11 @@ public class XdsSdsClientServerTest {
|
||||||
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
||||||
0L, Collections.singletonList(virtualHost),
|
0L, Collections.singletonList(virtualHost),
|
||||||
new ArrayList<NamedFilterConfig>());
|
new ArrayList<NamedFilterConfig>());
|
||||||
EnvoyServerProtoData.FilterChain defaultFilterChain = new EnvoyServerProtoData.FilterChain(
|
EnvoyServerProtoData.FilterChain defaultFilterChain = EnvoyServerProtoData.FilterChain.create(
|
||||||
"filter-chain-foo", filterChainMatch, httpConnectionManager, tlsContext,
|
"filter-chain-foo", filterChainMatch, httpConnectionManager, tlsContext,
|
||||||
tlsContextManager);
|
tlsContextManager);
|
||||||
EnvoyServerProtoData.Listener listener =
|
EnvoyServerProtoData.Listener listener = EnvoyServerProtoData.Listener.create(
|
||||||
new EnvoyServerProtoData.Listener(name, address, Arrays.asList(defaultFilterChain), null);
|
name, address, ImmutableList.of(defaultFilterChain), null);
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ package io.grpc.xds;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import io.grpc.InsecureChannelCredentials;
|
import io.grpc.InsecureChannelCredentials;
|
||||||
import io.grpc.internal.ObjectPool;
|
import io.grpc.internal.ObjectPool;
|
||||||
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
||||||
|
import io.grpc.xds.EnvoyServerProtoData.ConnectionSourceType;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.FilterChain;
|
import io.grpc.xds.EnvoyServerProtoData.FilterChain;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.Listener;
|
import io.grpc.xds.EnvoyServerProtoData.Listener;
|
||||||
import io.grpc.xds.Filter.FilterConfig;
|
import io.grpc.xds.Filter.FilterConfig;
|
||||||
|
|
@ -61,13 +63,13 @@ public class XdsServerTestHelper {
|
||||||
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
||||||
TlsContextManager tlsContextManager) {
|
TlsContextManager tlsContextManager) {
|
||||||
EnvoyServerProtoData.Listener listener = buildTestListener("listener1", "10.1.2.3",
|
EnvoyServerProtoData.Listener listener = buildTestListener("listener1", "10.1.2.3",
|
||||||
Arrays.<Integer>asList(), tlsContext, null, tlsContextManager);
|
ImmutableList.of(), tlsContext, null, tlsContextManager);
|
||||||
LdsUpdate listenerUpdate = LdsUpdate.forTcpListener(listener);
|
LdsUpdate listenerUpdate = LdsUpdate.forTcpListener(listener);
|
||||||
xdsClient.deliverLdsUpdate(listenerUpdate);
|
xdsClient.deliverLdsUpdate(listenerUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generateListenerUpdate(
|
static void generateListenerUpdate(
|
||||||
FakeXdsClient xdsClient, List<Integer> sourcePorts,
|
FakeXdsClient xdsClient, ImmutableList<Integer> sourcePorts,
|
||||||
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
||||||
EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain,
|
EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain,
|
||||||
TlsContextManager tlsContextManager) {
|
TlsContextManager tlsContextManager) {
|
||||||
|
|
@ -78,35 +80,45 @@ public class XdsServerTestHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static EnvoyServerProtoData.Listener buildTestListener(
|
static EnvoyServerProtoData.Listener buildTestListener(
|
||||||
String name, String address, List<Integer> sourcePorts,
|
String name, String address, ImmutableList<Integer> sourcePorts,
|
||||||
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
EnvoyServerProtoData.DownstreamTlsContext tlsContext,
|
||||||
EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain,
|
EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain,
|
||||||
TlsContextManager tlsContextManager) {
|
TlsContextManager tlsContextManager) {
|
||||||
EnvoyServerProtoData.FilterChainMatch filterChainMatch1 =
|
EnvoyServerProtoData.FilterChainMatch filterChainMatch1 =
|
||||||
new EnvoyServerProtoData.FilterChainMatch(
|
EnvoyServerProtoData.FilterChainMatch.create(
|
||||||
0,
|
0,
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
null,
|
ConnectionSourceType.ANY,
|
||||||
sourcePorts,
|
sourcePorts,
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
null);
|
"");
|
||||||
|
EnvoyServerProtoData.FilterChainMatch defaultFilterChainMatch =
|
||||||
|
EnvoyServerProtoData.FilterChainMatch.create(
|
||||||
|
0,
|
||||||
|
ImmutableList.of(),
|
||||||
|
ImmutableList.of(),
|
||||||
|
ImmutableList.of(),
|
||||||
|
ConnectionSourceType.ANY,
|
||||||
|
ImmutableList.of(),
|
||||||
|
ImmutableList.of(),
|
||||||
|
"");
|
||||||
VirtualHost virtualHost =
|
VirtualHost virtualHost =
|
||||||
VirtualHost.create(
|
VirtualHost.create(
|
||||||
"virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(),
|
"virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(),
|
||||||
ImmutableMap.<String, FilterConfig>of());
|
ImmutableMap.<String, FilterConfig>of());
|
||||||
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
||||||
0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
|
0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
|
||||||
EnvoyServerProtoData.FilterChain filterChain1 = new EnvoyServerProtoData.FilterChain(
|
EnvoyServerProtoData.FilterChain filterChain1 = EnvoyServerProtoData.FilterChain.create(
|
||||||
"filter-chain-foo", filterChainMatch1, httpConnectionManager, tlsContext,
|
"filter-chain-foo", filterChainMatch1, httpConnectionManager, tlsContext,
|
||||||
tlsContextManager);
|
tlsContextManager);
|
||||||
EnvoyServerProtoData.FilterChain defaultFilterChain = new EnvoyServerProtoData.FilterChain(
|
EnvoyServerProtoData.FilterChain defaultFilterChain = EnvoyServerProtoData.FilterChain.create(
|
||||||
"filter-chain-bar", null, httpConnectionManager, tlsContextForDefaultFilterChain,
|
"filter-chain-bar", defaultFilterChainMatch, httpConnectionManager,
|
||||||
tlsContextManager);
|
tlsContextForDefaultFilterChain, tlsContextManager);
|
||||||
EnvoyServerProtoData.Listener listener =
|
EnvoyServerProtoData.Listener listener =
|
||||||
new EnvoyServerProtoData.Listener(
|
EnvoyServerProtoData.Listener.create(
|
||||||
name, address, Arrays.asList(filterChain1), defaultFilterChain);
|
name, address, ImmutableList.of(filterChain1), defaultFilterChain);
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,8 +214,8 @@ public class XdsServerTestHelper {
|
||||||
|
|
||||||
void deliverLdsUpdate(List<FilterChain> filterChains,
|
void deliverLdsUpdate(List<FilterChain> filterChains,
|
||||||
FilterChain defaultFilterChain) {
|
FilterChain defaultFilterChain) {
|
||||||
ldsWatcher.onChanged(LdsUpdate.forTcpListener(new Listener(
|
ldsWatcher.onChanged(LdsUpdate.forTcpListener(Listener.create(
|
||||||
"listener", "0.0.0.0:1", filterChains, defaultFilterChain)));
|
"listener", "0.0.0.0:1", ImmutableList.copyOf(filterChains), defaultFilterChain)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deliverLdsUpdate(LdsUpdate ldsUpdate) {
|
void deliverLdsUpdate(LdsUpdate ldsUpdate) {
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,8 @@ public class XdsServerWrapperTest {
|
||||||
assertThat(xdsClient.ldsResource).isNull();
|
assertThat(xdsClient.ldsResource).isNull();
|
||||||
assertThat(xdsClient.shutdown).isTrue();
|
assertThat(xdsClient.shutdown).isTrue();
|
||||||
verify(mockServer).shutdown();
|
verify(mockServer).shutdown();
|
||||||
assertThat(f0.getSslContextProviderSupplier().isShutdown()).isTrue();
|
assertThat(f0.sslContextProviderSupplier().isShutdown()).isTrue();
|
||||||
assertThat(f1.getSslContextProviderSupplier().isShutdown()).isTrue();
|
assertThat(f1.sslContextProviderSupplier().isShutdown()).isTrue();
|
||||||
when(mockServer.isTerminated()).thenReturn(true);
|
when(mockServer.isTerminated()).thenReturn(true);
|
||||||
when(mockServer.awaitTermination(anyLong(), any(TimeUnit.class))).thenReturn(true);
|
when(mockServer.awaitTermination(anyLong(), any(TimeUnit.class))).thenReturn(true);
|
||||||
assertThat(xdsServerWrapper.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
|
assertThat(xdsServerWrapper.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
|
||||||
|
|
@ -276,8 +276,8 @@ public class XdsServerWrapperTest {
|
||||||
assertThat(xdsClient.ldsResource).isNull();
|
assertThat(xdsClient.ldsResource).isNull();
|
||||||
assertThat(xdsClient.shutdown).isTrue();
|
assertThat(xdsClient.shutdown).isTrue();
|
||||||
verify(mockServer).shutdown();
|
verify(mockServer).shutdown();
|
||||||
assertThat(f0.getSslContextProviderSupplier().isShutdown()).isTrue();
|
assertThat(f0.sslContextProviderSupplier().isShutdown()).isTrue();
|
||||||
assertThat(f1.getSslContextProviderSupplier().isShutdown()).isTrue();
|
assertThat(f1.sslContextProviderSupplier().isShutdown()).isTrue();
|
||||||
assertThat(start.isDone()).isFalse(); //shall we set initialStatus when shutdown?
|
assertThat(start.isDone()).isFalse(); //shall we set initialStatus when shutdown?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -335,7 +335,7 @@ public class XdsServerWrapperTest {
|
||||||
xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
|
xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
|
||||||
when(mockServer.start()).thenThrow(new IOException("error!"));
|
when(mockServer.start()).thenThrow(new IOException("error!"));
|
||||||
FilterChain filterChain = createFilterChain("filter-chain-1", createRds("rds"));
|
FilterChain filterChain = createFilterChain("filter-chain-1", createRds("rds"));
|
||||||
SslContextProviderSupplier sslSupplier = filterChain.getSslContextProviderSupplier();
|
SslContextProviderSupplier sslSupplier = filterChain.sslContextProviderSupplier();
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
|
||||||
xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
|
xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
|
||||||
xdsClient.deliverRdsUpdate("rds",
|
xdsClient.deliverRdsUpdate("rds",
|
||||||
|
|
@ -437,7 +437,7 @@ public class XdsServerWrapperTest {
|
||||||
ImmutableMap.<String, FilterConfig>of());
|
ImmutableMap.<String, FilterConfig>of());
|
||||||
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
|
||||||
0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
|
0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
|
||||||
EnvoyServerProtoData.FilterChain filterChain = new EnvoyServerProtoData.FilterChain(
|
EnvoyServerProtoData.FilterChain filterChain = EnvoyServerProtoData.FilterChain.create(
|
||||||
"filter-chain-foo", createMatch(), httpConnectionManager, createTls(),
|
"filter-chain-foo", createMatch(), httpConnectionManager, createTls(),
|
||||||
mock(TlsContextManager.class));
|
mock(TlsContextManager.class));
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
|
||||||
|
|
@ -509,7 +509,7 @@ public class XdsServerWrapperTest {
|
||||||
assertThat(realConfig.virtualHosts()).isEqualTo(
|
assertThat(realConfig.virtualHosts()).isEqualTo(
|
||||||
Collections.singletonList(createVirtualHost("virtual-host-2")));
|
Collections.singletonList(createVirtualHost("virtual-host-2")));
|
||||||
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
||||||
.isEqualTo(f3.getSslContextProviderSupplier());
|
.isEqualTo(f3.sslContextProviderSupplier());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -557,7 +557,7 @@ public class XdsServerWrapperTest {
|
||||||
Collections.singletonList(createVirtualHost("virtual-host-0")));
|
Collections.singletonList(createVirtualHost("virtual-host-0")));
|
||||||
assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
|
assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
|
||||||
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
||||||
.isSameInstanceAs(f2.getSslContextProviderSupplier());
|
.isSameInstanceAs(f2.sslContextProviderSupplier());
|
||||||
|
|
||||||
EnvoyServerProtoData.FilterChain f3 = createFilterChain("filter-chain-3", createRds("r0"));
|
EnvoyServerProtoData.FilterChain f3 = createFilterChain("filter-chain-3", createRds("r0"));
|
||||||
EnvoyServerProtoData.FilterChain f4 = createFilterChain("filter-chain-4", createRds("r1"));
|
EnvoyServerProtoData.FilterChain f4 = createFilterChain("filter-chain-4", createRds("r1"));
|
||||||
|
|
@ -587,7 +587,7 @@ public class XdsServerWrapperTest {
|
||||||
assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
|
assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
|
||||||
|
|
||||||
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier())
|
||||||
.isSameInstanceAs(f4.getSslContextProviderSupplier());
|
.isSameInstanceAs(f4.sslContextProviderSupplier());
|
||||||
verify(mockServer, times(1)).start();
|
verify(mockServer, times(1)).start();
|
||||||
xdsServerWrapper.shutdown();
|
xdsServerWrapper.shutdown();
|
||||||
verify(mockServer, times(1)).shutdown();
|
verify(mockServer, times(1)).shutdown();
|
||||||
|
|
@ -675,7 +675,7 @@ public class XdsServerWrapperTest {
|
||||||
verify(listener, times(1)).onNotServing(any(StatusException.class));
|
verify(listener, times(1)).onNotServing(any(StatusException.class));
|
||||||
verify(mockBuilder, times(1)).build();
|
verify(mockBuilder, times(1)).build();
|
||||||
FilterChain filterChain0 = createFilterChain("filter-chain-0", createRds("rds"));
|
FilterChain filterChain0 = createFilterChain("filter-chain-0", createRds("rds"));
|
||||||
SslContextProviderSupplier sslSupplier0 = filterChain0.getSslContextProviderSupplier();
|
SslContextProviderSupplier sslSupplier0 = filterChain0.sslContextProviderSupplier();
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain0), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain0), null);
|
||||||
xdsClient.ldsWatcher.onError(Status.INTERNAL);
|
xdsClient.ldsWatcher.onError(Status.INTERNAL);
|
||||||
assertThat(selectorManager.getSelectorToUpdateSelector())
|
assertThat(selectorManager.getSelectorToUpdateSelector())
|
||||||
|
|
@ -688,7 +688,7 @@ public class XdsServerWrapperTest {
|
||||||
when(mockServer.start()).thenThrow(new IOException("error!"))
|
when(mockServer.start()).thenThrow(new IOException("error!"))
|
||||||
.thenReturn(mockServer);
|
.thenReturn(mockServer);
|
||||||
FilterChain filterChain1 = createFilterChain("filter-chain-1", createRds("rds"));
|
FilterChain filterChain1 = createFilterChain("filter-chain-1", createRds("rds"));
|
||||||
SslContextProviderSupplier sslSupplier1 = filterChain1.getSslContextProviderSupplier();
|
SslContextProviderSupplier sslSupplier1 = filterChain1.sslContextProviderSupplier();
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain1), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain1), null);
|
||||||
assertThat(sslSupplier0.isShutdown()).isTrue();
|
assertThat(sslSupplier0.isShutdown()).isTrue();
|
||||||
xdsClient.deliverRdsUpdate("rds",
|
xdsClient.deliverRdsUpdate("rds",
|
||||||
|
|
@ -752,7 +752,7 @@ public class XdsServerWrapperTest {
|
||||||
.thenThrow(new IOException("error2!"))
|
.thenThrow(new IOException("error2!"))
|
||||||
.thenReturn(mockServer);
|
.thenReturn(mockServer);
|
||||||
FilterChain filterChain2 = createFilterChain("filter-chain-2", createRds("rds"));
|
FilterChain filterChain2 = createFilterChain("filter-chain-2", createRds("rds"));
|
||||||
SslContextProviderSupplier sslSupplier2 = filterChain2.getSslContextProviderSupplier();
|
SslContextProviderSupplier sslSupplier2 = filterChain2.sslContextProviderSupplier();
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain2), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain2), null);
|
||||||
xdsClient.deliverRdsUpdate("rds",
|
xdsClient.deliverRdsUpdate("rds",
|
||||||
Collections.singletonList(createVirtualHost("virtual-host-1")));
|
Collections.singletonList(createVirtualHost("virtual-host-1")));
|
||||||
|
|
@ -780,7 +780,7 @@ public class XdsServerWrapperTest {
|
||||||
|
|
||||||
// serving after not serving
|
// serving after not serving
|
||||||
FilterChain filterChain3 = createFilterChain("filter-chain-2", createRds("rds"));
|
FilterChain filterChain3 = createFilterChain("filter-chain-2", createRds("rds"));
|
||||||
SslContextProviderSupplier sslSupplier3 = filterChain3.getSslContextProviderSupplier();
|
SslContextProviderSupplier sslSupplier3 = filterChain3.sslContextProviderSupplier();
|
||||||
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain3), null);
|
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain3), null);
|
||||||
xdsClient.deliverRdsUpdate("rds",
|
xdsClient.deliverRdsUpdate("rds",
|
||||||
Collections.singletonList(createVirtualHost("virtual-host-1")));
|
Collections.singletonList(createVirtualHost("virtual-host-1")));
|
||||||
|
|
@ -1187,7 +1187,7 @@ public class XdsServerWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FilterChain createFilterChain(String name, HttpConnectionManager hcm) {
|
private static FilterChain createFilterChain(String name, HttpConnectionManager hcm) {
|
||||||
return new EnvoyServerProtoData.FilterChain(name, createMatch(),
|
return EnvoyServerProtoData.FilterChain.create(name, createMatch(),
|
||||||
hcm, createTls(), mock(TlsContextManager.class));
|
hcm, createTls(), mock(TlsContextManager.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1207,15 +1207,15 @@ public class XdsServerWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EnvoyServerProtoData.FilterChainMatch createMatch() {
|
private static EnvoyServerProtoData.FilterChainMatch createMatch() {
|
||||||
return new EnvoyServerProtoData.FilterChainMatch(
|
return EnvoyServerProtoData.FilterChainMatch.create(
|
||||||
0,
|
0,
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<EnvoyServerProtoData.CidrRange>asList(),
|
ImmutableList.of(),
|
||||||
EnvoyServerProtoData.ConnectionSourceType.ANY,
|
EnvoyServerProtoData.ConnectionSourceType.ANY,
|
||||||
Arrays.<Integer>asList(),
|
ImmutableList.of(),
|
||||||
Arrays.<String>asList(),
|
ImmutableList.of(),
|
||||||
null);
|
"");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ServerRoutingConfig createRoutingConfig(String path, String domain,
|
private static ServerRoutingConfig createRoutingConfig(String path, String domain,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue