23
23
import com .google .common .base .MoreObjects ;
24
24
import io .grpc .ConnectivityState ;
25
25
import io .grpc .InternalLogId ;
26
- import io .grpc .LoadBalancerProvider ;
26
+ import io .grpc .LoadBalancer ;
27
27
import io .grpc .Status ;
28
28
import io .grpc .SynchronizationContext ;
29
29
import io .grpc .SynchronizationContext .ScheduledHandle ;
30
- import io .grpc .internal . ServiceConfigUtil . PolicySelection ;
30
+ import io .grpc .util . GracefulSwitchLoadBalancer ;
31
31
import io .grpc .util .MultiChildLoadBalancer ;
32
32
import io .grpc .xds .ClusterManagerLoadBalancerProvider .ClusterManagerConfig ;
33
33
import io .grpc .xds .client .XdsLogger ;
@@ -71,7 +71,10 @@ class ClusterManagerLoadBalancer extends MultiChildLoadBalancer {
71
71
72
72
@ Override
73
73
protected ResolvedAddresses getChildAddresses (Object key , ResolvedAddresses resolvedAddresses ,
74
- Object childConfig ) {
74
+ Object unusedChildConfig ) {
75
+ ClusterManagerConfig config = (ClusterManagerConfig )
76
+ resolvedAddresses .getLoadBalancingPolicyConfig ();
77
+ Object childConfig = config .childPolicies .get (key );
75
78
return resolvedAddresses .toBuilder ().setLoadBalancingPolicyConfig (childConfig ).build ();
76
79
}
77
80
@@ -81,13 +84,12 @@ protected Map<Object, ChildLbState> createChildLbMap(ResolvedAddresses resolvedA
81
84
resolvedAddresses .getLoadBalancingPolicyConfig ();
82
85
Map <Object , ChildLbState > newChildPolicies = new HashMap <>();
83
86
if (config != null ) {
84
- for (Entry < String , PolicySelection > entry : config .childPolicies .entrySet ()) {
85
- ChildLbState child = getChildLbState (entry . getKey () );
87
+ for (String key : config .childPolicies .keySet ()) {
88
+ ChildLbState child = getChildLbState (key );
86
89
if (child == null ) {
87
- child = new ClusterManagerLbState (entry .getKey (),
88
- entry .getValue ().getProvider (), entry .getValue ().getConfig ());
90
+ child = new ClusterManagerLbState (key , GracefulSwitchLoadBalancerFactory .INSTANCE , null );
89
91
}
90
- newChildPolicies .put (entry . getKey () , child );
92
+ newChildPolicies .put (key , child );
91
93
}
92
94
}
93
95
logger .log (
@@ -108,8 +110,8 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
108
110
resolvedAddresses .getLoadBalancingPolicyConfig ();
109
111
ClusterManagerConfig lastConfig = (ClusterManagerConfig )
110
112
lastResolvedAddresses .getLoadBalancingPolicyConfig ();
111
- Map <String , PolicySelection > adjChildPolicies = new HashMap <>(config .childPolicies );
112
- for (Entry <String , PolicySelection > entry : lastConfig .childPolicies .entrySet ()) {
113
+ Map <String , Object > adjChildPolicies = new HashMap <>(config .childPolicies );
114
+ for (Entry <String , Object > entry : lastConfig .childPolicies .entrySet ()) {
113
115
ClusterManagerLbState state = (ClusterManagerLbState ) getChildLbState (entry .getKey ());
114
116
if (adjChildPolicies .containsKey (entry .getKey ())) {
115
117
if (state .deletionTimer != null ) {
@@ -202,9 +204,9 @@ private class ClusterManagerLbState extends ChildLbState {
202
204
@ Nullable
203
205
ScheduledHandle deletionTimer ;
204
206
205
- public ClusterManagerLbState (Object key , LoadBalancerProvider policyProvider ,
207
+ public ClusterManagerLbState (Object key , LoadBalancer . Factory policyFactory ,
206
208
Object childConfig ) {
207
- super (key , policyProvider , childConfig );
209
+ super (key , policyFactory , childConfig );
208
210
}
209
211
210
212
@ Override
@@ -237,8 +239,8 @@ class DeletionTask implements Runnable {
237
239
public void run () {
238
240
ClusterManagerConfig config = (ClusterManagerConfig )
239
241
lastResolvedAddresses .getLoadBalancingPolicyConfig ();
240
- Map <String , PolicySelection > childPolicies = new HashMap <>(config .childPolicies );
241
- PolicySelection removed = childPolicies .remove (getKey ());
242
+ Map <String , Object > childPolicies = new HashMap <>(config .childPolicies );
243
+ Object removed = childPolicies .remove (getKey ());
242
244
assert removed != null ;
243
245
config = new ClusterManagerConfig (childPolicies );
244
246
lastResolvedAddresses =
@@ -276,4 +278,13 @@ public void updateBalancingState(final ConnectivityState newState,
276
278
}
277
279
}
278
280
}
281
+
282
+ static final class GracefulSwitchLoadBalancerFactory extends LoadBalancer .Factory {
283
+ static final LoadBalancer .Factory INSTANCE = new GracefulSwitchLoadBalancerFactory ();
284
+
285
+ @ Override
286
+ public LoadBalancer newLoadBalancer (LoadBalancer .Helper helper ) {
287
+ return new GracefulSwitchLoadBalancer (helper );
288
+ }
289
+ }
279
290
}
0 commit comments