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

grpc / grpc-java / #19715

06 Mar 2025 08:10AM UTC coverage: 88.479% (-0.04%) from 88.515%
#19715

push

github

web-flow
xds: xDS-based HTTP CONNECT configuration (#11861)

34489 of 38980 relevant lines covered (88.48%)

0.88 hits per line

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

41.54
/../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
    private final boolean isHttp11ProxyAvailable;
78

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

86
    boolean isHttp11ProxyAvailable() {
87
      return isHttp11ProxyAvailable;
1✔
88
    }
89

90
    @Override
91
    public int hashCode() {
92
      return Objects.hash(discoveryMechanisms, lbConfig);
×
93
    }
94

95
    @Override
96
    public boolean equals(Object o) {
97
      if (this == o) {
×
98
        return true;
×
99
      }
100
      if (o == null || getClass() != o.getClass()) {
×
101
        return false;
×
102
      }
103
      ClusterResolverConfig that = (ClusterResolverConfig) o;
×
104
      return discoveryMechanisms.equals(that.discoveryMechanisms)
×
105
          && lbConfig.equals(that.lbConfig);
×
106
    }
107

108
    @Override
109
    public String toString() {
110
      return MoreObjects.toStringHelper(this)
×
111
          .add("discoveryMechanisms", discoveryMechanisms)
×
112
          .add("lbConfig", lbConfig)
×
113
          .toString();
×
114
    }
115

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

141
      enum Type {
1✔
142
        EDS,
1✔
143
        LOGICAL_DNS,
1✔
144
      }
145

146
      private DiscoveryMechanism(String cluster, Type type, @Nullable String edsServiceName,
147
          @Nullable String dnsHostName, @Nullable ServerInfo lrsServerInfo,
148
          @Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext,
149
          Map<String, Struct> filterMetadata, @Nullable OutlierDetection outlierDetection) {
1✔
150
        this.cluster = checkNotNull(cluster, "cluster");
1✔
151
        this.type = checkNotNull(type, "type");
1✔
152
        this.edsServiceName = edsServiceName;
1✔
153
        this.dnsHostName = dnsHostName;
1✔
154
        this.lrsServerInfo = lrsServerInfo;
1✔
155
        this.maxConcurrentRequests = maxConcurrentRequests;
1✔
156
        this.tlsContext = tlsContext;
1✔
157
        this.filterMetadata = ImmutableMap.copyOf(checkNotNull(filterMetadata, "filterMetadata"));
1✔
158
        this.outlierDetection = outlierDetection;
1✔
159
      }
1✔
160

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

169
      static DiscoveryMechanism forLogicalDns(String cluster, String dnsHostName,
170
          @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests,
171
          @Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata) {
172
        return new DiscoveryMechanism(cluster, Type.LOGICAL_DNS, null, dnsHostName,
1✔
173
            lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, null);
174
      }
175

176
      @Override
177
      public int hashCode() {
178
        return Objects.hash(cluster, type, lrsServerInfo, maxConcurrentRequests, tlsContext,
×
179
            edsServiceName, dnsHostName, filterMetadata, outlierDetection);
180
      }
181

182
      @Override
183
      public boolean equals(Object o) {
184
        if (this == o) {
×
185
          return true;
×
186
        }
187
        if (o == null || getClass() != o.getClass()) {
×
188
          return false;
×
189
        }
190
        DiscoveryMechanism that = (DiscoveryMechanism) o;
×
191
        return cluster.equals(that.cluster)
×
192
            && type == that.type
193
            && Objects.equals(edsServiceName, that.edsServiceName)
×
194
            && Objects.equals(dnsHostName, that.dnsHostName)
×
195
            && Objects.equals(lrsServerInfo, that.lrsServerInfo)
×
196
            && Objects.equals(maxConcurrentRequests, that.maxConcurrentRequests)
×
197
            && Objects.equals(tlsContext, that.tlsContext)
×
198
            && Objects.equals(filterMetadata, that.filterMetadata)
×
199
            && Objects.equals(outlierDetection, that.outlierDetection);
×
200
      }
201

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