Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpclb: internal accessor for balancer address related attribute keys #6667

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions grpclb/build.gradle
Expand Up @@ -26,3 +26,7 @@ dependencies {
}

configureProtoCompilation()

javadoc {
exclude 'io/grpc/grpclb/Internal*'
}
1 change: 0 additions & 1 deletion grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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(
Expand Down
@@ -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();
}
}