mirror of https://github.com/grpc/grpc-java.git
grpclb: internal accessor for balancer address related attribute keys (#6667)
Creates an internal accessor for attribute keys in grpclb package that is used by name resolver implementations to set balancer addresses as name resolution result attributes.
This commit is contained in:
parent
be27d0ba8b
commit
26bff62ff3
|
|
@ -26,3 +26,7 @@ dependencies {
|
|||
}
|
||||
|
||||
configureProtoCompilation()
|
||||
|
||||
javadoc {
|
||||
exclude 'io/grpc/grpclb/Internal*'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public final class GrpclbConstants {
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import io.grpc.LoadBalancer;
|
|||
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 @@ class GrpclbLoadBalancer extends LoadBalancer {
|
|||
@SuppressWarnings("deprecation") // TODO(creamsoup) migrate to use parsed service config
|
||||
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
|
||||
Attributes attributes = resolvedAddresses.getAttributes();
|
||||
List<EquivalentAddressGroup> newLbAddresses = attributes.get(GrpcAttributes.ATTR_LB_ADDRS);
|
||||
List<EquivalentAddressGroup> newLbAddresses = attributes.get(GrpclbConstants.ATTR_LB_ADDRS);
|
||||
if ((newLbAddresses == null || newLbAddresses.isEmpty())
|
||||
&& resolvedAddresses.getAddresses().isEmpty()) {
|
||||
handleNameResolutionError(
|
||||
|
|
|
|||
|
|
@ -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<EquivalentAddressGroup> lbAddrs) {
|
||||
return attrs.toBuilder().set(GrpclbConstants.ATTR_LB_ADDRS, lbAddrs).build();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue