Skip to content

Commit

Permalink
Add annotation for attribute keys being depracated.
Browse files Browse the repository at this point in the history
  • Loading branch information
voidzcy committed Jan 30, 2020
1 parent 5adefa9 commit 08cb3d8
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 4 deletions.
Expand Up @@ -223,6 +223,7 @@ public AsciiString scheme() {
return SCHEME;
}

@SuppressWarnings("deprecation")
@Override
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler);
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/io/grpc/internal/GrpcAttributes.java
Expand Up @@ -38,14 +38,23 @@ public final class GrpcAttributes {
public static final Attributes.Key<Map<String, ?>> NAME_RESOLVER_SERVICE_CONFIG =
Attributes.Key.create("service-config");

/**
* Attribute key for gRPC LB server addresses.
*
* <p>Deprecated: this will be used for grpclb specific logic, which will be moved out of core.
*/
@Deprecated
@NameResolver.ResolutionResultAttr
public static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
Attributes.Key.create("io.grpc.grpclb.lbAddrs");

/**
* 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");
Expand Down
Expand Up @@ -129,6 +129,7 @@ public List<String> resolveTxt(String serviceConfigHostname) throws NamingExcept
return Collections.unmodifiableList(serviceConfigTxtRecords);
}

@SuppressWarnings("deprecation")
@Override
public List<EquivalentAddressGroup> resolveSrv(
AddressResolver addressResolver, String grpclbHostname) throws Exception {
Expand Down
Expand Up @@ -561,6 +561,7 @@ public List<EquivalentAddressGroup> resolveSrv(AddressResolver addressResolver,
assertThat(ac.getValue().getServiceConfig()).isNull();
}

@SuppressWarnings("deprecation")
@Test
public void resolve_balancerAddrsAsAttributes() throws Exception {
InetAddress backendAddr = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
Expand Down
Expand Up @@ -24,7 +24,6 @@
import io.grpc.Attributes;
import io.grpc.EquivalentAddressGroup;
import io.grpc.internal.DnsNameResolver.AddressResolver;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.JndiResourceResolverFactory.JndiRecordFetcher;
import io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver;
import io.grpc.internal.JndiResourceResolverFactory.RecordFetcher;
Expand Down Expand Up @@ -81,6 +80,7 @@ public void txtRecordLookup() throws Exception {
assertThat(resolver.resolveTxt("service.example.com")).isEqualTo(golden);
}

@SuppressWarnings("deprecation")
@Test
public void srvRecordLookup() throws Exception {
AddressResolver addressResolver = mock(AddressResolver.class);
Expand Down
2 changes: 2 additions & 0 deletions grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java
Expand Up @@ -42,10 +42,12 @@ public final class GrpclbConstants {
static final Attributes.Key<String> TOKEN_ATTRIBUTE_KEY =
Attributes.Key.create("lb-token");

@SuppressWarnings("deprecation")
@EquivalentAddressGroup.Attr
static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
io.grpc.internal.GrpcAttributes.ATTR_LB_ADDRS;

@SuppressWarnings("deprecation")
@EquivalentAddressGroup.Attr
static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
io.grpc.internal.GrpcAttributes.ATTR_LB_ADDR_AUTHORITY;
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {

if (newLbAddresses != null) {
for (EquivalentAddressGroup lbAddr : newLbAddresses) {
String lbAddrAuthority = lbAddr.getAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY);
String lbAddrAuthority = lbAddr.getAttributes().get(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY);
if (lbAddrAuthority == null) {
throw new AssertionError(
"This is a bug: LB address " + lbAddr + " does not have an authority.");
Expand Down
2 changes: 1 addition & 1 deletion grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
Expand Up @@ -793,7 +793,7 @@ private LbAddressGroup flattenLbAddressGroups(List<LbAddressGroup> groupList) {
// actually used in the normal case. https://github.com/grpc/grpc-java/issues/4618 should allow
// this to be more obvious.
Attributes attrs = Attributes.newBuilder()
.set(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY, authority)
.set(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY, authority)
.build();
return new LbAddressGroup(flattenEquivalentAddressGroup(eags, attrs), authority);
}
Expand Down
Expand Up @@ -2401,7 +2401,7 @@ private static String lbAuthority(int unused) {

private static Attributes lbAttributes(String authority) {
return Attributes.newBuilder()
.set(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY, authority)
.set(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY, authority)
.build();
}

Expand Down
3 changes: 3 additions & 0 deletions xds/src/main/java/io/grpc/xds/FallbackLb.java
Expand Up @@ -61,6 +61,7 @@ protected LoadBalancer delegate() {
return fallbackPolicyLb;
}

@SuppressWarnings("deprecation")
@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
Attributes attributes = resolvedAddresses.getAttributes();
Expand Down Expand Up @@ -113,6 +114,8 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
List<EquivalentAddressGroup> servers = resolvedAddresses.getAddresses();
// Some addresses in the list may be grpclb-v1 balancer addresses, so if the fallback policy
// does not support grpclb-v1 balancer addresses, then we need to exclude them from the list.
// TODO(chengyuanzhang): delete the following logic after changing internal resolver
// to not include grpclb server addresses.
if (!newFallbackPolicyName.equals("grpclb") && !newFallbackPolicyName.equals(XDS_POLICY_NAME)) {
ImmutableList.Builder<EquivalentAddressGroup> backends = ImmutableList.builder();
for (EquivalentAddressGroup eag : resolvedAddresses.getAddresses()) {
Expand Down

0 comments on commit 08cb3d8

Please sign in to comment.