mirror of https://github.com/grpc/grpc-java.git
xds: Avoid depending on io.grpc.xds.Internal* classes
Internal* classes should generally be accessors that are used outside of the package/project. Only one attribute was used outside of xds, so leave only that one attribute in InternalXdsAttributes. One attribute was used by the internal.security package, so move the definition to the same package to reduce the circular dependencies.
This commit is contained in:
parent
1cf1927d1a
commit
4a0f707331
|
|
@ -88,7 +88,7 @@ final class CdsLoadBalancer2 extends LoadBalancer {
|
||||||
}
|
}
|
||||||
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
||||||
this.resolvedAddresses = resolvedAddresses;
|
this.resolvedAddresses = resolvedAddresses;
|
||||||
xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
|
xdsClientPool = resolvedAddresses.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL);
|
||||||
xdsClient = xdsClientPool.getObject();
|
xdsClient = xdsClientPool.getObject();
|
||||||
CdsConfig config = (CdsConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
|
CdsConfig config = (CdsConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
|
||||||
logger.log(XdsLogLevel.INFO, "Config: {0}", config);
|
logger.log(XdsLogLevel.INFO, "Config: {0}", config);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ import io.grpc.xds.client.Locality;
|
||||||
import io.grpc.xds.client.XdsClient;
|
import io.grpc.xds.client.XdsClient;
|
||||||
import io.grpc.xds.client.XdsLogger;
|
import io.grpc.xds.client.XdsLogger;
|
||||||
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
|
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
|
||||||
|
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
|
||||||
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
||||||
import io.grpc.xds.orca.OrcaPerRequestUtil;
|
import io.grpc.xds.orca.OrcaPerRequestUtil;
|
||||||
import io.grpc.xds.orca.OrcaPerRequestUtil.OrcaPerRequestReportListener;
|
import io.grpc.xds.orca.OrcaPerRequestUtil.OrcaPerRequestReportListener;
|
||||||
|
|
@ -114,12 +115,12 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
||||||
Attributes attributes = resolvedAddresses.getAttributes();
|
Attributes attributes = resolvedAddresses.getAttributes();
|
||||||
if (xdsClientPool == null) {
|
if (xdsClientPool == null) {
|
||||||
xdsClientPool = attributes.get(InternalXdsAttributes.XDS_CLIENT_POOL);
|
xdsClientPool = attributes.get(XdsAttributes.XDS_CLIENT_POOL);
|
||||||
assert xdsClientPool != null;
|
assert xdsClientPool != null;
|
||||||
xdsClient = xdsClientPool.getObject();
|
xdsClient = xdsClientPool.getObject();
|
||||||
}
|
}
|
||||||
if (callCounterProvider == null) {
|
if (callCounterProvider == null) {
|
||||||
callCounterProvider = attributes.get(InternalXdsAttributes.CALL_COUNTER_PROVIDER);
|
callCounterProvider = attributes.get(XdsAttributes.CALL_COUNTER_PROVIDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClusterImplConfig config =
|
ClusterImplConfig config =
|
||||||
|
|
@ -236,9 +237,9 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
.set(ATTR_CLUSTER_LOCALITY, localityAtomicReference);
|
.set(ATTR_CLUSTER_LOCALITY, localityAtomicReference);
|
||||||
if (GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)) {
|
if (GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)) {
|
||||||
String hostname = args.getAddresses().get(0).getAttributes()
|
String hostname = args.getAddresses().get(0).getAttributes()
|
||||||
.get(InternalXdsAttributes.ATTR_ADDRESS_NAME);
|
.get(XdsAttributes.ATTR_ADDRESS_NAME);
|
||||||
if (hostname != null) {
|
if (hostname != null) {
|
||||||
attrsBuilder.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, hostname);
|
attrsBuilder.set(XdsAttributes.ATTR_ADDRESS_NAME, hostname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args = args.toBuilder().setAddresses(addresses).setAttributes(attrsBuilder.build()).build();
|
args = args.toBuilder().setAddresses(addresses).setAttributes(attrsBuilder.build()).build();
|
||||||
|
|
@ -287,10 +288,10 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
List<EquivalentAddressGroup> newAddresses = new ArrayList<>();
|
List<EquivalentAddressGroup> newAddresses = new ArrayList<>();
|
||||||
for (EquivalentAddressGroup eag : addresses) {
|
for (EquivalentAddressGroup eag : addresses) {
|
||||||
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
|
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
|
||||||
InternalXdsAttributes.ATTR_CLUSTER_NAME, cluster);
|
XdsAttributes.ATTR_CLUSTER_NAME, cluster);
|
||||||
if (sslContextProviderSupplier != null) {
|
if (sslContextProviderSupplier != null) {
|
||||||
attrBuilder.set(
|
attrBuilder.set(
|
||||||
InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
||||||
sslContextProviderSupplier);
|
sslContextProviderSupplier);
|
||||||
}
|
}
|
||||||
newAddresses.add(new EquivalentAddressGroup(eag.getAddresses(), attrBuilder.build()));
|
newAddresses.add(new EquivalentAddressGroup(eag.getAddresses(), attrBuilder.build()));
|
||||||
|
|
@ -299,8 +300,8 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClusterLocality createClusterLocalityFromAttributes(Attributes addressAttributes) {
|
private ClusterLocality createClusterLocalityFromAttributes(Attributes addressAttributes) {
|
||||||
Locality locality = addressAttributes.get(InternalXdsAttributes.ATTR_LOCALITY);
|
Locality locality = addressAttributes.get(XdsAttributes.ATTR_LOCALITY);
|
||||||
String localityName = addressAttributes.get(InternalXdsAttributes.ATTR_LOCALITY_NAME);
|
String localityName = addressAttributes.get(XdsAttributes.ATTR_LOCALITY_NAME);
|
||||||
|
|
||||||
// Endpoint addresses resolved by ClusterResolverLoadBalancer should always contain
|
// Endpoint addresses resolved by ClusterResolverLoadBalancer should always contain
|
||||||
// attributes with its locality, including endpoints in LOGICAL_DNS clusters.
|
// attributes with its locality, including endpoints in LOGICAL_DNS clusters.
|
||||||
|
|
@ -431,7 +432,7 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
|
||||||
result = PickResult.withSubchannel(result.getSubchannel(),
|
result = PickResult.withSubchannel(result.getSubchannel(),
|
||||||
result.getStreamTracerFactory(),
|
result.getStreamTracerFactory(),
|
||||||
result.getSubchannel().getAttributes().get(
|
result.getSubchannel().getAttributes().get(
|
||||||
InternalXdsAttributes.ATTR_ADDRESS_NAME));
|
XdsAttributes.ATTR_ADDRESS_NAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
|
public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
|
||||||
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
|
||||||
if (xdsClientPool == null) {
|
if (xdsClientPool == null) {
|
||||||
xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
|
xdsClientPool = resolvedAddresses.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL);
|
||||||
xdsClient = xdsClientPool.getObject();
|
xdsClient = xdsClientPool.getObject();
|
||||||
}
|
}
|
||||||
ClusterResolverConfig config =
|
ClusterResolverConfig config =
|
||||||
|
|
@ -423,12 +423,12 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
String localityName = localityName(locality);
|
String localityName = localityName(locality);
|
||||||
Attributes attr =
|
Attributes attr =
|
||||||
endpoint.eag().getAttributes().toBuilder()
|
endpoint.eag().getAttributes().toBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY, locality)
|
.set(XdsAttributes.ATTR_LOCALITY, locality)
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, localityName)
|
.set(XdsAttributes.ATTR_LOCALITY_NAME, localityName)
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT,
|
.set(XdsAttributes.ATTR_LOCALITY_WEIGHT,
|
||||||
localityLbInfo.localityWeight())
|
localityLbInfo.localityWeight())
|
||||||
.set(InternalXdsAttributes.ATTR_SERVER_WEIGHT, weight)
|
.set(XdsAttributes.ATTR_SERVER_WEIGHT, weight)
|
||||||
.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
|
.set(XdsAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
|
||||||
.build();
|
.build();
|
||||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(
|
EquivalentAddressGroup eag = new EquivalentAddressGroup(
|
||||||
endpoint.eag().getAddresses(), attr);
|
endpoint.eag().getAddresses(), attr);
|
||||||
|
|
@ -630,9 +630,9 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
// to handle such it.
|
// to handle such it.
|
||||||
String localityName = localityName(LOGICAL_DNS_CLUSTER_LOCALITY);
|
String localityName = localityName(LOGICAL_DNS_CLUSTER_LOCALITY);
|
||||||
Attributes attr = eag.getAttributes().toBuilder()
|
Attributes attr = eag.getAttributes().toBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY, LOGICAL_DNS_CLUSTER_LOCALITY)
|
.set(XdsAttributes.ATTR_LOCALITY, LOGICAL_DNS_CLUSTER_LOCALITY)
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, localityName)
|
.set(XdsAttributes.ATTR_LOCALITY_NAME, localityName)
|
||||||
.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, dnsHostName)
|
.set(XdsAttributes.ATTR_ADDRESS_NAME, dnsHostName)
|
||||||
.build();
|
.build();
|
||||||
eag = new EquivalentAddressGroup(eag.getAddresses(), attr);
|
eag = new EquivalentAddressGroup(eag.getAddresses(), attr);
|
||||||
eag = AddressFilter.setPathFilter(eag, Arrays.asList(priorityName, localityName));
|
eag = AddressFilter.setPathFilter(eag, Arrays.asList(priorityName, localityName));
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
package io.grpc.xds;
|
package io.grpc.xds;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static io.grpc.xds.InternalXdsAttributes.ATTR_DRAIN_GRACE_NANOS;
|
import static io.grpc.xds.XdsAttributes.ATTR_DRAIN_GRACE_NANOS;
|
||||||
import static io.grpc.xds.InternalXdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
|
import static io.grpc.xds.XdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
|
||||||
import static io.grpc.xds.XdsServerWrapper.ATTR_SERVER_ROUTING_CONFIG;
|
import static io.grpc.xds.XdsServerWrapper.ATTR_SERVER_ROUTING_CONFIG;
|
||||||
import static io.grpc.xds.internal.security.SecurityProtocolNegotiators.ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER;
|
import static io.grpc.xds.internal.security.SecurityProtocolNegotiators.ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ final class GcpAuthenticationFilter implements Filter, ClientInterceptorBuilder
|
||||||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
|
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
|
||||||
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
|
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
|
||||||
|
|
||||||
/*String clusterName = callOptions.getOption(InternalXdsAttributes.ATTR_CLUSTER_NAME);
|
/*String clusterName = callOptions.getOption(XdsAttributes.ATTR_CLUSTER_NAME);
|
||||||
if (clusterName == null) {
|
if (clusterName == null) {
|
||||||
return next.newCall(method, callOptions);
|
return next.newCall(method, callOptions);
|
||||||
}*/
|
}*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 The gRPC Authors
|
* Copyright 2024 The gRPC Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -18,96 +18,19 @@ package io.grpc.xds;
|
||||||
|
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.EquivalentAddressGroup;
|
import io.grpc.EquivalentAddressGroup;
|
||||||
import io.grpc.Grpc;
|
|
||||||
import io.grpc.Internal;
|
import io.grpc.Internal;
|
||||||
import io.grpc.NameResolver;
|
|
||||||
import io.grpc.internal.ObjectPool;
|
|
||||||
import io.grpc.xds.XdsNameResolverProvider.CallCounterProvider;
|
|
||||||
import io.grpc.xds.client.Locality;
|
|
||||||
import io.grpc.xds.client.XdsClient;
|
|
||||||
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal attributes used for xDS implementation. Do not use.
|
* Internal attributes used for xDS implementation. Do not use.
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public final class InternalXdsAttributes {
|
public final class InternalXdsAttributes {
|
||||||
|
|
||||||
// TODO(sanjaypujare): move to xds internal package.
|
|
||||||
/** Attribute key for SslContextProviderSupplier (used from client) for a subchannel. */
|
|
||||||
@Grpc.TransportAttr
|
|
||||||
public static final Attributes.Key<SslContextProviderSupplier>
|
|
||||||
ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER =
|
|
||||||
Attributes.Key.create("io.grpc.xds.internal.security.SslContextProviderSupplier");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attribute key for passing around the XdsClient object pool across NameResolver/LoadBalancers.
|
|
||||||
*/
|
|
||||||
@NameResolver.ResolutionResultAttr
|
|
||||||
static final Attributes.Key<ObjectPool<XdsClient>> XDS_CLIENT_POOL =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.xdsClientPool");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attribute key for obtaining the global provider that provides atomics for aggregating
|
|
||||||
* outstanding RPCs sent to each cluster.
|
|
||||||
*/
|
|
||||||
@NameResolver.ResolutionResultAttr
|
|
||||||
static final Attributes.Key<CallCounterProvider> CALL_COUNTER_PROVIDER =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.callCounterProvider");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map from localities to their weights.
|
|
||||||
*/
|
|
||||||
@NameResolver.ResolutionResultAttr
|
|
||||||
static final Attributes.Key<Integer> ATTR_LOCALITY_WEIGHT =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.localityWeight");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the cluster that provides this EquivalentAddressGroup.
|
* Name of the cluster that provides this EquivalentAddressGroup.
|
||||||
*/
|
*/
|
||||||
@Internal
|
|
||||||
@EquivalentAddressGroup.Attr
|
@EquivalentAddressGroup.Attr
|
||||||
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
|
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.clusterName");
|
XdsAttributes.ATTR_CLUSTER_NAME;
|
||||||
|
|
||||||
/**
|
|
||||||
* The locality that this EquivalentAddressGroup is in.
|
|
||||||
*/
|
|
||||||
@EquivalentAddressGroup.Attr
|
|
||||||
static final Attributes.Key<Locality> ATTR_LOCALITY =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.locality");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the locality that this EquivalentAddressGroup is in.
|
|
||||||
*/
|
|
||||||
@EquivalentAddressGroup.Attr
|
|
||||||
static final Attributes.Key<String> ATTR_LOCALITY_NAME =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.localityName");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Endpoint weight for load balancing purposes.
|
|
||||||
*/
|
|
||||||
@EquivalentAddressGroup.Attr
|
|
||||||
static final Attributes.Key<Long> ATTR_SERVER_WEIGHT =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.serverWeight");
|
|
||||||
|
|
||||||
/** Name associated with individual address, if available (e.g., DNS name). */
|
|
||||||
@EquivalentAddressGroup.Attr
|
|
||||||
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.addressName");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter chain match for network filters.
|
|
||||||
*/
|
|
||||||
@Grpc.TransportAttr
|
|
||||||
static final Attributes.Key<FilterChainSelectorManager>
|
|
||||||
ATTR_FILTER_CHAIN_SELECTOR_MANAGER = Attributes.Key.create(
|
|
||||||
"io.grpc.xds.InternalXdsAttributes.filterChainSelectorManager");
|
|
||||||
|
|
||||||
/** Grace time to use when draining. Null for an infinite grace time. */
|
|
||||||
@Grpc.TransportAttr
|
|
||||||
static final Attributes.Key<Long> ATTR_DRAIN_GRACE_NANOS =
|
|
||||||
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.drainGraceTime");
|
|
||||||
|
|
||||||
private InternalXdsAttributes() {}
|
private InternalXdsAttributes() {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ final class RingHashLoadBalancer extends MultiChildLoadBalancer {
|
||||||
Map<EquivalentAddressGroup, Long> serverWeights = new HashMap<>();
|
Map<EquivalentAddressGroup, Long> serverWeights = new HashMap<>();
|
||||||
long totalWeight = 0L;
|
long totalWeight = 0L;
|
||||||
for (EquivalentAddressGroup eag : addrList) {
|
for (EquivalentAddressGroup eag : addrList) {
|
||||||
Long weight = eag.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT);
|
Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
|
||||||
// Support two ways of server weighing: either multiple instances of the same address
|
// Support two ways of server weighing: either multiple instances of the same address
|
||||||
// or each address contains a per-address weight attribute. If a weight is not provided,
|
// or each address contains a per-address weight attribute. If a weight is not provided,
|
||||||
// each occurrence of the address will be counted a weight value of one.
|
// each occurrence of the address will be counted a weight value of one.
|
||||||
|
|
@ -241,7 +241,7 @@ final class RingHashLoadBalancer extends MultiChildLoadBalancer {
|
||||||
|
|
||||||
long totalWeight = 0;
|
long totalWeight = 0;
|
||||||
for (EquivalentAddressGroup eag : addrList) {
|
for (EquivalentAddressGroup eag : addrList) {
|
||||||
Long weight = eag.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT);
|
Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
|
||||||
|
|
||||||
if (weight == null) {
|
if (weight == null) {
|
||||||
weight = 1L;
|
weight = 1L;
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ final class WrrLocalityLoadBalancer extends LoadBalancer {
|
||||||
Map<String, Integer> localityWeights = new HashMap<>();
|
Map<String, Integer> localityWeights = new HashMap<>();
|
||||||
for (EquivalentAddressGroup eag : resolvedAddresses.getAddresses()) {
|
for (EquivalentAddressGroup eag : resolvedAddresses.getAddresses()) {
|
||||||
Attributes eagAttrs = eag.getAttributes();
|
Attributes eagAttrs = eag.getAttributes();
|
||||||
String locality = eagAttrs.get(InternalXdsAttributes.ATTR_LOCALITY_NAME);
|
String locality = eagAttrs.get(XdsAttributes.ATTR_LOCALITY_NAME);
|
||||||
Integer localityWeight = eagAttrs.get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT);
|
Integer localityWeight = eagAttrs.get(XdsAttributes.ATTR_LOCALITY_WEIGHT);
|
||||||
|
|
||||||
if (locality == null) {
|
if (locality == null) {
|
||||||
Status unavailableStatus = Status.UNAVAILABLE.withDescription(
|
Status unavailableStatus = Status.UNAVAILABLE.withDescription(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 The gRPC Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.grpc.xds;
|
||||||
|
|
||||||
|
import io.grpc.Attributes;
|
||||||
|
import io.grpc.EquivalentAddressGroup;
|
||||||
|
import io.grpc.Grpc;
|
||||||
|
import io.grpc.NameResolver;
|
||||||
|
import io.grpc.internal.ObjectPool;
|
||||||
|
import io.grpc.xds.XdsNameResolverProvider.CallCounterProvider;
|
||||||
|
import io.grpc.xds.client.Locality;
|
||||||
|
import io.grpc.xds.client.XdsClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attributes used for xDS implementation.
|
||||||
|
*/
|
||||||
|
final class XdsAttributes {
|
||||||
|
/**
|
||||||
|
* Attribute key for passing around the XdsClient object pool across NameResolver/LoadBalancers.
|
||||||
|
*/
|
||||||
|
@NameResolver.ResolutionResultAttr
|
||||||
|
static final Attributes.Key<ObjectPool<XdsClient>> XDS_CLIENT_POOL =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.xdsClientPool");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute key for obtaining the global provider that provides atomics for aggregating
|
||||||
|
* outstanding RPCs sent to each cluster.
|
||||||
|
*/
|
||||||
|
@NameResolver.ResolutionResultAttr
|
||||||
|
static final Attributes.Key<CallCounterProvider> CALL_COUNTER_PROVIDER =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.callCounterProvider");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from localities to their weights.
|
||||||
|
*/
|
||||||
|
@NameResolver.ResolutionResultAttr
|
||||||
|
static final Attributes.Key<Integer> ATTR_LOCALITY_WEIGHT =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.localityWeight");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the cluster that provides this EquivalentAddressGroup.
|
||||||
|
*/
|
||||||
|
@EquivalentAddressGroup.Attr
|
||||||
|
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.clusterName");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The locality that this EquivalentAddressGroup is in.
|
||||||
|
*/
|
||||||
|
@EquivalentAddressGroup.Attr
|
||||||
|
static final Attributes.Key<Locality> ATTR_LOCALITY =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.locality");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the locality that this EquivalentAddressGroup is in.
|
||||||
|
*/
|
||||||
|
@EquivalentAddressGroup.Attr
|
||||||
|
static final Attributes.Key<String> ATTR_LOCALITY_NAME =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.localityName");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint weight for load balancing purposes.
|
||||||
|
*/
|
||||||
|
@EquivalentAddressGroup.Attr
|
||||||
|
static final Attributes.Key<Long> ATTR_SERVER_WEIGHT =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.serverWeight");
|
||||||
|
|
||||||
|
/** Name associated with individual address, if available (e.g., DNS name). */
|
||||||
|
@EquivalentAddressGroup.Attr
|
||||||
|
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.addressName");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter chain match for network filters.
|
||||||
|
*/
|
||||||
|
@Grpc.TransportAttr
|
||||||
|
static final Attributes.Key<FilterChainSelectorManager>
|
||||||
|
ATTR_FILTER_CHAIN_SELECTOR_MANAGER = Attributes.Key.create(
|
||||||
|
"io.grpc.xds.XdsAttributes.filterChainSelectorManager");
|
||||||
|
|
||||||
|
/** Grace time to use when draining. Null for an infinite grace time. */
|
||||||
|
@Grpc.TransportAttr
|
||||||
|
static final Attributes.Key<Long> ATTR_DRAIN_GRACE_NANOS =
|
||||||
|
Attributes.Key.create("io.grpc.xds.XdsAttributes.drainGraceTime");
|
||||||
|
|
||||||
|
private XdsAttributes() {}
|
||||||
|
}
|
||||||
|
|
@ -307,8 +307,8 @@ final class XdsNameResolver extends NameResolver {
|
||||||
ConfigOrError parsedServiceConfig = serviceConfigParser.parseServiceConfig(rawServiceConfig);
|
ConfigOrError parsedServiceConfig = serviceConfigParser.parseServiceConfig(rawServiceConfig);
|
||||||
Attributes attrs =
|
Attributes attrs =
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
||||||
.set(InternalXdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
|
.set(XdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
|
||||||
.set(InternalConfigSelector.KEY, configSelector)
|
.set(InternalConfigSelector.KEY, configSelector)
|
||||||
.build();
|
.build();
|
||||||
ResolutionResult result =
|
ResolutionResult result =
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ package io.grpc.xds;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static io.grpc.xds.InternalXdsAttributes.ATTR_DRAIN_GRACE_NANOS;
|
import static io.grpc.xds.XdsAttributes.ATTR_DRAIN_GRACE_NANOS;
|
||||||
import static io.grpc.xds.InternalXdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
|
import static io.grpc.xds.XdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.errorprone.annotations.DoNotCall;
|
import com.google.errorprone.annotations.DoNotCall;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
|
import io.grpc.Grpc;
|
||||||
import io.grpc.internal.GrpcUtil;
|
import io.grpc.internal.GrpcUtil;
|
||||||
import io.grpc.internal.ObjectPool;
|
import io.grpc.internal.ObjectPool;
|
||||||
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
||||||
|
|
@ -28,7 +29,6 @@ import io.grpc.netty.InternalProtocolNegotiator;
|
||||||
import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator;
|
import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator;
|
||||||
import io.grpc.netty.InternalProtocolNegotiators;
|
import io.grpc.netty.InternalProtocolNegotiators;
|
||||||
import io.grpc.netty.ProtocolNegotiationEvent;
|
import io.grpc.netty.ProtocolNegotiationEvent;
|
||||||
import io.grpc.xds.InternalXdsAttributes;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerAdapter;
|
import io.netty.channel.ChannelHandlerAdapter;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
@ -63,6 +63,12 @@ public final class SecurityProtocolNegotiators {
|
||||||
ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER =
|
ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER =
|
||||||
Attributes.Key.create("io.grpc.xds.internal.security.server.sslContextProviderSupplier");
|
Attributes.Key.create("io.grpc.xds.internal.security.server.sslContextProviderSupplier");
|
||||||
|
|
||||||
|
/** Attribute key for SslContextProviderSupplier (used from client) for a subchannel. */
|
||||||
|
@Grpc.TransportAttr
|
||||||
|
public static final Attributes.Key<SslContextProviderSupplier>
|
||||||
|
ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER =
|
||||||
|
Attributes.Key.create("io.grpc.xds.internal.security.SslContextProviderSupplier");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link InternalProtocolNegotiator.ClientFactory}.
|
* Returns a {@link InternalProtocolNegotiator.ClientFactory}.
|
||||||
*
|
*
|
||||||
|
|
@ -130,8 +136,7 @@ public final class SecurityProtocolNegotiators {
|
||||||
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
|
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
|
||||||
// check if SslContextProviderSupplier was passed via attributes
|
// check if SslContextProviderSupplier was passed via attributes
|
||||||
SslContextProviderSupplier localSslContextProviderSupplier =
|
SslContextProviderSupplier localSslContextProviderSupplier =
|
||||||
grpcHandler.getEagAttributes().get(
|
grpcHandler.getEagAttributes().get(ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||||
InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
|
||||||
if (localSslContextProviderSupplier == null) {
|
if (localSslContextProviderSupplier == null) {
|
||||||
checkNotNull(
|
checkNotNull(
|
||||||
fallbackProtocolNegotiator, "No TLS config and no fallbackProtocolNegotiator!");
|
fallbackProtocolNegotiator, "No TLS config and no fallbackProtocolNegotiator!");
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ public class CdsLoadBalancer2Test {
|
||||||
.setAttributes(
|
.setAttributes(
|
||||||
// Other attributes not used by cluster_resolver LB are omitted.
|
// Other attributes not used by cluster_resolver LB are omitted.
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
||||||
.build())
|
.build())
|
||||||
.setLoadBalancingPolicyConfig(new CdsConfig(CLUSTER))
|
.setLoadBalancingPolicyConfig(new CdsConfig(CLUSTER))
|
||||||
.build());
|
.build());
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ import io.grpc.xds.client.Stats.ClusterStats;
|
||||||
import io.grpc.xds.client.Stats.UpstreamLocalityStats;
|
import io.grpc.xds.client.Stats.UpstreamLocalityStats;
|
||||||
import io.grpc.xds.client.XdsClient;
|
import io.grpc.xds.client.XdsClient;
|
||||||
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
||||||
|
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
|
||||||
import io.grpc.xds.internal.security.SslContextProvider;
|
import io.grpc.xds.internal.security.SslContextProvider;
|
||||||
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
@ -195,7 +196,7 @@ public class ClusterImplLoadBalancerTest {
|
||||||
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(downstreamBalancers);
|
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(downstreamBalancers);
|
||||||
assertThat(Iterables.getOnlyElement(childBalancer.addresses)).isEqualTo(endpoint);
|
assertThat(Iterables.getOnlyElement(childBalancer.addresses)).isEqualTo(endpoint);
|
||||||
assertThat(childBalancer.config).isSameInstanceAs(weightedTargetConfig);
|
assertThat(childBalancer.config).isSameInstanceAs(weightedTargetConfig);
|
||||||
assertThat(childBalancer.attributes.get(InternalXdsAttributes.XDS_CLIENT_POOL))
|
assertThat(childBalancer.attributes.get(XdsAttributes.XDS_CLIENT_POOL))
|
||||||
.isSameInstanceAs(xdsClientPool);
|
.isSameInstanceAs(xdsClientPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -533,7 +534,7 @@ public class ClusterImplLoadBalancerTest {
|
||||||
.setAddresses(Collections.singletonList(endpoint))
|
.setAddresses(Collections.singletonList(endpoint))
|
||||||
.setAttributes(
|
.setAttributes(
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
||||||
.build())
|
.build())
|
||||||
.setLoadBalancingPolicyConfig(config)
|
.setLoadBalancingPolicyConfig(config)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -738,14 +739,14 @@ public class ClusterImplLoadBalancerTest {
|
||||||
.build();
|
.build();
|
||||||
Subchannel subchannel = leafBalancer.helper.createSubchannel(args);
|
Subchannel subchannel = leafBalancer.helper.createSubchannel(args);
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_CLUSTER_NAME))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_CLUSTER_NAME))
|
||||||
.isEqualTo(CLUSTER);
|
.isEqualTo(CLUSTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An address update should also retain the cluster attribute.
|
// An address update should also retain the cluster attribute.
|
||||||
subchannel.updateAddresses(leafBalancer.addresses);
|
subchannel.updateAddresses(leafBalancer.addresses);
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_CLUSTER_NAME))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_CLUSTER_NAME))
|
||||||
.isEqualTo(CLUSTER);
|
.isEqualTo(CLUSTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -783,10 +784,10 @@ public class ClusterImplLoadBalancerTest {
|
||||||
new FixedResultPicker(PickResult.withSubchannel(subchannel)));
|
new FixedResultPicker(PickResult.withSubchannel(subchannel)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertThat(subchannel.getAttributes().get(InternalXdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(
|
assertThat(subchannel.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(
|
||||||
"authority-host-name");
|
"authority-host-name");
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_ADDRESS_NAME))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME))
|
||||||
.isEqualTo("authority-host-name");
|
.isEqualTo("authority-host-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -835,9 +836,9 @@ public class ClusterImplLoadBalancerTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Sub Channel wrapper args won't have the address name although addresses will.
|
// Sub Channel wrapper args won't have the address name although addresses will.
|
||||||
assertThat(subchannel.getAttributes().get(InternalXdsAttributes.ATTR_ADDRESS_NAME)).isNull();
|
assertThat(subchannel.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)).isNull();
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_ADDRESS_NAME))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME))
|
||||||
.isEqualTo("authority-host-name");
|
.isEqualTo("authority-host-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -877,7 +878,7 @@ public class ClusterImplLoadBalancerTest {
|
||||||
Subchannel subchannel = leafBalancer.helper.createSubchannel(args);
|
Subchannel subchannel = leafBalancer.helper.createSubchannel(args);
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
SslContextProviderSupplier supplier =
|
SslContextProviderSupplier supplier =
|
||||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
eag.getAttributes().get(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||||
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -891,7 +892,8 @@ public class ClusterImplLoadBalancerTest {
|
||||||
assertThat(Iterables.getOnlyElement(downstreamBalancers)).isSameInstanceAs(leafBalancer);
|
assertThat(Iterables.getOnlyElement(downstreamBalancers)).isSameInstanceAs(leafBalancer);
|
||||||
subchannel = leafBalancer.helper.createSubchannel(args); // creates new connections
|
subchannel = leafBalancer.helper.createSubchannel(args); // creates new connections
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER))
|
assertThat(
|
||||||
|
eag.getAttributes().get(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER))
|
||||||
.isNull();
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -908,14 +910,14 @@ public class ClusterImplLoadBalancerTest {
|
||||||
subchannel = leafBalancer.helper.createSubchannel(args); // creates new connections
|
subchannel = leafBalancer.helper.createSubchannel(args); // creates new connections
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
SslContextProviderSupplier supplier =
|
SslContextProviderSupplier supplier =
|
||||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
eag.getAttributes().get(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||||
assertThat(supplier.isShutdown()).isFalse();
|
assertThat(supplier.isShutdown()).isFalse();
|
||||||
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
assertThat(supplier.getTlsContext()).isEqualTo(upstreamTlsContext);
|
||||||
}
|
}
|
||||||
loadBalancer.shutdown();
|
loadBalancer.shutdown();
|
||||||
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
|
||||||
SslContextProviderSupplier supplier =
|
SslContextProviderSupplier supplier =
|
||||||
eag.getAttributes().get(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
eag.getAttributes().get(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER);
|
||||||
assertThat(supplier.isShutdown()).isTrue();
|
assertThat(supplier.isShutdown()).isTrue();
|
||||||
}
|
}
|
||||||
loadBalancer = null;
|
loadBalancer = null;
|
||||||
|
|
@ -928,8 +930,8 @@ public class ClusterImplLoadBalancerTest {
|
||||||
.setAddresses(addresses)
|
.setAddresses(addresses)
|
||||||
.setAttributes(
|
.setAttributes(
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
||||||
.set(InternalXdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
|
.set(XdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
|
||||||
.build())
|
.build())
|
||||||
.setLoadBalancingPolicyConfig(config)
|
.setLoadBalancingPolicyConfig(config)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -986,11 +988,11 @@ public class ClusterImplLoadBalancerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Attributes.Builder attributes = Attributes.newBuilder()
|
Attributes.Builder attributes = Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY, locality)
|
.set(XdsAttributes.ATTR_LOCALITY, locality)
|
||||||
// Unique but arbitrary string
|
// Unique but arbitrary string
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, locality.toString());
|
.set(XdsAttributes.ATTR_LOCALITY_NAME, locality.toString());
|
||||||
if (authorityHostname != null) {
|
if (authorityHostname != null) {
|
||||||
attributes.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, authorityHostname);
|
attributes.set(XdsAttributes.ATTR_ADDRESS_NAME, authorityHostname);
|
||||||
}
|
}
|
||||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
|
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
|
||||||
attributes.build());
|
attributes.build());
|
||||||
|
|
|
||||||
|
|
@ -272,13 +272,13 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
// Endpoints in locality1 have no endpoint-level weight specified, so all endpoints within
|
// Endpoints in locality1 have no endpoint-level weight specified, so all endpoints within
|
||||||
// locality1 are equally weighted.
|
// locality1 are equally weighted.
|
||||||
assertThat(addr1.getAddresses()).isEqualTo(endpoint1.getAddresses());
|
assertThat(addr1.getAddresses()).isEqualTo(endpoint1.getAddresses());
|
||||||
assertThat(addr1.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT))
|
assertThat(addr1.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT))
|
||||||
.isEqualTo(10);
|
.isEqualTo(10);
|
||||||
assertThat(addr2.getAddresses()).isEqualTo(endpoint2.getAddresses());
|
assertThat(addr2.getAddresses()).isEqualTo(endpoint2.getAddresses());
|
||||||
assertThat(addr2.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT))
|
assertThat(addr2.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT))
|
||||||
.isEqualTo(10);
|
.isEqualTo(10);
|
||||||
assertThat(addr3.getAddresses()).isEqualTo(endpoint3.getAddresses());
|
assertThat(addr3.getAddresses()).isEqualTo(endpoint3.getAddresses());
|
||||||
assertThat(addr3.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT))
|
assertThat(addr3.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT))
|
||||||
.isEqualTo(50 * 60);
|
.isEqualTo(50 * 60);
|
||||||
assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
|
assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
|
||||||
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
|
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
|
||||||
|
|
@ -342,7 +342,7 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
childBalancer.addresses.get(0).getAttributes()
|
childBalancer.addresses.get(0).getAttributes()
|
||||||
.get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT)).isEqualTo(100);
|
.get(XdsAttributes.ATTR_LOCALITY_WEIGHT)).isEqualTo(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -368,7 +368,7 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
childBalancer.addresses.get(0).getAttributes()
|
childBalancer.addresses.get(0).getAttributes()
|
||||||
.get(InternalXdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
|
.get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -468,16 +468,16 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
assertThat(childProvider3.getPolicyName()).isEqualTo("round_robin");
|
assertThat(childProvider3.getPolicyName()).isEqualTo("round_robin");
|
||||||
|
|
||||||
for (EquivalentAddressGroup eag : childBalancer.addresses) {
|
for (EquivalentAddressGroup eag : childBalancer.addresses) {
|
||||||
if (eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY) == locality1) {
|
if (eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY) == locality1) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY_WEIGHT))
|
||||||
.isEqualTo(70);
|
.isEqualTo(70);
|
||||||
}
|
}
|
||||||
if (eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY) == locality2) {
|
if (eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY) == locality2) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY_WEIGHT))
|
||||||
.isEqualTo(10);
|
.isEqualTo(10);
|
||||||
}
|
}
|
||||||
if (eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY) == locality3) {
|
if (eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY) == locality3) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT))
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY_WEIGHT))
|
||||||
.isEqualTo(20);
|
.isEqualTo(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -659,7 +659,7 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
|
|
||||||
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
|
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
|
||||||
for (EquivalentAddressGroup eag : childBalancer.addresses) {
|
for (EquivalentAddressGroup eag : childBalancer.addresses) {
|
||||||
assertThat(eag.getAttributes().get(InternalXdsAttributes.ATTR_LOCALITY)).isEqualTo(locality2);
|
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_LOCALITY)).isEqualTo(locality2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -740,9 +740,9 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
Collections.<DropOverload>emptyList(), "pick_first");
|
Collections.<DropOverload>emptyList(), "pick_first");
|
||||||
assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), childBalancer.addresses);
|
assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), childBalancer.addresses);
|
||||||
assertThat(childBalancer.addresses.get(0).getAttributes()
|
assertThat(childBalancer.addresses.get(0).getAttributes()
|
||||||
.get(InternalXdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME);
|
.get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME);
|
||||||
assertThat(childBalancer.addresses.get(1).getAttributes()
|
assertThat(childBalancer.addresses.get(1).getAttributes()
|
||||||
.get(InternalXdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME);
|
.get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1068,7 +1068,7 @@ public class ClusterResolverLoadBalancerTest {
|
||||||
.setAttributes(
|
.setAttributes(
|
||||||
// Other attributes not used by cluster_resolver LB are omitted.
|
// Other attributes not used by cluster_resolver LB are omitted.
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
|
||||||
.build())
|
.build())
|
||||||
.setLoadBalancingPolicyConfig(config)
|
.setLoadBalancingPolicyConfig(config)
|
||||||
.build());
|
.build());
|
||||||
|
|
|
||||||
|
|
@ -1084,7 +1084,7 @@ public class RingHashLoadBalancerTest {
|
||||||
for (int i = 0; i < weights.length; i++) {
|
for (int i = 0; i < weights.length; i++) {
|
||||||
SocketAddress addr = new FakeSocketAddress("server" + i);
|
SocketAddress addr = new FakeSocketAddress("server" + i);
|
||||||
Attributes attr = Attributes.newBuilder().set(
|
Attributes attr = Attributes.newBuilder().set(
|
||||||
InternalXdsAttributes.ATTR_SERVER_WEIGHT, weights[i]).build();
|
XdsAttributes.ATTR_SERVER_WEIGHT, weights[i]).build();
|
||||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(addr, attr);
|
EquivalentAddressGroup eag = new EquivalentAddressGroup(addr, attr);
|
||||||
addrs.add(eag);
|
addrs.add(eag);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ public class WrrLocalityLoadBalancerTest {
|
||||||
verify(mockWeightedTargetLb).handleResolvedAddresses(resolvedAddressesCaptor.capture());
|
verify(mockWeightedTargetLb).handleResolvedAddresses(resolvedAddressesCaptor.capture());
|
||||||
|
|
||||||
//assertThat(resolvedAddressesCaptor.getValue().getAttributes()
|
//assertThat(resolvedAddressesCaptor.getValue().getAttributes()
|
||||||
// .get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHTS)).isNull();
|
// .get(XdsAttributes.ATTR_LOCALITY_WEIGHTS)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -254,9 +254,9 @@ public class WrrLocalityLoadBalancerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Attributes.Builder attrBuilder = Attributes.newBuilder()
|
Attributes.Builder attrBuilder = Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, locality);
|
.set(XdsAttributes.ATTR_LOCALITY_NAME, locality);
|
||||||
if (localityWeight != null) {
|
if (localityWeight != null) {
|
||||||
attrBuilder.set(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT, localityWeight);
|
attrBuilder.set(XdsAttributes.ATTR_LOCALITY_WEIGHT, localityWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
|
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
|
||||||
|
|
|
||||||
|
|
@ -755,8 +755,8 @@ public class XdsNameResolverTest {
|
||||||
assertServiceConfigForLoadBalancingConfig(
|
assertServiceConfigForLoadBalancingConfig(
|
||||||
Collections.singletonList(cluster2),
|
Collections.singletonList(cluster2),
|
||||||
(Map<String, ?>) result.getServiceConfig().getConfig());
|
(Map<String, ?>) result.getServiceConfig().getConfig());
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
|
||||||
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
||||||
// Simulates making a call1 RPC.
|
// Simulates making a call1 RPC.
|
||||||
Result selectResult = configSelector.selectConfig(
|
Result selectResult = configSelector.selectConfig(
|
||||||
|
|
@ -1156,7 +1156,7 @@ public class XdsNameResolverTest {
|
||||||
assertThat(result.getAddressesOrError().getValue()).isEmpty();
|
assertThat(result.getAddressesOrError().getValue()).isEmpty();
|
||||||
assertServiceConfigForLoadBalancingConfig(
|
assertServiceConfigForLoadBalancingConfig(
|
||||||
Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
|
Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
||||||
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
||||||
assertCallSelectClusterResult(call1, configSelector, cluster2, 20.0);
|
assertCallSelectClusterResult(call1, configSelector, cluster2, 20.0);
|
||||||
assertCallSelectClusterResult(call1, configSelector, cluster1, 20.0);
|
assertCallSelectClusterResult(call1, configSelector, cluster1, 20.0);
|
||||||
|
|
@ -1207,7 +1207,7 @@ public class XdsNameResolverTest {
|
||||||
ImmutableList.of(ImmutableMap.of("rls_experimental", expectedRlsLbConfig)))));
|
ImmutableList.of(ImmutableMap.of("rls_experimental", expectedRlsLbConfig)))));
|
||||||
assertThat(clusterManagerLbConfig).isEqualTo(expectedClusterManagerLbConfig);
|
assertThat(clusterManagerLbConfig).isEqualTo(expectedClusterManagerLbConfig);
|
||||||
|
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
||||||
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
|
||||||
assertCallSelectRlsPluginResult(
|
assertCallSelectRlsPluginResult(
|
||||||
call1, configSelector, "rls-plugin-foo", 20.0);
|
call1, configSelector, "rls-plugin-foo", 20.0);
|
||||||
|
|
@ -1345,8 +1345,8 @@ public class XdsNameResolverTest {
|
||||||
assertThat(result.getAddressesOrError().getValue()).isEmpty();
|
assertThat(result.getAddressesOrError().getValue()).isEmpty();
|
||||||
assertServiceConfigForLoadBalancingConfig(
|
assertServiceConfigForLoadBalancingConfig(
|
||||||
Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
|
Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL)).isNotNull();
|
||||||
assertThat(result.getAttributes().get(InternalXdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
|
assertThat(result.getAttributes().get(XdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
|
||||||
return result.getAttributes().get(InternalConfigSelector.KEY);
|
return result.getAttributes().get(InternalConfigSelector.KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ import io.grpc.xds.client.Bootstrapper;
|
||||||
import io.grpc.xds.client.CommonBootstrapperTestUtils;
|
import io.grpc.xds.client.CommonBootstrapperTestUtils;
|
||||||
import io.grpc.xds.internal.Matchers.HeaderMatcher;
|
import io.grpc.xds.internal.Matchers.HeaderMatcher;
|
||||||
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
||||||
|
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
|
||||||
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
import io.grpc.xds.internal.security.SslContextProviderSupplier;
|
||||||
import io.grpc.xds.internal.security.TlsContextManagerImpl;
|
import io.grpc.xds.internal.security.TlsContextManagerImpl;
|
||||||
import io.grpc.xds.internal.security.certprovider.FileWatcherCertificateProviderProvider;
|
import io.grpc.xds.internal.security.certprovider.FileWatcherCertificateProviderProvider;
|
||||||
|
|
@ -653,7 +654,7 @@ public class XdsSecurityClientServerTest {
|
||||||
Attributes attrs =
|
Attributes attrs =
|
||||||
(upstreamTlsContext != null)
|
(upstreamTlsContext != null)
|
||||||
? Attributes.newBuilder()
|
? Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
.set(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
||||||
new SslContextProviderSupplier(
|
new SslContextProviderSupplier(
|
||||||
upstreamTlsContext, tlsContextManagerForClient))
|
upstreamTlsContext, tlsContextManagerForClient))
|
||||||
.build()
|
.build()
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ import io.grpc.netty.InternalProtocolNegotiators;
|
||||||
import io.grpc.netty.ProtocolNegotiationEvent;
|
import io.grpc.netty.ProtocolNegotiationEvent;
|
||||||
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.InternalXdsAttributes;
|
|
||||||
import io.grpc.xds.TlsContextManager;
|
import io.grpc.xds.TlsContextManager;
|
||||||
import io.grpc.xds.client.Bootstrapper;
|
import io.grpc.xds.client.Bootstrapper;
|
||||||
import io.grpc.xds.client.CommonBootstrapperTestUtils;
|
import io.grpc.xds.client.CommonBootstrapperTestUtils;
|
||||||
|
|
@ -134,7 +133,7 @@ public class SecurityProtocolNegotiatorsTest {
|
||||||
when(mockHandler.getEagAttributes())
|
when(mockHandler.getEagAttributes())
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
.set(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
|
||||||
new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager))
|
new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager))
|
||||||
.build());
|
.build());
|
||||||
ChannelHandler newHandler = pn.newHandler(mockHandler);
|
ChannelHandler newHandler = pn.newHandler(mockHandler);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue