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

grpc / grpc-java / #19839

02 Jun 2025 05:31AM UTC coverage: 88.584% (+0.04%) from 88.545%
#19839

Pull #12120

github

web-flow
Merge 23e5bbfbc into 80ea4e9e6
Pull Request #12120: Revert "xds: xDS-based HTTP CONNECT configuration (v1.71.x backport)"

34276 of 38693 relevant lines covered (88.58%)

0.89 hits per line

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

39.68
/../xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java
1
/*
2
 * Copyright 2020 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.checkNotNull;
20

21
import com.google.common.base.MoreObjects;
22
import com.google.common.collect.ImmutableMap;
23
import com.google.protobuf.Struct;
24
import io.grpc.Internal;
25
import io.grpc.LoadBalancer;
26
import io.grpc.LoadBalancer.Helper;
27
import io.grpc.LoadBalancerProvider;
28
import io.grpc.NameResolver.ConfigOrError;
29
import io.grpc.Status;
30
import io.grpc.xds.EnvoyServerProtoData.OutlierDetection;
31
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
32
import io.grpc.xds.client.Bootstrapper.ServerInfo;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.Objects;
36
import javax.annotation.Nullable;
37

38
/**
39
 * The provider for the cluster_resolver load balancing policy. This class should not be directly
40
 * referenced in code.  The policy should be accessed through
41
 * {@link io.grpc.LoadBalancerRegistry#getProvider} with the name "cluster_resolver_experimental".
42
 */
43
@Internal
44
public final class ClusterResolverLoadBalancerProvider extends LoadBalancerProvider {
1✔
45

46
  @Override
47
  public boolean isAvailable() {
48
    return true;
1✔
49
  }
50

51
  @Override
52
  public int getPriority() {
53
    return 5;
1✔
54
  }
55

56
  @Override
57
  public String getPolicyName() {
58
    return XdsLbPolicies.CLUSTER_RESOLVER_POLICY_NAME;
1✔
59
  }
60

61
  @Override
62
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
63
    return ConfigOrError.fromError(
×
64
        Status.INTERNAL.withDescription(getPolicyName() + " cannot be used from service config"));
×
65
  }
66

67
  @Override
68
  public LoadBalancer newLoadBalancer(Helper helper) {
69
    return new ClusterResolverLoadBalancer(helper);
1✔
70
  }
71

72
  static final class ClusterResolverConfig {
73
    // Ordered list of clusters to be resolved.
74
    final List<DiscoveryMechanism> discoveryMechanisms;
75
    // GracefulSwitch configuration
76
    final Object lbConfig;
77

78
    ClusterResolverConfig(List<DiscoveryMechanism> discoveryMechanisms, Object lbConfig) {
1✔
79
      this.discoveryMechanisms = checkNotNull(discoveryMechanisms, "discoveryMechanisms");
1✔
80
      this.lbConfig = checkNotNull(lbConfig, "lbConfig");
1✔
81
    }
1✔
82

83
    @Override
84
    public int hashCode() {
85
      return Objects.hash(discoveryMechanisms, lbConfig);
×
86
    }
87

88
    @Override
89
    public boolean equals(Object o) {
90
      if (this == o) {
×
91
        return true;
×
92
      }
93
      if (o == null || getClass() != o.getClass()) {
×
94
        return false;
×
95
      }
96
      ClusterResolverConfig that = (ClusterResolverConfig) o;
×
97
      return discoveryMechanisms.equals(that.discoveryMechanisms)
×
98
          && lbConfig.equals(that.lbConfig);
×
99
    }
100

101
    @Override
102
    public String toString() {
103
      return MoreObjects.toStringHelper(this)
×
104
          .add("discoveryMechanisms", discoveryMechanisms)
×
105
          .add("lbConfig", lbConfig)
×
106
          .toString();
×
107
    }
108

109
    // Describes the mechanism for a specific cluster.
110
    static final class DiscoveryMechanism {
111
      // Name of the cluster to resolve.
112
      final String cluster;
113
      // Type of the cluster.
114
      final Type type;
115
      // Load reporting server info. Null if not enabled.
116
      @Nullable
117
      final ServerInfo lrsServerInfo;
118
      // Cluster-level max concurrent request threshold. Null if not specified.
119
      @Nullable
120
      final Long maxConcurrentRequests;
121
      // TLS context for connections to endpoints in the cluster.
122
      @Nullable
123
      final UpstreamTlsContext tlsContext;
124
      // Resource name for resolving endpoints via EDS. Only valid for EDS clusters.
125
      @Nullable
126
      final String edsServiceName;
127
      // Hostname for resolving endpoints via DNS. Only valid for LOGICAL_DNS clusters.
128
      @Nullable
129
      final String dnsHostName;
130
      @Nullable
131
      final OutlierDetection outlierDetection;
132
      final Map<String, Struct> filterMetadata;
133

134
      enum Type {
1✔
135
        EDS,
1✔
136
        LOGICAL_DNS,
1✔
137
      }
138

139
      private DiscoveryMechanism(String cluster, Type type, @Nullable String edsServiceName,
140
          @Nullable String dnsHostName, @Nullable ServerInfo lrsServerInfo,
141
          @Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext,
142
          Map<String, Struct> filterMetadata, @Nullable OutlierDetection outlierDetection) {
1✔
143
        this.cluster = checkNotNull(cluster, "cluster");
1✔
144
        this.type = checkNotNull(type, "type");
1✔
145
        this.edsServiceName = edsServiceName;
1✔
146
        this.dnsHostName = dnsHostName;
1✔
147
        this.lrsServerInfo = lrsServerInfo;
1✔
148
        this.maxConcurrentRequests = maxConcurrentRequests;
1✔
149
        this.tlsContext = tlsContext;
1✔
150
        this.filterMetadata = ImmutableMap.copyOf(checkNotNull(filterMetadata, "filterMetadata"));
1✔
151
        this.outlierDetection = outlierDetection;
1✔
152
      }
1✔
153

154
      static DiscoveryMechanism forEds(String cluster, @Nullable String edsServiceName,
155
          @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests,
156
          @Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata,
157
          OutlierDetection outlierDetection) {
158
        return new DiscoveryMechanism(cluster, Type.EDS, edsServiceName, null, lrsServerInfo,
1✔
159
            maxConcurrentRequests, tlsContext, filterMetadata, outlierDetection);
160
      }
161

162
      static DiscoveryMechanism forLogicalDns(String cluster, String dnsHostName,
163
          @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests,
164
          @Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata) {
165
        return new DiscoveryMechanism(cluster, Type.LOGICAL_DNS, null, dnsHostName,
1✔
166
            lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, null);
167
      }
168

169
      @Override
170
      public int hashCode() {
171
        return Objects.hash(cluster, type, lrsServerInfo, maxConcurrentRequests, tlsContext,
×
172
            edsServiceName, dnsHostName, filterMetadata, outlierDetection);
173
      }
174

175
      @Override
176
      public boolean equals(Object o) {
177
        if (this == o) {
×
178
          return true;
×
179
        }
180
        if (o == null || getClass() != o.getClass()) {
×
181
          return false;
×
182
        }
183
        DiscoveryMechanism that = (DiscoveryMechanism) o;
×
184
        return cluster.equals(that.cluster)
×
185
            && type == that.type
186
            && Objects.equals(edsServiceName, that.edsServiceName)
×
187
            && Objects.equals(dnsHostName, that.dnsHostName)
×
188
            && Objects.equals(lrsServerInfo, that.lrsServerInfo)
×
189
            && Objects.equals(maxConcurrentRequests, that.maxConcurrentRequests)
×
190
            && Objects.equals(tlsContext, that.tlsContext)
×
191
            && Objects.equals(filterMetadata, that.filterMetadata)
×
192
            && Objects.equals(outlierDetection, that.outlierDetection);
×
193
      }
194

195
      @Override
196
      public String toString() {
197
        MoreObjects.ToStringHelper toStringHelper =
×
198
            MoreObjects.toStringHelper(this)
×
199
                .add("cluster", cluster)
×
200
                .add("type", type)
×
201
                .add("edsServiceName", edsServiceName)
×
202
                .add("dnsHostName", dnsHostName)
×
203
                .add("lrsServerInfo", lrsServerInfo)
×
204
                // Exclude tlsContext as its string representation is cumbersome.
205
                .add("maxConcurrentRequests", maxConcurrentRequests)
×
206
                .add("filterMetadata", filterMetadata)
×
207
                // Exclude outlierDetection as its string representation is long.
208
                ;
209
        return toStringHelper.toString();
×
210
      }
211
    }
212
  }
213
}
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