@@ -106,7 +106,7 @@ public class DomainProcessorImpl implements DomainProcessor, MakeRightExecutor {
106
106
private static Map <String , Map <String , ScheduledFuture <?>>> statusUpdaters = new ConcurrentHashMap <>();
107
107
108
108
// List of clusters in a namespace.
109
- private static Map <String , Map <String , ClusterPresenceInfo >> clusters = new ConcurrentHashMap <>();
109
+ private static final Map <String , Map <String , ClusterPresenceInfo >> clusters = new ConcurrentHashMap <>();
110
110
111
111
private final DomainProcessorDelegate delegate ;
112
112
private final SemanticVersion productVersion ;
@@ -132,11 +132,12 @@ public DomainProcessorImpl(DomainProcessorDelegate delegate, SemanticVersion pro
132
132
this .productVersion = productVersion ;
133
133
}
134
134
135
- private static DomainPresenceInfo getExistingDomainPresenceInfo (String ns , String domainUid ) {
135
+ @ Override
136
+ public DomainPresenceInfo getExistingDomainPresenceInfo (String ns , String domainUid ) {
136
137
return domains .computeIfAbsent (ns , k -> new ConcurrentHashMap <>()).get (domainUid );
137
138
}
138
139
139
- private static DomainPresenceInfo getExistingDomainPresenceInfo (DomainPresenceInfo newPresence ) {
140
+ private DomainPresenceInfo getExistingDomainPresenceInfo (DomainPresenceInfo newPresence ) {
140
141
return getExistingDomainPresenceInfo (newPresence .getNamespace (), newPresence .getDomainUid ());
141
142
}
142
143
@@ -158,6 +159,11 @@ public Map<String, Map<String,ClusterPresenceInfo>> getClusterPresenceInfoMap()
158
159
return clusters ;
159
160
}
160
161
162
+ @ Override
163
+ public Map <String , FiberGate > getMakeRightFiberGateMap () {
164
+ return makeRightFiberGates ;
165
+ }
166
+
161
167
private static List <DomainPresenceInfo > getExistingDomainPresenceInfoForCluster (String ns , String cluster ) {
162
168
List <DomainPresenceInfo > referencingDomains = new ArrayList <>();
163
169
Optional .ofNullable (domains .get (ns )).ifPresent (d -> d .values ().stream ()
@@ -244,21 +250,10 @@ private static void deleteEventK8SObjects(CoreV1Event event) {
244
250
getEventK8SObjects (event ).remove (event );
245
251
}
246
252
247
- private static void onCreateModifyEvent (CoreV1Event event ) {
248
- V1ObjectReference ref = event .getInvolvedObject ();
249
-
250
- if (ref == null || ref .getName () == null ) {
251
- return ;
252
- }
253
-
254
- String kind = ref .getKind ();
255
- if (kind == null ) {
256
- return ;
257
- }
258
-
253
+ private static void onCreateModifyEvent (@ Nonnull String kind , @ Nonnull String name , CoreV1Event event ) {
259
254
switch (kind ) {
260
255
case EventConstants .EVENT_KIND_POD :
261
- processPodEvent (event );
256
+ processPodEvent (name , event );
262
257
break ;
263
258
case EventConstants .EVENT_KIND_DOMAIN :
264
259
case EventConstants .EVENT_KIND_NAMESPACE :
@@ -272,13 +267,8 @@ private static void onCreateModifyEvent(CoreV1Event event) {
272
267
}
273
268
}
274
269
275
- private static void processPodEvent (CoreV1Event event ) {
276
- V1ObjectReference ref = event .getInvolvedObject ();
277
-
278
- if (ref == null || ref .getName () == null ) {
279
- return ;
280
- }
281
- if (ref .getName ().equals (NamespaceHelper .getOperatorPodName ())) {
270
+ private static void processPodEvent (@ Nonnull String name , CoreV1Event event ) {
271
+ if (name .equals (NamespaceHelper .getOperatorPodName ())) {
282
272
updateEventK8SObjects (event );
283
273
} else {
284
274
processServerEvent (event );
@@ -313,30 +303,19 @@ public static List<DomainResource> getDomains(String ns) {
313
303
}
314
304
315
305
private static void addToList (List <DomainResource > list , DomainPresenceInfo info ) {
316
- if (info . isNotDeleting ()) {
306
+ if (isNotDeleting (info )) {
317
307
list .add (info .getDomain ());
318
308
}
319
309
}
320
310
321
- private void onDeleteEvent (CoreV1Event event ) {
322
- V1ObjectReference ref = event .getInvolvedObject ();
323
-
324
- if (ref == null || ref .getName () == null ) {
325
- return ;
326
- }
327
-
328
- String kind = ref .getKind ();
329
- if (kind == null ) {
330
- return ;
331
- }
332
-
311
+ private void onDeleteEvent (@ Nonnull String kind , @ Nonnull String name , CoreV1Event event ) {
333
312
switch (kind ) {
334
313
case EventConstants .EVENT_KIND_DOMAIN :
335
314
case EventConstants .EVENT_KIND_NAMESPACE :
336
315
deleteEventK8SObjects (event );
337
316
break ;
338
317
case EventConstants .EVENT_KIND_POD :
339
- if (ref . getName () .equals (NamespaceHelper .getOperatorPodName ())) {
318
+ if (name .equals (NamespaceHelper .getOperatorPodName ())) {
340
319
deleteEventK8SObjects (event );
341
320
}
342
321
break ;
@@ -432,7 +411,11 @@ private boolean findClusterPresenceInfo(String namespace, String clusterName) {
432
411
}
433
412
434
413
private boolean hasDeletedClusterEventData (MakeRightClusterOperation operation ) {
435
- return operation .getEventData () != null && operation .getEventData ().getItem ().name ().equals ("CLUSTER_DELETED" );
414
+ return EventItem .CLUSTER_DELETED == getEventItem (operation );
415
+ }
416
+
417
+ private EventItem getEventItem (MakeRightClusterOperation operation ) {
418
+ return Optional .ofNullable (operation .getEventData ()).map (EventData ::getItem ).orElse (null );
436
419
}
437
420
438
421
private void logStartingDomain (DomainPresenceInfo presenceInfo ) {
@@ -477,6 +460,10 @@ public void registerClusterPresenceInfo(ClusterPresenceInfo info) {
477
460
@ Override
478
461
public void unregisterDomainPresenceInfo (DomainPresenceInfo info ) {
479
462
unregisterPresenceInfo (info .getNamespace (), info .getDomainUid ());
463
+ }
464
+
465
+ @ Override
466
+ public void unregisterDomainEventK8SObjects (DomainPresenceInfo info ) {
480
467
unregisterEventK8SObject (info .getNamespace (), info .getDomainUid ());
481
468
}
482
469
@@ -595,7 +582,7 @@ private void processServerPodWatch(V1Pod pod, String watchType) {
595
582
break ;
596
583
case DELETED :
597
584
boolean removed = info .deleteServerPodFromEvent (serverName , pod );
598
- if (removed && info . isNotDeleting () && Boolean .FALSE .equals (info .isServerPodBeingDeleted (serverName ))) {
585
+ if (removed && isNotDeleting (info ) && Boolean .FALSE .equals (info .isServerPodBeingDeleted (serverName ))) {
599
586
LOGGER .info (MessageKeys .POD_DELETED , domainUid , getPodNamespace (pod ), serverName );
600
587
createMakeRightOperation (info ).interrupt ().withExplicitRecheck ().execute ();
601
588
}
@@ -670,7 +657,7 @@ public void dispatchServiceWatch(Watch.Response<V1Service> item) {
670
657
break ;
671
658
case DELETED :
672
659
boolean removed = ServiceHelper .deleteFromEvent (info , item .object );
673
- if (removed && info . isNotDeleting ()) {
660
+ if (removed && isNotDeleting (info )) {
674
661
createMakeRightOperation (info ).interrupt ().withExplicitRecheck ().execute ();
675
662
}
676
663
break ;
@@ -702,14 +689,18 @@ public void dispatchPodDisruptionBudgetWatch(Watch.Response<V1PodDisruptionBudge
702
689
break ;
703
690
case DELETED :
704
691
boolean removed = PodDisruptionBudgetHelper .deleteFromEvent (info , item .object );
705
- if (removed && info . isNotDeleting ()) {
692
+ if (removed && isNotDeleting (info )) {
706
693
createMakeRightOperation (info ).interrupt ().withExplicitRecheck ().execute ();
707
694
}
708
695
break ;
709
696
default :
710
697
}
711
698
}
712
699
700
+ private static boolean isNotDeleting (DomainPresenceInfo info ) {
701
+ return info .isNotDeleting () && info .getDomain () != null ;
702
+ }
703
+
713
704
private String getPDBNamespace (V1PodDisruptionBudget pdb ) {
714
705
return Optional .ofNullable (pdb ).map (V1PodDisruptionBudget ::getMetadata )
715
706
.map (V1ObjectMeta ::getNamespace ).orElse (null );
@@ -721,7 +712,7 @@ private String getPDBNamespace(V1PodDisruptionBudget pdb) {
721
712
*/
722
713
public void dispatchConfigMapWatch (Watch .Response <V1ConfigMap > item ) {
723
714
V1ConfigMap c = item .object ;
724
- if (c != null && c .getMetadata () != null ) {
715
+ if (c .getMetadata () != null ) {
725
716
switch (item .type ) {
726
717
case MODIFIED :
727
718
case DELETED :
@@ -742,18 +733,22 @@ public void dispatchConfigMapWatch(Watch.Response<V1ConfigMap> item) {
742
733
*/
743
734
public void dispatchEventWatch (Watch .Response <CoreV1Event > item ) {
744
735
CoreV1Event e = item .object ;
745
- if (e != null ) {
746
- switch (item .type ) {
747
- case ADDED :
748
- case MODIFIED :
749
- onCreateModifyEvent (e );
750
- break ;
751
- case DELETED :
752
- onDeleteEvent (e );
753
- break ;
754
- case ERROR :
755
- default :
756
- }
736
+ V1ObjectReference ref = e .getInvolvedObject ();
737
+
738
+ if (ref == null || ref .getName () == null || ref .getKind () == null ) {
739
+ return ;
740
+ }
741
+
742
+ switch (item .type ) {
743
+ case ADDED :
744
+ case MODIFIED :
745
+ onCreateModifyEvent (ref .getKind (), ref .getName (), e );
746
+ break ;
747
+ case DELETED :
748
+ onDeleteEvent (ref .getKind (), ref .getName (), e );
749
+ break ;
750
+ case ERROR :
751
+ default :
757
752
}
758
753
}
759
754
0 commit comments