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