From d5eb61c968490c02594b89cce99a6c2dcfdb061d Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 10 Dec 2019 13:59:10 -0800 Subject: [PATCH] xds: drop support for balancer_name in XdsConfig The balancer_name field in XdsConfig is deprecated and from now on we ignore it and don't support it. --- .../io/grpc/internal/ServiceConfigUtil.java | 11 --- .../grpc/internal/ServiceConfigUtilTest.java | 30 +------- .../java/io/grpc/xds/CdsLoadBalancer.java | 1 - .../main/java/io/grpc/xds/LookasideLb.java | 68 +++++-------------- .../io/grpc/xds/XdsLoadBalancerProvider.java | 21 ++---- .../java/io/grpc/xds/CdsLoadBalancerTest.java | 3 - .../test/java/io/grpc/xds/FallbackLbTest.java | 7 -- .../java/io/grpc/xds/LookasideLbTest.java | 30 ++------ .../grpc/xds/XdsLoadBalancerProviderTest.java | 5 -- 9 files changed, 33 insertions(+), 143 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java b/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java index 96a7b039c5..abc0d9e461 100644 --- a/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java +++ b/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java @@ -48,8 +48,6 @@ public final class ServiceConfigUtil { private static final String SERVICE_CONFIG_METHOD_CONFIG_KEY = "methodConfig"; private static final String SERVICE_CONFIG_LOAD_BALANCING_POLICY_KEY = "loadBalancingPolicy"; private static final String SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY = "loadBalancingConfig"; - // TODO(chengyuanzhang): delete this key after shifting to use bootstrap. - private static final String XDS_CONFIG_BALANCER_NAME_KEY = "balancerName"; private static final String XDS_CONFIG_CHILD_POLICY_KEY = "childPolicy"; private static final String XDS_CONFIG_FALLBACK_POLICY_KEY = "fallbackPolicy"; private static final String XDS_CONFIG_EDS_SERVICE_NAME = "edsServiceName"; @@ -363,7 +361,6 @@ public final class ServiceConfigUtil { "loadBalancingConfig": [ {"xds" : { - "balancerName": "balancer1", "childPolicy": [...], "fallbackPolicy": [...], } @@ -420,14 +417,6 @@ public final class ServiceConfigUtil { return Collections.unmodifiableList(result); } - /** - * Extracts the loadbalancer name from xds loadbalancer config. - */ - // TODO(chengyuanzhang): delete after shifting to use bootstrap. - public static String getBalancerNameFromXdsConfig(Map rawXdsConfig) { - return JsonUtil.getString(rawXdsConfig, XDS_CONFIG_BALANCER_NAME_KEY); - } - /** * Extract the server name to use in EDS query. */ diff --git a/core/src/test/java/io/grpc/internal/ServiceConfigUtilTest.java b/core/src/test/java/io/grpc/internal/ServiceConfigUtilTest.java index e7c0d40245..ff85640117 100644 --- a/core/src/test/java/io/grpc/internal/ServiceConfigUtilTest.java +++ b/core/src/test/java/io/grpc/internal/ServiceConfigUtilTest.java @@ -17,7 +17,6 @@ package io.grpc.internal; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import io.grpc.internal.ServiceConfigUtil.LbConfig; @@ -32,22 +31,9 @@ import org.junit.runners.JUnit4; */ @RunWith(JUnit4.class) public class ServiceConfigUtilTest { - @Test - public void getBalancerNameFromXdsConfig() throws Exception { - String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," - + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," - + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" - + "}"; - assertEquals( - "dns:///balancer.example.com:8080", - ServiceConfigUtil.getBalancerNameFromXdsConfig(checkObject(JsonParser.parse(rawLbConfig)))); - } - @Test public void getChildPolicyFromXdsConfig() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; @@ -65,7 +51,6 @@ public class ServiceConfigUtilTest { @Test public void getChildPolicyFromXdsConfig_null() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; @@ -78,7 +63,6 @@ public class ServiceConfigUtilTest { @Test public void getFallbackPolicyFromXdsConfig() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; @@ -96,7 +80,6 @@ public class ServiceConfigUtilTest { @Test public void getFallbackPolicyFromXdsConfig_null() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "}"; @@ -109,7 +92,6 @@ public class ServiceConfigUtilTest { @Test public void getEdsServiceNameFromXdsConfig() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]," + "\"edsServiceName\" : \"dns:///eds.service.com:8080\"" @@ -123,7 +105,6 @@ public class ServiceConfigUtilTest { @Test public void getEdsServiceNameFromXdsConfig_null() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; @@ -136,7 +117,6 @@ public class ServiceConfigUtilTest { @Test public void getLrsServerNameFromXdsConfig() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]," + "\"lrsLoadReportingServerName\" : \"dns:///lrs.service.com:8080\"" @@ -150,7 +130,6 @@ public class ServiceConfigUtilTest { @Test public void getLrsServerNameFromXdsConfig_null() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; @@ -163,7 +142,6 @@ public class ServiceConfigUtilTest { @Test public void unwrapLoadBalancingConfig() throws Exception { String lbConfig = "{\"xds_experimental\" : { " - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "}}"; @@ -171,8 +149,7 @@ public class ServiceConfigUtilTest { ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig))); assertThat(config.getPolicyName()).isEqualTo("xds_experimental"); assertThat(config.getRawConfigValue()).isEqualTo(JsonParser.parse( - "{\"balancerName\" : \"dns:///balancer.example.com:8080\"," - + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "{\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "}")); } @@ -180,7 +157,6 @@ public class ServiceConfigUtilTest { public void unwrapLoadBalancingConfig_failOnTooManyFields() throws Exception { // A LoadBalancingConfig should not have more than one field. String lbConfig = "{\"xds_experimental\" : { " - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "}," + "\"grpclb\" : {} }"; @@ -219,7 +195,7 @@ public class ServiceConfigUtilTest { @Test public void unwrapLoadBalancingConfigList() throws Exception { String lbConfig = "[ " - + "{\"xds_experimental\" : {\"balancerName\" : \"dns:///balancer.example.com:8080\"} }," + + "{\"xds_experimental\" : {\"unknown_field\" : \"dns:///balancer.example.com:8080\"} }," + "{\"grpclb\" : {} } ]"; List configs = ServiceConfigUtil.unwrapLoadBalancingConfigList( @@ -227,7 +203,7 @@ public class ServiceConfigUtilTest { assertThat(configs).containsExactly( ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse( "{\"xds_experimental\" : " - + "{\"balancerName\" : \"dns:///balancer.example.com:8080\"} }"))), + + "{\"unknown_field\" : \"dns:///balancer.example.com:8080\"} }"))), ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse( "{\"grpclb\" : {} }")))).inOrder(); } diff --git a/xds/src/main/java/io/grpc/xds/CdsLoadBalancer.java b/xds/src/main/java/io/grpc/xds/CdsLoadBalancer.java index fd04b454c4..d79f093622 100644 --- a/xds/src/main/java/io/grpc/xds/CdsLoadBalancer.java +++ b/xds/src/main/java/io/grpc/xds/CdsLoadBalancer.java @@ -253,7 +253,6 @@ public final class CdsLoadBalancer extends LoadBalancer { "The load balancing policy in ClusterUpdate '%s' is not supported", newUpdate); final XdsConfig edsConfig = new XdsConfig( - /* balancerName = */ null, new LbConfig(newUpdate.getLbPolicy(), ImmutableMap.of()), /* fallbackPolicy = */ null, /* edsServiceName = */ newUpdate.getEdsServiceName(), diff --git a/xds/src/main/java/io/grpc/xds/LookasideLb.java b/xds/src/main/java/io/grpc/xds/LookasideLb.java index 647dd412fd..239c1c821b 100644 --- a/xds/src/main/java/io/grpc/xds/LookasideLb.java +++ b/xds/src/main/java/io/grpc/xds/LookasideLb.java @@ -53,7 +53,6 @@ import io.grpc.xds.XdsClient.RefCountedXdsClientObjectPool; import io.grpc.xds.XdsClient.XdsClientFactory; import io.grpc.xds.XdsLoadBalancerProvider.XdsConfig; import io.grpc.xds.XdsSubchannelPickers.ErrorPicker; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -73,22 +72,16 @@ final class LookasideLb extends LoadBalancer { private final Helper lookasideLbHelper; // Most recent XdsConfig. - // Becomes non-null once handleResolvedAddresses() successfully. @Nullable private XdsConfig xdsConfig; // Most recent EndpointWatcher. - // Becomes non-null once handleResolvedAddresses() successfully. @Nullable private EndpointWatcher endpointWatcher; - - // Becomes non-null and calls getObject() once handleResolvedAddresses() successfully. - // Will call returnObject() at balancer shutdown. @Nullable private ObjectPool xdsClientRef; - // Becomes non-null once handleResolvedAddresses() successfully. @Nullable XdsClient xdsClient; - // Becomes non-null for EDS-only case once handleResolvedAddresses() successfully. + // Only for EDS-only case. // TODO(zdapeng): Stop using it once XdsClientImpl is used. @Nullable ManagedChannel channel; @@ -160,41 +153,22 @@ final class LookasideLb extends LoadBalancer { } newXdsConfig = (XdsConfig) cfg.getConfig(); } - ObjectPool xdsClientRefFromResolver = attributes.get(XdsAttributes.XDS_CLIENT_REF); - ObjectPool xdsClientRef; - // Init XdsClient. - if (xdsClient == null) { - // There are three usecases: - // 1. The EDS-only legacy usecase that requires balancerName from xds config. - // Note: we don't support balancerName change. - // TODO(zdapeng): Remove the legacy case. - // 2. The EDS-only with bootstrap usecase: - // The name resolver resolves a ResolvedAddresses with an XdsConfig without balancerName - // field. Use the bootstrap information to create a channel. - // 3. Non EDS-only usecase: + if (xdsClientRef == null) { + // Init xdsClientRef and xdsClient. + // There are two usecases: + // 1. The EDS-only: + // The name resolver resolves a ResolvedAddresses with an XdsConfig. Use the bootstrap + // information to create a channel. + // 2. Non EDS-only usecase: // XDS_CLIENT_REF attribute is available from ResolvedAddresses either from // XdsNameResolver or CDS policy. // // We assume XdsConfig switching happens only within one usecase, and there is no switching // between different usecases. - if (newXdsConfig.balancerName != null) { - // This is the EDS-only legacy usecase that requires balancerName from xds config. - channel = initLbChannel( - lookasideLbHelper, newXdsConfig.balancerName, Collections.emptyList()); - xdsClientRef = new RefCountedXdsClientObjectPool(new XdsClientFactory() { - @Override - XdsClient createXdsClient() { - return new XdsComms2( - channel, lookasideLbHelper, new ExponentialBackoffPolicy.Provider(), - GrpcUtil.STOPWATCH_SUPPLIER, Node.getDefaultInstance()); - } - }); - } else if (xdsClientRefFromResolver != null) { - // This is the Non EDS-only usecase. - xdsClientRef = xdsClientRefFromResolver; - } else { - // This is the EDS-only with bootstrap usecase. + + xdsClientRef = attributes.get(XdsAttributes.XDS_CLIENT_REF); + if (xdsClientRef == null) { // This is the EDS-only usecase. final BootstrapInfo bootstrapInfo; try { bootstrapInfo = bootstrapper.readBootstrap(); @@ -229,16 +203,10 @@ final class LookasideLb extends LoadBalancer { } }); } - - // At this point the xdsClientRef is assigned in all usecases, cache them for later use. - this.xdsClientRef = xdsClientRef; xdsClient = xdsClientRef.getObject(); } - // Note: balancerName change is unsupported and ignored. - // TODO(zdapeng): Remove support for balancerName. // Note: childPolicy change will be handled in LocalityStore, to be implemented. - // If edsServiceName in XdsConfig is changed, do a graceful switch. if (xdsConfig == null || !Objects.equals(newXdsConfig.edsServiceName, xdsConfig.edsServiceName)) { @@ -295,11 +263,11 @@ final class LookasideLb extends LoadBalancer { private static ManagedChannel initLbChannel( Helper helper, - String balancerName, + String serverUri, List channelCredsList) { ManagedChannel channel = null; try { - channel = helper.createResolvingOobChannel(balancerName); + channel = helper.createResolvingOobChannel(serverUri); } catch (UnsupportedOperationException uoe) { // Temporary solution until createResolvingOobChannel is implemented. // FIXME (https://github.com/grpc/grpc-java/issues/5495) @@ -309,19 +277,19 @@ final class LookasideLb extends LoadBalancer { FINEST, "createResolvingOobChannel() not supported by the helper: " + helper, uoe); - logger.log(FINEST, "creating oob channel for target {0}", balancerName); + logger.log(FINEST, "creating oob channel for target {0}", serverUri); } // Use the first supported channel credentials configuration. // Currently, only "google_default" is supported. for (ChannelCreds creds : channelCredsList) { if (creds.getType().equals("google_default")) { - channel = GoogleDefaultChannelBuilder.forTarget(balancerName).build(); + channel = GoogleDefaultChannelBuilder.forTarget(serverUri).build(); break; } } if (channel == null) { - channel = ManagedChannelBuilder.forTarget(balancerName).build(); + channel = ManagedChannelBuilder.forTarget(serverUri).build(); } } return channel; @@ -401,8 +369,6 @@ final class LookasideLb extends LoadBalancer { @Override public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) { - XdsConfig xdsConfig = (XdsConfig) resolvedAddresses.getLoadBalancingPolicyConfig(); - if (endpointWatcher != null) { // TODO(zddapeng): Handle child policy changed if any. return; @@ -420,7 +386,7 @@ final class LookasideLb extends LoadBalancer { // TODO(zdapeng): Use XdsClient to do Lrs directly. // For now create an LRS Client. - if (xdsConfig.balancerName != null) { + if (channel != null) { lrsClient = loadReportClientFactory.createLoadReportClient( channel, diff --git a/xds/src/main/java/io/grpc/xds/XdsLoadBalancerProvider.java b/xds/src/main/java/io/grpc/xds/XdsLoadBalancerProvider.java index 007cd06fa5..2663883e66 100644 --- a/xds/src/main/java/io/grpc/xds/XdsLoadBalancerProvider.java +++ b/xds/src/main/java/io/grpc/xds/XdsLoadBalancerProvider.java @@ -76,8 +76,6 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { static ConfigOrError parseLoadBalancingConfigPolicy( Map rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) { try { - String newBalancerName = - ServiceConfigUtil.getBalancerNameFromXdsConfig(rawLoadBalancingPolicyConfig); LbConfig childPolicy = selectChildPolicy(rawLoadBalancingPolicyConfig, registry); LbConfig fallbackPolicy = selectFallbackPolicy(rawLoadBalancingPolicyConfig, registry); String edsServiceName = @@ -85,8 +83,7 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { String lrsServerName = ServiceConfigUtil.getLrsServerNameFromXdsConfig(rawLoadBalancingPolicyConfig); return ConfigOrError.fromConfig( - new XdsConfig( - newBalancerName, childPolicy, fallbackPolicy, edsServiceName, lrsServerName)); + new XdsConfig(childPolicy, fallbackPolicy, edsServiceName, lrsServerName)); } catch (RuntimeException e) { return ConfigOrError.fromError( Status.UNKNOWN.withDescription("Failed to parse config " + e.getMessage()).withCause(e)); @@ -130,9 +127,6 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { * Represents a successfully parsed and validated LoadBalancingConfig for XDS. */ static final class XdsConfig { - // TODO(chengyuanzhang): delete after shifting to use bootstrap. - @Nullable - final String balancerName; // TODO(carl-mastrangelo): make these Object's containing the fully parsed child configs. @Nullable final LbConfig childPolicy; @@ -149,10 +143,10 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { final String lrsServerName; XdsConfig( - @Nullable String balancerName, @Nullable LbConfig childPolicy, - @Nullable LbConfig fallbackPolicy, @Nullable String edsServiceName, + @Nullable LbConfig childPolicy, + @Nullable LbConfig fallbackPolicy, + @Nullable String edsServiceName, @Nullable String lrsServerName) { - this.balancerName = balancerName; this.childPolicy = childPolicy; this.fallbackPolicy = fallbackPolicy; this.edsServiceName = edsServiceName; @@ -162,7 +156,6 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("balancerName", balancerName) .add("childPolicy", childPolicy) .add("fallbackPolicy", fallbackPolicy) .add("edsServiceName", edsServiceName) @@ -176,8 +169,7 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { return false; } XdsConfig that = (XdsConfig) obj; - return Objects.equal(this.balancerName, that.balancerName) - && Objects.equal(this.childPolicy, that.childPolicy) + return Objects.equal(this.childPolicy, that.childPolicy) && Objects.equal(this.fallbackPolicy, that.fallbackPolicy) && Objects.equal(this.edsServiceName, that.edsServiceName) && Objects.equal(this.lrsServerName, that.lrsServerName); @@ -185,8 +177,7 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider { @Override public int hashCode() { - return Objects.hashCode( - balancerName, childPolicy, fallbackPolicy, edsServiceName, lrsServerName); + return Objects.hashCode(childPolicy, fallbackPolicy, edsServiceName, lrsServerName); } } } diff --git a/xds/src/test/java/io/grpc/xds/CdsLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/CdsLoadBalancerTest.java index a4f5985eb4..a943f9b651 100644 --- a/xds/src/test/java/io/grpc/xds/CdsLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/CdsLoadBalancerTest.java @@ -235,7 +235,6 @@ public class CdsLoadBalancerTest { ArgumentCaptor resolvedAddressesCaptor1 = ArgumentCaptor.forClass(null); verify(edsLoadBalancer1).handleResolvedAddresses(resolvedAddressesCaptor1.capture()); XdsConfig expectedXdsConfig = new XdsConfig( - null, new LbConfig("round_robin", ImmutableMap.of()), null, "edsServiceFoo.googleapis.com", @@ -282,7 +281,6 @@ public class CdsLoadBalancerTest { ArgumentCaptor resolvedAddressesCaptor2 = ArgumentCaptor.forClass(null); verify(edsLoadBalancer2).handleResolvedAddresses(resolvedAddressesCaptor2.capture()); expectedXdsConfig = new XdsConfig( - null, new LbConfig("round_robin", ImmutableMap.of()), null, "edsServiceBar.googleapis.com", @@ -311,7 +309,6 @@ public class CdsLoadBalancerTest { .build()); verify(edsLoadBalancer2, times(2)).handleResolvedAddresses(resolvedAddressesCaptor2.capture()); expectedXdsConfig = new XdsConfig( - null, new LbConfig("round_robin", ImmutableMap.of()), null, "edsServiceBar2.googleapis.com", diff --git a/xds/src/test/java/io/grpc/xds/FallbackLbTest.java b/xds/src/test/java/io/grpc/xds/FallbackLbTest.java index aeb54478a6..a3fecb50a8 100644 --- a/xds/src/test/java/io/grpc/xds/FallbackLbTest.java +++ b/xds/src/test/java/io/grpc/xds/FallbackLbTest.java @@ -133,7 +133,6 @@ public class FallbackLbTest { EquivalentAddressGroup eag112 = new EquivalentAddressGroup(mock(SocketAddress.class)); List eags11 = ImmutableList.of(eag111, eag112); String lbConfigRaw11 = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -160,7 +159,6 @@ public class FallbackLbTest { EquivalentAddressGroup eag121 = new EquivalentAddressGroup(mock(SocketAddress.class)); List eags12 = ImmutableList.of(eag121); String lbConfigRaw12 = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"no\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -185,7 +183,6 @@ public class FallbackLbTest { EquivalentAddressGroup eag212 = new EquivalentAddressGroup(mock(SocketAddress.class)); List eags21 = ImmutableList.of(eag211, eag212); String lbConfigRaw21 = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_2\" : { \"fallback_2_option\" : \"yes\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -221,7 +218,6 @@ public class FallbackLbTest { EquivalentAddressGroup eag221 = new EquivalentAddressGroup(mock(SocketAddress.class)); List eags22 = ImmutableList.of(eag221); String lbConfigRaw22 = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_2\" : { \"fallback_2_option\" : \"no\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -263,7 +259,6 @@ public class FallbackLbTest { List eags = ImmutableList.of(eag0, eag1, eag2); String lbConfigRaw = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -296,7 +291,6 @@ public class FallbackLbTest { ImmutableList.of(new InetSocketAddress(8082)), attributes); List eags = ImmutableList.of(eag1, eag2); String lbConfigRaw = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" + "}"; @SuppressWarnings("unchecked") @@ -354,7 +348,6 @@ public class FallbackLbTest { List eags = ImmutableList.of(eag0, eag1, eag2); String lbConfigRaw = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"fallbackPolicy\" : [{\"grpclb\" : { \"grpclb_option\" : \"yes\"}}]" + "}"; @SuppressWarnings("unchecked") diff --git a/xds/src/test/java/io/grpc/xds/LookasideLbTest.java b/xds/src/test/java/io/grpc/xds/LookasideLbTest.java index 0ba3dc0de2..0f332f9b04 100644 --- a/xds/src/test/java/io/grpc/xds/LookasideLbTest.java +++ b/xds/src/test/java/io/grpc/xds/LookasideLbTest.java @@ -252,11 +252,17 @@ public class LookasideLbTest { } }); + List serverList = + ImmutableList.of( + new ServerInfo("trafficdirector.googleapis.com", ImmutableList.of())); + BootstrapInfo bootstrapInfo = new BootstrapInfo(serverList, Node.getDefaultInstance()); + doReturn(bootstrapInfo).when(bootstrapper).readBootstrap(); + lookasideLb = new LookasideLb( helper, edsUpdateCallback, lbRegistry, localityStoreFactory, loadReportClientFactory, bootstrapper); - String lbConfigRaw11 = "{\"balancerName\" : \"dns:///balancer1.example.com:8080\"}"; + String lbConfigRaw11 = "{}"; @SuppressWarnings("unchecked") Map lbConfig11 = (Map) JsonParser.parse(lbConfigRaw11); defaultResolvedAddress = ResolvedAddresses.newBuilder() @@ -469,28 +475,6 @@ public class LookasideLbTest { xdsClientRef.returnObject(xdsClientFromResolver); } - @Deprecated // balancerName will be unsupported. - @Test - public void handleResolvedAddress_createLbChannel() - throws Exception { - // Test balancer created with the default real LookasideChannelLbFactory - lookasideLb = new LookasideLb(helper, mock(EndpointUpdateCallback.class)); - String lbConfigRaw = "{'balancerName' : 'dns:///balancer1.example.com:8080'}" - .replace("'", "\""); - @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); - ResolvedAddresses resolvedAddresses = ResolvedAddresses.newBuilder() - .setAddresses(ImmutableList.of()) - .setAttributes(Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build()) - .build(); - - verify(helper, never()).createResolvingOobChannel(anyString()); - lookasideLb.handleResolvedAddresses(resolvedAddresses); - verify(helper).createResolvingOobChannel("dns:///balancer1.example.com:8080"); - - lookasideLb.shutdown(); - } - @Test public void handleResolvedAddress_withBootstrap() throws Exception { List serverList = diff --git a/xds/src/test/java/io/grpc/xds/XdsLoadBalancerProviderTest.java b/xds/src/test/java/io/grpc/xds/XdsLoadBalancerProviderTest.java index a5f38de78f..2e83b9e583 100644 --- a/xds/src/test/java/io/grpc/xds/XdsLoadBalancerProviderTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsLoadBalancerProviderTest.java @@ -107,7 +107,6 @@ public class XdsLoadBalancerProviderTest { @Test public void selectChildPolicy() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"unsupported_1\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}," + "{\"supported_2\" : {\"key\" : \"val\"}}]," + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" @@ -126,7 +125,6 @@ public class XdsLoadBalancerProviderTest { @Test public void selectFallBackPolicy() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]," + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}," + "{\"supported_2\" : {\"key\" : \"val\"}}]" @@ -143,7 +141,6 @@ public class XdsLoadBalancerProviderTest { @Test public void selectFallBackPolicy_roundRobinIsDefault() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "}"; LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig( @@ -158,7 +155,6 @@ public class XdsLoadBalancerProviderTest { @Test public void parseLoadBalancingConfigPolicy() throws Exception { String rawLbConfig = "{" - + "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"supported_1\" : {}}]," + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"round_robin\" : {\"key\" : \"val\"}}," + "{\"supported_2\" : {\"key\" : \"val\"}}]," @@ -173,7 +169,6 @@ public class XdsLoadBalancerProviderTest { assertThat(configOrError.getConfig()).isInstanceOf(XdsConfig.class); assertThat(configOrError.getConfig()).isEqualTo( new XdsConfig( - "dns:///balancer.example.com:8080", ServiceConfigUtil.unwrapLoadBalancingConfig( checkObject(JsonParser.parse("{\"supported_1\" : {}}"))), ServiceConfigUtil.unwrapLoadBalancingConfig(