1616
1717package io .grpc .internal ;
1818
19- import com .google .common .annotations .VisibleForTesting ;
20- import com .google .common .base .Strings ;
2119import io .grpc .LoadBalancer ;
2220import io .grpc .LoadBalancerProvider ;
2321import io .grpc .NameResolver ;
3331 * down the address list and sticks to the first that works.
3432 */
3533public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
36- private static final String NO_CONFIG = "no service config" ;
3734 private static final String SHUFFLE_ADDRESS_LIST_KEY = "shuffleAddressList" ;
38- private static final String CONFIG_FLAG_NAME = "GRPC_EXPERIMENTAL_PICKFIRST_LB_CONFIG" ;
39- @ VisibleForTesting
40- static boolean enablePickFirstConfig = !Strings .isNullOrEmpty (System .getenv (CONFIG_FLAG_NAME ));
4135
4236 @ Override
4337 public boolean isAvailable () {
@@ -62,18 +56,14 @@ public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
6256 @ Override
6357 public ConfigOrError parseLoadBalancingPolicyConfig (
6458 Map <String , ?> rawLoadBalancingPolicyConfig ) {
65- if (enablePickFirstConfig ) {
66- try {
67- return ConfigOrError .fromConfig (
68- new PickFirstLoadBalancerConfig (JsonUtil .getBoolean (rawLoadBalancingPolicyConfig ,
69- SHUFFLE_ADDRESS_LIST_KEY )));
70- } catch (RuntimeException e ) {
71- return ConfigOrError .fromError (
72- Status .UNAVAILABLE .withCause (e ).withDescription (
73- "Failed parsing configuration for " + getPolicyName ()));
74- }
75- } else {
76- return ConfigOrError .fromConfig (NO_CONFIG );
59+ try {
60+ return ConfigOrError .fromConfig (
61+ new PickFirstLoadBalancerConfig (JsonUtil .getBoolean (rawLoadBalancingPolicyConfig ,
62+ SHUFFLE_ADDRESS_LIST_KEY )));
63+ } catch (RuntimeException e ) {
64+ return ConfigOrError .fromError (
65+ Status .UNAVAILABLE .withCause (e ).withDescription (
66+ "Failed parsing configuration for " + getPolicyName ()));
7767 }
7868 }
7969}
0 commit comments