core, grpclb: clean up grpclb specific attributes in core (#6790)

Move ATTR_LB_ADDR_AUTHORITY and ATTR_LB_PROVIDED_BACKEND attributes definition in GrpcAttributes to GrpclbConstants. grpc-alts will have a compile dependency on grpc-grpclb.
This commit is contained in:
Chengyuan Zhang 2020-03-02 10:27:57 -08:00 committed by GitHub
parent 1df7d7ea8e
commit afc1f2e567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 34 deletions

View File

@ -11,6 +11,7 @@ java_library(
":handshaker_java_proto",
"//api",
"//core:internal",
"//grpclb",
"//netty",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
@ -32,7 +33,6 @@ java_library(
"src/main/java/io/grpc/alts/*.java",
]),
visibility = ["//visibility:public"],
runtime_deps = ["//grpclb"],
deps = [
":alts_internal",
":handshaker_java_grpc",

View File

@ -15,6 +15,7 @@ targetCompatibility = 1.7
dependencies {
compile project(':grpc-auth'),
project(':grpc-core'),
project(':grpc-grpclb'),
project(':grpc-netty'),
project(':grpc-protobuf'),
project(':grpc-stub'),
@ -28,7 +29,6 @@ dependencies {
exclude group: 'io.grpc', module: 'grpc-context'
}
compileOnly libraries.javax_annotation
runtime project(':grpc-grpclb')
testCompile project(':grpc-testing'),
project(':grpc-testing-proto'),
libraries.guava,

View File

@ -29,7 +29,7 @@ import io.grpc.InternalChannelz.Security;
import io.grpc.SecurityLevel;
import io.grpc.Status;
import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult;
import io.grpc.internal.GrpcAttributes;
import io.grpc.grpclb.GrpclbConstants;
import io.grpc.internal.ObjectPool;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
import io.grpc.netty.InternalNettyChannelBuilder;
@ -223,13 +223,13 @@ public final class AltsProtocolNegotiator {
return SCHEME;
}
@SuppressWarnings("deprecation")
@Override
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler);
ChannelHandler securityHandler;
if (grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY) != null
|| grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND) != null) {
if (grpcHandler.getEagAttributes().get(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY) != null
|| grpcHandler.getEagAttributes().get(
GrpclbConstants.ATTR_LB_PROVIDED_BACKEND) != null) {
TsiHandshaker handshaker = handshakerFactory.newHandshaker(grpcHandler.getAuthority());
NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker);
securityHandler =

View File

@ -24,8 +24,8 @@ import com.google.common.collect.ImmutableList;
import io.grpc.Attributes;
import io.grpc.Channel;
import io.grpc.ManagedChannel;
import io.grpc.grpclb.GrpclbConstants;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.ObjectPool;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
import io.grpc.netty.GrpcSslContexts;
@ -80,7 +80,7 @@ public final class GoogleDefaultProtocolNegotiatorTest {
@Test
public void altsHandler() {
Attributes eagAttributes =
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
when(mockHandler.getEagAttributes()).thenReturn(eagAttributes);

View File

@ -25,25 +25,6 @@ import io.grpc.SecurityLevel;
* Special attributes that are only useful to gRPC.
*/
public final class GrpcAttributes {
/**
* The naming authority of a gRPC LB server address. It is an address-group-level attribute,
* present when the address group is a LoadBalancer.
*
* <p>Deprecated: this will be used for grpclb specific logic, which will be moved out of core.
*/
@Deprecated
@EquivalentAddressGroup.Attr
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
Attributes.Key.create("io.grpc.grpclb.lbAddrAuthority");
/**
* Whether this EquivalentAddressGroup was provided by a GRPCLB server. It would be rare for this
* value to be {@code false}; generally it would be better to not have the key present at all.
*/
@EquivalentAddressGroup.Attr
public static final Attributes.Key<Boolean> ATTR_LB_PROVIDED_BACKEND =
Attributes.Key.create("io.grpc.grpclb.lbProvidedBackend");
/**
* The security level of the transport. If it's not present, {@link SecurityLevel#NONE} should be
* assumed.

View File

@ -48,10 +48,21 @@ public final class GrpclbConstants {
static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
Attributes.Key.create("io.grpc.grpclb.lbAddrs");
@SuppressWarnings("deprecation")
/**
* The naming authority of a gRPC LB server address. It is an address-group-level attribute,
* present when the address group is a LoadBalancer.
*/
@EquivalentAddressGroup.Attr
static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
io.grpc.internal.GrpcAttributes.ATTR_LB_ADDR_AUTHORITY;
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
Attributes.Key.create("io.grpc.grpclb.lbAddrAuthority");
/**
* Whether this EquivalentAddressGroup was provided by a GRPCLB server. It would be rare for this
* value to be {@code false}; generally it would be better to not have the key present at all.
*/
@EquivalentAddressGroup.Attr
public static final Attributes.Key<Boolean> ATTR_LB_PROVIDED_BACKEND =
Attributes.Key.create("io.grpc.grpclb.lbProvidedBackend");
private GrpclbConstants() { }
}

View File

@ -47,7 +47,6 @@ import io.grpc.Status;
import io.grpc.SynchronizationContext;
import io.grpc.SynchronizationContext.ScheduledHandle;
import io.grpc.internal.BackoffPolicy;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.TimeProvider;
import io.grpc.lb.v1.ClientStats;
import io.grpc.lb.v1.InitialLoadBalanceRequest;
@ -86,7 +85,7 @@ import javax.annotation.concurrent.NotThreadSafe;
final class GrpclbState {
static final long FALLBACK_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
private static final Attributes LB_PROVIDED_BACKEND_ATTRS =
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
@VisibleForTesting
static final PickResult DROP_PICK_RESULT =

View File

@ -76,7 +76,6 @@ import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.internal.BackoffPolicy;
import io.grpc.internal.FakeClock;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.JsonParser;
import io.grpc.lb.v1.ClientStats;
import io.grpc.lb.v1.ClientStatsPerToken;
@ -142,7 +141,7 @@ public class GrpclbLoadBalancerTest {
}
};
private static final Attributes LB_BACKEND_ATTRS =
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
@Mock
private Helper helper;