From db6f4aa3c2f35b8f1ece4fcab275e398076c75c5 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 31 Jan 2020 12:25:55 -0800 Subject: [PATCH 1/3] Use ATTR_LB_ADDRS from GrpclbConstants instead of GrpcAttributes. --- grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java index 922a8b61970..00af68f844b 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java +++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java @@ -30,7 +30,6 @@ import io.grpc.Status; import io.grpc.grpclb.GrpclbState.Mode; import io.grpc.internal.BackoffPolicy; -import io.grpc.internal.GrpcAttributes; import io.grpc.internal.ServiceConfigUtil; import io.grpc.internal.ServiceConfigUtil.LbConfig; import io.grpc.internal.TimeProvider; @@ -92,7 +91,7 @@ public void handleSubchannelState(Subchannel subchannel, ConnectivityStateInfo n @SuppressWarnings("deprecation") // TODO(creamsoup) migrate to use parsed service config public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) { Attributes attributes = resolvedAddresses.getAttributes(); - List newLbAddresses = attributes.get(GrpcAttributes.ATTR_LB_ADDRS); + List newLbAddresses = attributes.get(GrpclbConstants.ATTR_LB_ADDRS); if ((newLbAddresses == null || newLbAddresses.isEmpty()) && resolvedAddresses.getAddresses().isEmpty()) { handleNameResolutionError( From 45f96894e3fd1a92bafa37707e4d1a4aa19660e7 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 31 Jan 2020 13:58:06 -0800 Subject: [PATCH 2/3] Make balancer address related attribute key public for internal uses. --- grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java index db5e84f08c6..27a234517b1 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java +++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java @@ -44,12 +44,12 @@ public final class GrpclbConstants { @SuppressWarnings("deprecation") @EquivalentAddressGroup.Attr - static final Attributes.Key> ATTR_LB_ADDRS = + public static final Attributes.Key> ATTR_LB_ADDRS = io.grpc.internal.GrpcAttributes.ATTR_LB_ADDRS; @SuppressWarnings("deprecation") @EquivalentAddressGroup.Attr - static final Attributes.Key ATTR_LB_ADDR_AUTHORITY = + public static final Attributes.Key ATTR_LB_ADDR_AUTHORITY = io.grpc.internal.GrpcAttributes.ATTR_LB_ADDR_AUTHORITY; private GrpclbConstants() { } From 7db4d1cb5c0c824576511417d1d5d62209e05c16 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 31 Jan 2020 14:46:59 -0800 Subject: [PATCH 3/3] Add internal accessor for grpclb balancer address related attribute keys. --- grpclb/build.gradle | 4 ++ .../java/io/grpc/grpclb/GrpclbConstants.java | 5 +- .../InternalGrpclbConstantsAccessor.java | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 grpclb/src/main/java/io/grpc/grpclb/InternalGrpclbConstantsAccessor.java diff --git a/grpclb/build.gradle b/grpclb/build.gradle index ed48c1a5eba..82ddb89c397 100644 --- a/grpclb/build.gradle +++ b/grpclb/build.gradle @@ -26,3 +26,7 @@ dependencies { } configureProtoCompilation() + +javadoc { + exclude 'io/grpc/grpclb/Internal*' +} diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java index 27a234517b1..75267757273 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java +++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java @@ -43,13 +43,12 @@ public final class GrpclbConstants { Attributes.Key.create("lb-token"); @SuppressWarnings("deprecation") - @EquivalentAddressGroup.Attr - public static final Attributes.Key> ATTR_LB_ADDRS = + static final Attributes.Key> ATTR_LB_ADDRS = io.grpc.internal.GrpcAttributes.ATTR_LB_ADDRS; @SuppressWarnings("deprecation") @EquivalentAddressGroup.Attr - public static final Attributes.Key ATTR_LB_ADDR_AUTHORITY = + static final Attributes.Key ATTR_LB_ADDR_AUTHORITY = io.grpc.internal.GrpcAttributes.ATTR_LB_ADDR_AUTHORITY; private GrpclbConstants() { } diff --git a/grpclb/src/main/java/io/grpc/grpclb/InternalGrpclbConstantsAccessor.java b/grpclb/src/main/java/io/grpc/grpclb/InternalGrpclbConstantsAccessor.java new file mode 100644 index 00000000000..298add4b738 --- /dev/null +++ b/grpclb/src/main/java/io/grpc/grpclb/InternalGrpclbConstantsAccessor.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020 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.grpclb; + +import io.grpc.Attributes; +import io.grpc.EquivalentAddressGroup; +import io.grpc.Internal; +import java.util.List; + +/** + * Internal {@link GrpclbConstants} accessor. This is intended for usage internal to the gRPC + * team. If you *really* think you need to use this, contact the gRPC team first. + */ +@Internal +public class InternalGrpclbConstantsAccessor { + + // Prevent instantiation. + private InternalGrpclbConstantsAccessor() { + } + + /** + * Sets attribute for gRPC LB address authority. + */ + public static Attributes setLbAddrAuthorityAttr( + @EquivalentAddressGroup.Attr Attributes attrs, String authority) { + return attrs.toBuilder().set(GrpclbConstants.ATTR_LB_ADDR_AUTHORITY, authority).build(); + } + + /** + * Sets attribute for gRPC LB addresses. + */ + public static Attributes setLbAddrAttr(Attributes attrs, List lbAddrs) { + return attrs.toBuilder().set(GrpclbConstants.ATTR_LB_ADDRS, lbAddrs).build(); + } +}