Skip to content

Commit afc1f2e

Browse files
authored
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.
1 parent 1df7d7e commit afc1f2e

File tree

8 files changed

+24
-34
lines changed

8 files changed

+24
-34
lines changed

alts/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ java_library(
1111
":handshaker_java_proto",
1212
"//api",
1313
"//core:internal",
14+
"//grpclb",
1415
"//netty",
1516
"//stub",
1617
"@com_google_code_findbugs_jsr305//jar",
@@ -32,7 +33,6 @@ java_library(
3233
"src/main/java/io/grpc/alts/*.java",
3334
]),
3435
visibility = ["//visibility:public"],
35-
runtime_deps = ["//grpclb"],
3636
deps = [
3737
":alts_internal",
3838
":handshaker_java_grpc",

alts/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ targetCompatibility = 1.7
1515
dependencies {
1616
compile project(':grpc-auth'),
1717
project(':grpc-core'),
18+
project(':grpc-grpclb'),
1819
project(':grpc-netty'),
1920
project(':grpc-protobuf'),
2021
project(':grpc-stub'),
@@ -28,7 +29,6 @@ dependencies {
2829
exclude group: 'io.grpc', module: 'grpc-context'
2930
}
3031
compileOnly libraries.javax_annotation
31-
runtime project(':grpc-grpclb')
3232
testCompile project(':grpc-testing'),
3333
project(':grpc-testing-proto'),
3434
libraries.guava,

alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.grpc.SecurityLevel;
3030
import io.grpc.Status;
3131
import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult;
32-
import io.grpc.internal.GrpcAttributes;
32+
import io.grpc.grpclb.GrpclbConstants;
3333
import io.grpc.internal.ObjectPool;
3434
import io.grpc.netty.GrpcHttp2ConnectionHandler;
3535
import io.grpc.netty.InternalNettyChannelBuilder;
@@ -223,13 +223,13 @@ public AsciiString scheme() {
223223
return SCHEME;
224224
}
225225

226-
@SuppressWarnings("deprecation")
227226
@Override
228227
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
229228
ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler);
230229
ChannelHandler securityHandler;
231-
if (grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY) != null
232-
|| grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND) != null) {
230+
if (grpcHandler.getEagAttributes().get(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY) != null
231+
|| grpcHandler.getEagAttributes().get(
232+
GrpclbConstants.ATTR_LB_PROVIDED_BACKEND) != null) {
233233
TsiHandshaker handshaker = handshakerFactory.newHandshaker(grpcHandler.getAuthority());
234234
NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker);
235235
securityHandler =

alts/src/test/java/io/grpc/alts/internal/GoogleDefaultProtocolNegotiatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import io.grpc.Attributes;
2525
import io.grpc.Channel;
2626
import io.grpc.ManagedChannel;
27+
import io.grpc.grpclb.GrpclbConstants;
2728
import io.grpc.inprocess.InProcessChannelBuilder;
28-
import io.grpc.internal.GrpcAttributes;
2929
import io.grpc.internal.ObjectPool;
3030
import io.grpc.netty.GrpcHttp2ConnectionHandler;
3131
import io.grpc.netty.GrpcSslContexts;
@@ -80,7 +80,7 @@ public void tearDown() {
8080
@Test
8181
public void altsHandler() {
8282
Attributes eagAttributes =
83-
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
83+
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
8484
GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
8585
when(mockHandler.getEagAttributes()).thenReturn(eagAttributes);
8686

core/src/main/java/io/grpc/internal/GrpcAttributes.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,6 @@
2525
* Special attributes that are only useful to gRPC.
2626
*/
2727
public final class GrpcAttributes {
28-
/**
29-
* The naming authority of a gRPC LB server address. It is an address-group-level attribute,
30-
* present when the address group is a LoadBalancer.
31-
*
32-
* <p>Deprecated: this will be used for grpclb specific logic, which will be moved out of core.
33-
*/
34-
@Deprecated
35-
@EquivalentAddressGroup.Attr
36-
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
37-
Attributes.Key.create("io.grpc.grpclb.lbAddrAuthority");
38-
39-
/**
40-
* Whether this EquivalentAddressGroup was provided by a GRPCLB server. It would be rare for this
41-
* value to be {@code false}; generally it would be better to not have the key present at all.
42-
*/
43-
@EquivalentAddressGroup.Attr
44-
public static final Attributes.Key<Boolean> ATTR_LB_PROVIDED_BACKEND =
45-
Attributes.Key.create("io.grpc.grpclb.lbProvidedBackend");
46-
4728
/**
4829
* The security level of the transport. If it's not present, {@link SecurityLevel#NONE} should be
4930
* assumed.

grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,21 @@ public final class GrpclbConstants {
4848
static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
4949
Attributes.Key.create("io.grpc.grpclb.lbAddrs");
5050

51-
@SuppressWarnings("deprecation")
51+
/**
52+
* The naming authority of a gRPC LB server address. It is an address-group-level attribute,
53+
* present when the address group is a LoadBalancer.
54+
*/
55+
@EquivalentAddressGroup.Attr
56+
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
57+
Attributes.Key.create("io.grpc.grpclb.lbAddrAuthority");
58+
59+
/**
60+
* Whether this EquivalentAddressGroup was provided by a GRPCLB server. It would be rare for this
61+
* value to be {@code false}; generally it would be better to not have the key present at all.
62+
*/
5263
@EquivalentAddressGroup.Attr
53-
static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
54-
io.grpc.internal.GrpcAttributes.ATTR_LB_ADDR_AUTHORITY;
64+
public static final Attributes.Key<Boolean> ATTR_LB_PROVIDED_BACKEND =
65+
Attributes.Key.create("io.grpc.grpclb.lbProvidedBackend");
5566

5667
private GrpclbConstants() { }
5768
}

grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import io.grpc.SynchronizationContext;
4848
import io.grpc.SynchronizationContext.ScheduledHandle;
4949
import io.grpc.internal.BackoffPolicy;
50-
import io.grpc.internal.GrpcAttributes;
5150
import io.grpc.internal.TimeProvider;
5251
import io.grpc.lb.v1.ClientStats;
5352
import io.grpc.lb.v1.InitialLoadBalanceRequest;
@@ -86,7 +85,7 @@
8685
final class GrpclbState {
8786
static final long FALLBACK_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
8887
private static final Attributes LB_PROVIDED_BACKEND_ATTRS =
89-
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
88+
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
9089

9190
@VisibleForTesting
9291
static final PickResult DROP_PICK_RESULT =

grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import io.grpc.inprocess.InProcessServerBuilder;
7777
import io.grpc.internal.BackoffPolicy;
7878
import io.grpc.internal.FakeClock;
79-
import io.grpc.internal.GrpcAttributes;
8079
import io.grpc.internal.JsonParser;
8180
import io.grpc.lb.v1.ClientStats;
8281
import io.grpc.lb.v1.ClientStatsPerToken;
@@ -142,7 +141,7 @@ public boolean shouldAccept(Runnable command) {
142141
}
143142
};
144143
private static final Attributes LB_BACKEND_ATTRS =
145-
Attributes.newBuilder().set(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND, true).build();
144+
Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
146145

147146
@Mock
148147
private Helper helper;

0 commit comments

Comments
 (0)