mirror of https://github.com/grpc/grpc-java.git
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:
parent
1df7d7ea8e
commit
afc1f2e567
|
|
@ -11,6 +11,7 @@ java_library(
|
||||||
":handshaker_java_proto",
|
":handshaker_java_proto",
|
||||||
"//api",
|
"//api",
|
||||||
"//core:internal",
|
"//core:internal",
|
||||||
|
"//grpclb",
|
||||||
"//netty",
|
"//netty",
|
||||||
"//stub",
|
"//stub",
|
||||||
"@com_google_code_findbugs_jsr305//jar",
|
"@com_google_code_findbugs_jsr305//jar",
|
||||||
|
|
@ -32,7 +33,6 @@ java_library(
|
||||||
"src/main/java/io/grpc/alts/*.java",
|
"src/main/java/io/grpc/alts/*.java",
|
||||||
]),
|
]),
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
runtime_deps = ["//grpclb"],
|
|
||||||
deps = [
|
deps = [
|
||||||
":alts_internal",
|
":alts_internal",
|
||||||
":handshaker_java_grpc",
|
":handshaker_java_grpc",
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ targetCompatibility = 1.7
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':grpc-auth'),
|
compile project(':grpc-auth'),
|
||||||
project(':grpc-core'),
|
project(':grpc-core'),
|
||||||
|
project(':grpc-grpclb'),
|
||||||
project(':grpc-netty'),
|
project(':grpc-netty'),
|
||||||
project(':grpc-protobuf'),
|
project(':grpc-protobuf'),
|
||||||
project(':grpc-stub'),
|
project(':grpc-stub'),
|
||||||
|
|
@ -28,7 +29,6 @@ dependencies {
|
||||||
exclude group: 'io.grpc', module: 'grpc-context'
|
exclude group: 'io.grpc', module: 'grpc-context'
|
||||||
}
|
}
|
||||||
compileOnly libraries.javax_annotation
|
compileOnly libraries.javax_annotation
|
||||||
runtime project(':grpc-grpclb')
|
|
||||||
testCompile project(':grpc-testing'),
|
testCompile project(':grpc-testing'),
|
||||||
project(':grpc-testing-proto'),
|
project(':grpc-testing-proto'),
|
||||||
libraries.guava,
|
libraries.guava,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import io.grpc.InternalChannelz.Security;
|
||||||
import io.grpc.SecurityLevel;
|
import io.grpc.SecurityLevel;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult;
|
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.internal.ObjectPool;
|
||||||
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
||||||
import io.grpc.netty.InternalNettyChannelBuilder;
|
import io.grpc.netty.InternalNettyChannelBuilder;
|
||||||
|
|
@ -223,13 +223,13 @@ public final class AltsProtocolNegotiator {
|
||||||
return SCHEME;
|
return SCHEME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
|
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
|
||||||
ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler);
|
ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler);
|
||||||
ChannelHandler securityHandler;
|
ChannelHandler securityHandler;
|
||||||
if (grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY) != null
|
if (grpcHandler.getEagAttributes().get(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY) != null
|
||||||
|| grpcHandler.getEagAttributes().get(GrpcAttributes.ATTR_LB_PROVIDED_BACKEND) != null) {
|
|| grpcHandler.getEagAttributes().get(
|
||||||
|
GrpclbConstants.ATTR_LB_PROVIDED_BACKEND) != null) {
|
||||||
TsiHandshaker handshaker = handshakerFactory.newHandshaker(grpcHandler.getAuthority());
|
TsiHandshaker handshaker = handshakerFactory.newHandshaker(grpcHandler.getAuthority());
|
||||||
NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker);
|
NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker);
|
||||||
securityHandler =
|
securityHandler =
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ import com.google.common.collect.ImmutableList;
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.ManagedChannel;
|
||||||
|
import io.grpc.grpclb.GrpclbConstants;
|
||||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||||
import io.grpc.internal.GrpcAttributes;
|
|
||||||
import io.grpc.internal.ObjectPool;
|
import io.grpc.internal.ObjectPool;
|
||||||
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
import io.grpc.netty.GrpcHttp2ConnectionHandler;
|
||||||
import io.grpc.netty.GrpcSslContexts;
|
import io.grpc.netty.GrpcSslContexts;
|
||||||
|
|
@ -80,7 +80,7 @@ public final class GoogleDefaultProtocolNegotiatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void altsHandler() {
|
public void altsHandler() {
|
||||||
Attributes eagAttributes =
|
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);
|
GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
|
||||||
when(mockHandler.getEagAttributes()).thenReturn(eagAttributes);
|
when(mockHandler.getEagAttributes()).thenReturn(eagAttributes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,25 +25,6 @@ import io.grpc.SecurityLevel;
|
||||||
* Special attributes that are only useful to gRPC.
|
* Special attributes that are only useful to gRPC.
|
||||||
*/
|
*/
|
||||||
public final class GrpcAttributes {
|
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
|
* The security level of the transport. If it's not present, {@link SecurityLevel#NONE} should be
|
||||||
* assumed.
|
* assumed.
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,21 @@ public final class GrpclbConstants {
|
||||||
static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
|
static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
|
||||||
Attributes.Key.create("io.grpc.grpclb.lbAddrs");
|
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
|
@EquivalentAddressGroup.Attr
|
||||||
static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
|
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
|
||||||
io.grpc.internal.GrpcAttributes.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() { }
|
private GrpclbConstants() { }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ import io.grpc.Status;
|
||||||
import io.grpc.SynchronizationContext;
|
import io.grpc.SynchronizationContext;
|
||||||
import io.grpc.SynchronizationContext.ScheduledHandle;
|
import io.grpc.SynchronizationContext.ScheduledHandle;
|
||||||
import io.grpc.internal.BackoffPolicy;
|
import io.grpc.internal.BackoffPolicy;
|
||||||
import io.grpc.internal.GrpcAttributes;
|
|
||||||
import io.grpc.internal.TimeProvider;
|
import io.grpc.internal.TimeProvider;
|
||||||
import io.grpc.lb.v1.ClientStats;
|
import io.grpc.lb.v1.ClientStats;
|
||||||
import io.grpc.lb.v1.InitialLoadBalanceRequest;
|
import io.grpc.lb.v1.InitialLoadBalanceRequest;
|
||||||
|
|
@ -86,7 +85,7 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||||
final class GrpclbState {
|
final class GrpclbState {
|
||||||
static final long FALLBACK_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
|
static final long FALLBACK_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
|
||||||
private static final Attributes LB_PROVIDED_BACKEND_ATTRS =
|
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
|
@VisibleForTesting
|
||||||
static final PickResult DROP_PICK_RESULT =
|
static final PickResult DROP_PICK_RESULT =
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ import io.grpc.inprocess.InProcessChannelBuilder;
|
||||||
import io.grpc.inprocess.InProcessServerBuilder;
|
import io.grpc.inprocess.InProcessServerBuilder;
|
||||||
import io.grpc.internal.BackoffPolicy;
|
import io.grpc.internal.BackoffPolicy;
|
||||||
import io.grpc.internal.FakeClock;
|
import io.grpc.internal.FakeClock;
|
||||||
import io.grpc.internal.GrpcAttributes;
|
|
||||||
import io.grpc.internal.JsonParser;
|
import io.grpc.internal.JsonParser;
|
||||||
import io.grpc.lb.v1.ClientStats;
|
import io.grpc.lb.v1.ClientStats;
|
||||||
import io.grpc.lb.v1.ClientStatsPerToken;
|
import io.grpc.lb.v1.ClientStatsPerToken;
|
||||||
|
|
@ -142,7 +141,7 @@ public class GrpclbLoadBalancerTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final Attributes LB_BACKEND_ATTRS =
|
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
|
@Mock
|
||||||
private Helper helper;
|
private Helper helper;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue