@@ -78,13 +78,95 @@ public static Step createAdminPodStep(Step next) {
78
78
return new AdminPodStep (next );
79
79
}
80
80
81
- private static class AdminPodStep extends Step {
81
+ // Make this public so that it can be unit tested
82
+ public static class AdminPodStep extends Step {
82
83
public AdminPodStep (Step next ) {
83
84
super (next );
84
85
}
85
86
86
87
@ Override
87
88
public NextAction apply (Packet packet ) {
89
+
90
+ // Compute the desired pod configuration for the admin server
91
+ V1Pod adminPod = computeAdminPodConfig (packet );
92
+
93
+ // Verify if Kubernetes api server has a matching Pod
94
+ // Create or replace, if necessary
95
+ V1ObjectMeta metadata = adminPod .getMetadata ();
96
+ String podName = metadata .getName ();
97
+ String namespace = metadata .getNamespace ();
98
+ String weblogicDomainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
99
+ String asName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
100
+
101
+ DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
102
+
103
+ Boolean explicitRestartAdmin = (Boolean ) packet .get (ProcessingConstants .EXPLICIT_RESTART_ADMIN );
104
+ @ SuppressWarnings ("unchecked" )
105
+ List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
106
+
107
+ boolean isExplicitRestartThisServer =
108
+ (Boolean .TRUE .equals (explicitRestartAdmin )) ||
109
+ (explicitRestartServers != null && explicitRestartServers .contains (asName ));
110
+
111
+ ServerKubernetesObjects created = new ServerKubernetesObjects ();
112
+ ServerKubernetesObjects current = info .getServers ().putIfAbsent (asName , created );
113
+ ServerKubernetesObjects sko = current != null ? current : created ;
114
+
115
+ // First, verify existing Pod
116
+ Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
117
+ @ Override
118
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
119
+ Map <String , List <String >> responseHeaders ) {
120
+ if (statusCode == CallBuilder .NOT_FOUND ) {
121
+ return onSuccess (packet , null , statusCode , responseHeaders );
122
+ }
123
+ return super .onFailure (packet , e , statusCode , responseHeaders );
124
+ }
125
+
126
+ @ Override
127
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
128
+ Map <String , List <String >> responseHeaders ) {
129
+ if (result == null ) {
130
+ Step create = CallBuilder .create ().createPodAsync (namespace , adminPod , new ResponseStep <V1Pod >(next ) {
131
+ @ Override
132
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
133
+ Map <String , List <String >> responseHeaders ) {
134
+ return super .onFailure (AdminPodStep .this , packet , e , statusCode , responseHeaders );
135
+ }
136
+
137
+ @ Override
138
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
139
+ Map <String , List <String >> responseHeaders ) {
140
+
141
+ LOGGER .info (MessageKeys .ADMIN_POD_CREATED , weblogicDomainUID , asName );
142
+ if (result != null ) {
143
+ sko .getPod ().set (result );
144
+ }
145
+ return doNext (packet );
146
+ }
147
+ });
148
+ return doNext (create , packet );
149
+ } else if (!isExplicitRestartThisServer && validateCurrentPod (adminPod , result )) {
150
+ // existing Pod has correct spec
151
+ LOGGER .fine (MessageKeys .ADMIN_POD_EXISTS , weblogicDomainUID , asName );
152
+ sko .getPod ().set (result );
153
+ return doNext (packet );
154
+ } else {
155
+ // we need to update the Pod
156
+ Step replace = new CyclePodStep (
157
+ AdminPodStep .this ,
158
+ podName , namespace , adminPod , MessageKeys .ADMIN_POD_REPLACED ,
159
+ weblogicDomainUID , asName , sko , next );
160
+ return doNext (replace , packet );
161
+ }
162
+ }
163
+ });
164
+
165
+ return doNext (read , packet );
166
+ }
167
+
168
+ // Make this protected so that it can be unit tested
169
+ protected V1Pod computeAdminPodConfig (Packet packet ) {
88
170
DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
89
171
90
172
Domain dom = info .getDomain ();
@@ -98,14 +180,6 @@ public NextAction apply(Packet packet) {
98
180
// Create local admin server Pod object
99
181
String podName = CallBuilder .toDNS1123LegalName (weblogicDomainUID + "-" + spec .getAsName ());
100
182
101
- Boolean explicitRestartAdmin = (Boolean ) packet .get (ProcessingConstants .EXPLICIT_RESTART_ADMIN );
102
- @ SuppressWarnings ("unchecked" )
103
- List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
104
-
105
- boolean isExplicitRestartThisServer =
106
- (Boolean .TRUE .equals (explicitRestartAdmin )) ||
107
- (explicitRestartServers != null && explicitRestartServers .contains (spec .getAsName ()));
108
-
109
183
String imageName = spec .getImage ();
110
184
if (imageName == null || imageName .length () == 0 ) {
111
185
imageName = KubernetesConstants .DEFAULT_IMAGE ;
@@ -213,8 +287,7 @@ public NextAction apply(Packet packet) {
213
287
}
214
288
215
289
// Add internal-weblogic-operator-service certificate to Admin Server pod
216
- ConfigMapConsumer configMapHelper = packet .getSPI (ConfigMapConsumer .class );
217
- String internalOperatorCert = configMapHelper .get (INTERNAL_OPERATOR_CERT_FILE );
290
+ String internalOperatorCert = getInternalOperatorCertFile (packet );
218
291
addEnvVar (container , INTERNAL_OPERATOR_CERT_ENV , internalOperatorCert );
219
292
220
293
// Override the weblogic domain and admin server related environment variables that
@@ -245,63 +318,13 @@ public NextAction apply(Packet packet) {
245
318
volumeDomainConfigMap .setConfigMap (cm );
246
319
podSpec .addVolumesItem (volumeDomainConfigMap );
247
320
248
- // Verify if Kubernetes api server has a matching Pod
249
- // Create or replace, if necessary
250
- ServerKubernetesObjects created = new ServerKubernetesObjects ();
251
- ServerKubernetesObjects current = info .getServers ().putIfAbsent (spec .getAsName (), created );
252
- ServerKubernetesObjects sko = current != null ? current : created ;
253
-
254
- // First, verify existing Pod
255
- Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
256
- @ Override
257
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
258
- Map <String , List <String >> responseHeaders ) {
259
- if (statusCode == CallBuilder .NOT_FOUND ) {
260
- return onSuccess (packet , null , statusCode , responseHeaders );
261
- }
262
- return super .onFailure (packet , e , statusCode , responseHeaders );
263
- }
321
+ return adminPod ;
322
+ }
264
323
265
- @ Override
266
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
267
- Map <String , List <String >> responseHeaders ) {
268
- if (result == null ) {
269
- Step create = CallBuilder .create ().createPodAsync (namespace , adminPod , new ResponseStep <V1Pod >(next ) {
270
- @ Override
271
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
272
- Map <String , List <String >> responseHeaders ) {
273
- return super .onFailure (AdminPodStep .this , packet , e , statusCode , responseHeaders );
274
- }
275
-
276
- @ Override
277
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
278
- Map <String , List <String >> responseHeaders ) {
279
-
280
- LOGGER .info (MessageKeys .ADMIN_POD_CREATED , weblogicDomainUID , spec .getAsName ());
281
- if (result != null ) {
282
- sko .getPod ().set (result );
283
- }
284
- return doNext (packet );
285
- }
286
- });
287
- return doNext (create , packet );
288
- } else if (!isExplicitRestartThisServer && validateCurrentPod (adminPod , result )) {
289
- // existing Pod has correct spec
290
- LOGGER .fine (MessageKeys .ADMIN_POD_EXISTS , weblogicDomainUID , spec .getAsName ());
291
- sko .getPod ().set (result );
292
- return doNext (packet );
293
- } else {
294
- // we need to update the Pod
295
- Step replace = new CyclePodStep (
296
- AdminPodStep .this ,
297
- podName , namespace , adminPod , MessageKeys .ADMIN_POD_REPLACED ,
298
- weblogicDomainUID , spec .getAsName (), sko , next );
299
- return doNext (replace , packet );
300
- }
301
- }
302
- });
303
-
304
- return doNext (read , packet );
324
+ // Make it protected to so that it can be unit tested:
325
+ protected String getInternalOperatorCertFile (Packet packet ) {
326
+ ConfigMapConsumer configMapHelper = packet .getSPI (ConfigMapConsumer .class );
327
+ return configMapHelper .get (INTERNAL_OPERATOR_CERT_FILE );
305
328
}
306
329
}
307
330
@@ -450,13 +473,105 @@ private static <T> boolean compareUnordered(List<T> a, List<T> b) {
450
473
return true ;
451
474
}
452
475
453
- private static class ManagedPodStep extends Step {
476
+ // Make this public so that it can be unit tested
477
+ public static class ManagedPodStep extends Step {
454
478
public ManagedPodStep (Step next ) {
455
479
super (next );
456
480
}
457
481
458
482
@ Override
459
483
public NextAction apply (Packet packet ) {
484
+ // Compute the desired pod configuration for the managed server
485
+ V1Pod pod = computeManagedPodConfig (packet );
486
+
487
+ // Verify if Kubernetes api server has a matching Pod
488
+ // Create or replace, if necessary
489
+ V1ObjectMeta metadata = pod .getMetadata ();
490
+ String podName = metadata .getName ();
491
+ String namespace = metadata .getNamespace ();
492
+ String weblogicDomainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
493
+ String weblogicServerName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
494
+ String weblogicClusterName = metadata .getLabels ().get (LabelConstants .CLUSTERNAME_LABEL );
495
+
496
+ DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
497
+
498
+ @ SuppressWarnings ("unchecked" )
499
+ List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
500
+ @ SuppressWarnings ("unchecked" )
501
+ List <String > explicitRestartClusters = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_CLUSTERS );
502
+
503
+ boolean isExplicitRestartThisServer =
504
+ (explicitRestartServers != null && explicitRestartServers .contains (weblogicServerName )) ||
505
+ (explicitRestartClusters != null && weblogicClusterName != null && explicitRestartClusters .contains (weblogicClusterName ));
506
+
507
+ ServerKubernetesObjects created = new ServerKubernetesObjects ();
508
+ ServerKubernetesObjects current = info .getServers ().putIfAbsent (weblogicServerName , created );
509
+ ServerKubernetesObjects sko = current != null ? current : created ;
510
+
511
+ // First, verify there existing Pod
512
+ Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
513
+ @ Override
514
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
515
+ Map <String , List <String >> responseHeaders ) {
516
+ if (statusCode == CallBuilder .NOT_FOUND ) {
517
+ return onSuccess (packet , null , statusCode , responseHeaders );
518
+ }
519
+ return super .onFailure (packet , e , statusCode , responseHeaders );
520
+ }
521
+
522
+ @ Override
523
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
524
+ Map <String , List <String >> responseHeaders ) {
525
+ if (result == null ) {
526
+ Step create = CallBuilder .create ().createPodAsync (namespace , pod , new ResponseStep <V1Pod >(next ) {
527
+ @ Override
528
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
529
+ Map <String , List <String >> responseHeaders ) {
530
+ return super .onFailure (ManagedPodStep .this , packet , e , statusCode , responseHeaders );
531
+ }
532
+
533
+ @ Override
534
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
535
+ Map <String , List <String >> responseHeaders ) {
536
+
537
+ LOGGER .info (MessageKeys .MANAGED_POD_CREATED , weblogicDomainUID , weblogicServerName );
538
+ if (result != null ) {
539
+ sko .getPod ().set (result );
540
+ }
541
+ return doNext (packet );
542
+ }
543
+ });
544
+ return doNext (DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , create ), packet );
545
+ } else if (!isExplicitRestartThisServer && validateCurrentPod (pod , result )) {
546
+ // existing Pod has correct spec
547
+ LOGGER .fine (MessageKeys .MANAGED_POD_EXISTS , weblogicDomainUID , weblogicServerName );
548
+ sko .getPod ().set (result );
549
+ return doNext (packet );
550
+ } else {
551
+ // we need to update the Pod
552
+ // defer to Pod rolling step
553
+ Step replace = new CyclePodStep (
554
+ ManagedPodStep .this ,
555
+ podName , namespace , pod , MessageKeys .MANAGED_POD_REPLACED ,
556
+ weblogicDomainUID , weblogicServerName , sko , next );
557
+ synchronized (packet ) {
558
+ @ SuppressWarnings ("unchecked" )
559
+ Map <String , StepAndPacket > rolling = (Map <String , StepAndPacket >) packet .get (ProcessingConstants .SERVERS_TO_ROLL );
560
+ if (rolling != null ) {
561
+ rolling .put (weblogicServerName , new StepAndPacket (
562
+ DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , replace ), packet .clone ()));
563
+ }
564
+ }
565
+ return doEnd (packet );
566
+ }
567
+ }
568
+ });
569
+
570
+ return doNext (read , packet );
571
+ }
572
+
573
+ // Make this protected so that it can be unit tested
574
+ protected V1Pod computeManagedPodConfig (Packet packet ) {
460
575
DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
461
576
462
577
Domain dom = info .getDomain ();
@@ -481,15 +596,6 @@ public NextAction apply(Packet packet) {
481
596
if (cluster != null )
482
597
weblogicClusterName = cluster .getClusterName ();
483
598
484
- @ SuppressWarnings ("unchecked" )
485
- List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
486
- @ SuppressWarnings ("unchecked" )
487
- List <String > explicitRestartClusters = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_CLUSTERS );
488
-
489
- boolean isExplicitRestartThisServer =
490
- (explicitRestartServers != null && explicitRestartServers .contains (weblogicServerName )) ||
491
- (explicitRestartClusters != null && weblogicClusterName != null && explicitRestartClusters .contains (weblogicClusterName ));
492
-
493
599
String imageName = spec .getImage ();
494
600
if (imageName == null || imageName .length () == 0 ) {
495
601
imageName = KubernetesConstants .DEFAULT_IMAGE ;
@@ -620,72 +726,7 @@ public NextAction apply(Packet packet) {
620
726
// come for free with the WLS docker container with the correct values.
621
727
overrideContainerWeblogicEnvVars (spec , weblogicServerName , container );
622
728
623
- // Verify if Kubernetes api server has a matching Pod
624
- // Create or replace, if necessary
625
- ServerKubernetesObjects created = new ServerKubernetesObjects ();
626
- ServerKubernetesObjects current = info .getServers ().putIfAbsent (weblogicServerName , created );
627
- ServerKubernetesObjects sko = current != null ? current : created ;
628
-
629
- // First, verify there existing Pod
630
- Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
631
- @ Override
632
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
633
- Map <String , List <String >> responseHeaders ) {
634
- if (statusCode == CallBuilder .NOT_FOUND ) {
635
- return onSuccess (packet , null , statusCode , responseHeaders );
636
- }
637
- return super .onFailure (packet , e , statusCode , responseHeaders );
638
- }
639
-
640
- @ Override
641
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
642
- Map <String , List <String >> responseHeaders ) {
643
- if (result == null ) {
644
- Step create = CallBuilder .create ().createPodAsync (namespace , pod , new ResponseStep <V1Pod >(next ) {
645
- @ Override
646
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
647
- Map <String , List <String >> responseHeaders ) {
648
- return super .onFailure (ManagedPodStep .this , packet , e , statusCode , responseHeaders );
649
- }
650
-
651
- @ Override
652
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
653
- Map <String , List <String >> responseHeaders ) {
654
-
655
- LOGGER .info (MessageKeys .MANAGED_POD_CREATED , weblogicDomainUID , weblogicServerName );
656
- if (result != null ) {
657
- sko .getPod ().set (result );
658
- }
659
- return doNext (packet );
660
- }
661
- });
662
- return doNext (DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , create ), packet );
663
- } else if (!isExplicitRestartThisServer && validateCurrentPod (pod , result )) {
664
- // existing Pod has correct spec
665
- LOGGER .fine (MessageKeys .MANAGED_POD_EXISTS , weblogicDomainUID , weblogicServerName );
666
- sko .getPod ().set (result );
667
- return doNext (packet );
668
- } else {
669
- // we need to update the Pod
670
- // defer to Pod rolling step
671
- Step replace = new CyclePodStep (
672
- ManagedPodStep .this ,
673
- podName , namespace , pod , MessageKeys .MANAGED_POD_REPLACED ,
674
- weblogicDomainUID , weblogicServerName , sko , next );
675
- synchronized (packet ) {
676
- @ SuppressWarnings ("unchecked" )
677
- Map <String , StepAndPacket > rolling = (Map <String , StepAndPacket >) packet .get (ProcessingConstants .SERVERS_TO_ROLL );
678
- if (rolling != null ) {
679
- rolling .put (weblogicServerName , new StepAndPacket (
680
- DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , replace ), packet .clone ()));
681
- }
682
- }
683
- return doEnd (packet );
684
- }
685
- }
686
- });
687
-
688
- return doNext (read , packet );
729
+ return pod ;
689
730
}
690
731
}
691
732
0 commit comments