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

grpc / grpc-java / #19858

11 Jun 2025 07:19PM UTC coverage: 88.606% (-0.007%) from 88.613%
#19858

push

github

web-flow
google-java-format a line that was too long (#12147)

34613 of 39064 relevant lines covered (88.61%)

0.89 hits per line

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

72.0
/../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
  @Override
40
  public boolean isAvailable() {
41
    return true;
1✔
42
  }
43

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

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

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

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

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

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

89
    /**
90
     * Name of cluster to query CDS for.
91
     */
92
    final String name;
93
    /**
94
     * Whether this cluster was dynamically chosen, so the XdsDependencyManager may be unaware of
95
     * it without an explicit cluster subscription.
96
     */
97
    final boolean isDynamic;
98

99
    CdsConfig(String name) {
100
      this(name, false);
1✔
101
    }
1✔
102

103
    CdsConfig(String name, boolean isDynamic) {
1✔
104
      checkArgument(name != null && !name.isEmpty(), "name is null or empty");
1✔
105
      this.name = name;
1✔
106
      this.isDynamic = isDynamic;
1✔
107
    }
1✔
108

109
    @Override
110
    public String toString() {
111
      return MoreObjects.toStringHelper(this)
×
112
          .add("name", name)
×
113
          .add("isDynamic", isDynamic)
×
114
          .toString();
×
115
    }
116
  }
117
}
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

© 2026 Coveralls, Inc