• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19908

16 Jul 2025 07:54PM UTC coverage: 88.593% (+0.07%) from 88.528%
#19908

push

github

ejona86
Revert "xds: Convert CdsLb to XdsDepManager"

This reverts commit 297ab05ef.

b/430347751 shows multiple concerning behaviors in the xDS stack with
the new A74 config update model. XdsDepManager and CdsLB2 still seem to
be working correctly, but the change is exacerbated issues in other
parts of the stack, like RingHashConfig not having equals fixed in
a8de9f07ab.

Revert only for the v1.74.x release, leaving it on master.

34647 of 39108 relevant lines covered (88.59%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/../xds/src/main/java/io/grpc/xds/CdsLoadBalancerProvider.java
1
/*
2
 * Copyright 2019 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.xds;
18

19
import static com.google.common.base.Preconditions.checkArgument;
20

21
import com.google.common.base.MoreObjects;
22
import io.grpc.Internal;
23
import io.grpc.LoadBalancer;
24
import io.grpc.LoadBalancer.Helper;
25
import io.grpc.LoadBalancerProvider;
26
import io.grpc.NameResolver.ConfigOrError;
27
import io.grpc.Status;
28
import io.grpc.internal.JsonUtil;
29
import java.util.Map;
30

31
/**
32
 * The provider for the "cds" balancing policy.  This class should not be directly referenced in
33
 * code.  The policy should be accessed through {@link io.grpc.LoadBalancerRegistry#getProvider}
34
 * with the name "cds" (currently "cds_experimental").
35
 */
36
@Internal
37
public class CdsLoadBalancerProvider extends LoadBalancerProvider {
1✔
38

39
  private static final String CLUSTER_KEY = "cluster";
40

41
  @Override
42
  public boolean isAvailable() {
43
    return true;
1✔
44
  }
45

46
  @Override
47
  public int getPriority() {
48
    return 5;
1✔
49
  }
50

51
  @Override
52
  public String getPolicyName() {
53
    return XdsLbPolicies.CDS_POLICY_NAME;
1✔
54
  }
55

56
  @Override
57
  public LoadBalancer newLoadBalancer(Helper helper) {
58
    return new CdsLoadBalancer2(helper);
1✔
59
  }
60

61
  @Override
62
  public ConfigOrError parseLoadBalancingPolicyConfig(
63
      Map<String, ?> rawLoadBalancingPolicyConfig) {
64
    return parseLoadBalancingConfigPolicy(rawLoadBalancingPolicyConfig);
1✔
65
  }
66

67
  /**
68
   * Parses raw load balancing config and returns a {@link ConfigOrError} that contains a
69
   * {@link CdsConfig} if parsing is successful.
70
   */
71
  static ConfigOrError parseLoadBalancingConfigPolicy(Map<String, ?> rawLoadBalancingPolicyConfig) {
72
    try {
73
      String cluster =
1✔
74
          JsonUtil.getString(rawLoadBalancingPolicyConfig, CLUSTER_KEY);
1✔
75
      return ConfigOrError.fromConfig(new CdsConfig(cluster));
1✔
76
    } catch (RuntimeException e) {
×
77
      return ConfigOrError.fromError(
×
78
          Status.UNAVAILABLE.withCause(e).withDescription(
×
79
              "Failed to parse CDS LB config: " + rawLoadBalancingPolicyConfig));
80
    }
81
  }
82

83
  /**
84
   * Represents a successfully parsed and validated LoadBalancingConfig for CDS.
85
   */
86
  static final class CdsConfig {
87

88
    /**
89
     * Name of cluster to query CDS for.
90
     */
91
    final String name;
92

93
    CdsConfig(String name) {
1✔
94
      checkArgument(name != null && !name.isEmpty(), "name is null or empty");
1✔
95
      this.name = name;
1✔
96
    }
1✔
97

98
    @Override
99
    public String toString() {
100
      return MoreObjects.toStringHelper(this).add("name", name).toString();
×
101
    }
102
  }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc