|
16 | 16 |
|
17 | 17 | package io.grpc.xds;
|
18 | 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 | 19 | import io.grpc.Internal;
|
25 | 20 | import io.grpc.LoadBalancer;
|
26 | 21 | import io.grpc.LoadBalancer.Helper;
|
27 | 22 | import io.grpc.LoadBalancerProvider;
|
28 | 23 | import io.grpc.NameResolver.ConfigOrError;
|
29 | 24 | 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 | 25 | import java.util.Map;
|
35 |
| -import java.util.Objects; |
36 |
| -import javax.annotation.Nullable; |
37 | 26 |
|
38 | 27 | /**
|
39 | 28 | * The provider for the cluster_resolver load balancing policy. This class should not be directly
|
@@ -69,145 +58,4 @@ public LoadBalancer newLoadBalancer(Helper helper) {
|
69 | 58 | return new ClusterResolverLoadBalancer(helper);
|
70 | 59 | }
|
71 | 60 |
|
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) { |
79 |
| - this.discoveryMechanisms = checkNotNull(discoveryMechanisms, "discoveryMechanisms"); |
80 |
| - this.lbConfig = checkNotNull(lbConfig, "lbConfig"); |
81 |
| - } |
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 { |
135 |
| - EDS, |
136 |
| - LOGICAL_DNS, |
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) { |
143 |
| - this.cluster = checkNotNull(cluster, "cluster"); |
144 |
| - this.type = checkNotNull(type, "type"); |
145 |
| - this.edsServiceName = edsServiceName; |
146 |
| - this.dnsHostName = dnsHostName; |
147 |
| - this.lrsServerInfo = lrsServerInfo; |
148 |
| - this.maxConcurrentRequests = maxConcurrentRequests; |
149 |
| - this.tlsContext = tlsContext; |
150 |
| - this.filterMetadata = ImmutableMap.copyOf(checkNotNull(filterMetadata, "filterMetadata")); |
151 |
| - this.outlierDetection = outlierDetection; |
152 |
| - } |
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, |
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, |
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 | 61 | }
|
0 commit comments