diff --git a/xds/src/main/java/io/grpc/xds/FallbackLb.java b/xds/src/main/java/io/grpc/xds/FallbackLb.java index 380a22dba19..9e37515c6e0 100644 --- a/xds/src/main/java/io/grpc/xds/FallbackLb.java +++ b/xds/src/main/java/io/grpc/xds/FallbackLb.java @@ -18,17 +18,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import static io.grpc.ConnectivityState.TRANSIENT_FAILURE; -import static io.grpc.xds.XdsLoadBalancerProvider.XDS_POLICY_NAME; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; import io.grpc.Attributes; import io.grpc.EquivalentAddressGroup; import io.grpc.LoadBalancer; import io.grpc.LoadBalancerRegistry; import io.grpc.NameResolver.ConfigOrError; import io.grpc.Status; -import io.grpc.internal.GrpcAttributes; import io.grpc.internal.ServiceConfigUtil.LbConfig; import io.grpc.util.ForwardingLoadBalancer; import io.grpc.util.GracefulSwitchLoadBalancer; @@ -112,20 +109,6 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) { fallbackPolicyLb.switchTo(lbRegistry.getProvider(newFallbackPolicyName)); List 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 backends = ImmutableList.builder(); - for (EquivalentAddressGroup eag : resolvedAddresses.getAddresses()) { - if (eag.getAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY) == null) { - backends.add(eag); - } - } - servers = backends.build(); - } - // TODO(zhangkun83): FIXME(#5496): this is a temporary hack. if (servers.isEmpty() && !fallbackPolicyLb.canHandleEmptyAddressListFromNameResolution()) { diff --git a/xds/src/test/java/io/grpc/xds/FallbackLbTest.java b/xds/src/test/java/io/grpc/xds/FallbackLbTest.java index 4a63a2b5558..0d715e35982 100644 --- a/xds/src/test/java/io/grpc/xds/FallbackLbTest.java +++ b/xds/src/test/java/io/grpc/xds/FallbackLbTest.java @@ -33,21 +33,16 @@ import io.grpc.LoadBalancer.SubchannelPicker; import io.grpc.LoadBalancerProvider; import io.grpc.LoadBalancerRegistry; -import io.grpc.Status; -import io.grpc.Status.Code; -import io.grpc.internal.GrpcAttributes; import io.grpc.internal.JsonParser; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.ArgumentCaptor; /** * Tests for {@link FallbackLb}. @@ -245,20 +240,13 @@ public void handlePolicyChanges() throws Exception { verify(balancer2).shutdown(); } - @Test - public void handleBackendsEagsOnly() throws Exception { - EquivalentAddressGroup eag0 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8080))); - Attributes attributes = Attributes - .newBuilder() - .set(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY, "this is a balancer address") - .build(); + public void propagateAddressesToFallbackPolicy() throws Exception { EquivalentAddressGroup eag1 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8081)), attributes); + ImmutableList.of(new InetSocketAddress(8080))); EquivalentAddressGroup eag2 = new EquivalentAddressGroup( ImmutableList.of(new InetSocketAddress(8082))); - List eags = ImmutableList.of(eag0, eag1, eag2); + List eags = ImmutableList.of(eag1, eag2); String lbConfigRaw = "{" + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" @@ -273,99 +261,11 @@ public void handleBackendsEagsOnly() throws Exception { LoadBalancer balancer1 = balancers1.get(0); verify(balancer1).handleResolvedAddresses( ResolvedAddresses.newBuilder() - .setAddresses(ImmutableList.of(eag0, eag2)) + .setAddresses(ImmutableList.of(eag1, eag2)) .setAttributes( Attributes.newBuilder() .set(ATTR_LOAD_BALANCING_CONFIG, ImmutableMap.of("fallback_1_option", "yes")) .build()) .build()); } - - @Test - public void resolvingWithOnlyGrpclbAddresses_NoBackendAddress() throws Exception { - Attributes attributes = Attributes - .newBuilder() - .set(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY, "this is a balancer address") - .build(); - EquivalentAddressGroup eag1 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8081)), attributes); - EquivalentAddressGroup eag2 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8082)), attributes); - List eags = ImmutableList.of(eag1, eag2); - String lbConfigRaw = "{" - + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" - + "}"; - @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); - fallbackLb.handleResolvedAddresses(ResolvedAddresses.newBuilder() - .setAddresses(eags) - .setAttributes(Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build()) - .build()); - - LoadBalancer balancer1 = balancers1.get(0); - ArgumentCaptor statusCaptor = ArgumentCaptor.forClass(Status.class); - verify(balancer1).handleNameResolutionError(statusCaptor.capture()); - assertThat(statusCaptor.getValue().getCode()).isEqualTo(Code.UNAVAILABLE); - } - - @Test - public void handleGrpclbAddresses() throws Exception { - final AtomicReference balancer = new AtomicReference<>(); - LoadBalancerProvider grpclbProvider = new LoadBalancerProvider() { - @Override - public boolean isAvailable() { - return true; - } - - @Override - public int getPriority() { - return 5; - } - - @Override - public String getPolicyName() { - return "grpclb"; - } - - @Override - public LoadBalancer newLoadBalancer(Helper helper) { - balancer.set(mock(LoadBalancer.class)); - return balancer.get(); - } - }; - LoadBalancerRegistry lbRegistry = new LoadBalancerRegistry(); - lbRegistry.register(grpclbProvider); - fallbackLb = new FallbackLb(helper, lbRegistry); - - EquivalentAddressGroup eag0 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8080))); - Attributes attributes = Attributes - .newBuilder() - .set(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY, "this is a balancer address") - .build(); - EquivalentAddressGroup eag1 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8081)), attributes); - EquivalentAddressGroup eag2 = new EquivalentAddressGroup( - ImmutableList.of(new InetSocketAddress(8082))); - List eags = ImmutableList.of(eag0, eag1, eag2); - - String lbConfigRaw = "{" - + "\"fallbackPolicy\" : [{\"grpclb\" : { \"grpclb_option\" : \"yes\"}}]" - + "}"; - @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); - fallbackLb.handleResolvedAddresses(ResolvedAddresses.newBuilder() - .setAddresses(eags) - .setAttributes(Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build()) - .build()); - - verify(balancer.get()).handleResolvedAddresses( - ResolvedAddresses.newBuilder() - .setAddresses(eags) - .setAttributes( - Attributes.newBuilder() - .set(ATTR_LOAD_BALANCING_CONFIG, ImmutableMap.of("grpclb_option", "yes")) - .build()) - .build()); - } }