@@ -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 ;
@@ -226,8 +300,7 @@ public NextAction apply(Packet packet) {
226
300
}
227
301
228
302
// Add internal-weblogic-operator-service certificate to Admin Server pod
229
- ConfigMapConsumer configMapHelper = packet .getSPI (ConfigMapConsumer .class );
230
- String internalOperatorCert = configMapHelper .get (INTERNAL_OPERATOR_CERT_FILE );
303
+ String internalOperatorCert = getInternalOperatorCertFile (packet );
231
304
addEnvVar (container , INTERNAL_OPERATOR_CERT_ENV , internalOperatorCert );
232
305
233
306
// Override the weblogic domain and admin server related environment variables that
@@ -258,63 +331,13 @@ public NextAction apply(Packet packet) {
258
331
volumeDomainConfigMap .setConfigMap (cm );
259
332
podSpec .addVolumesItem (volumeDomainConfigMap );
260
333
261
- // Verify if Kubernetes api server has a matching Pod
262
- // Create or replace, if necessary
263
- ServerKubernetesObjects created = new ServerKubernetesObjects ();
264
- ServerKubernetesObjects current = info .getServers ().putIfAbsent (spec .getAsName (), created );
265
- ServerKubernetesObjects sko = current != null ? current : created ;
266
-
267
- // First, verify existing Pod
268
- Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
269
- @ Override
270
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
271
- Map <String , List <String >> responseHeaders ) {
272
- if (statusCode == CallBuilder .NOT_FOUND ) {
273
- return onSuccess (packet , null , statusCode , responseHeaders );
274
- }
275
- return super .onFailure (packet , e , statusCode , responseHeaders );
276
- }
334
+ return adminPod ;
335
+ }
277
336
278
- @ Override
279
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
280
- Map <String , List <String >> responseHeaders ) {
281
- if (result == null ) {
282
- Step create = CallBuilder .create ().createPodAsync (namespace , adminPod , new ResponseStep <V1Pod >(next ) {
283
- @ Override
284
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
285
- Map <String , List <String >> responseHeaders ) {
286
- return super .onFailure (AdminPodStep .this , packet , e , statusCode , responseHeaders );
287
- }
288
-
289
- @ Override
290
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
291
- Map <String , List <String >> responseHeaders ) {
292
-
293
- LOGGER .info (MessageKeys .ADMIN_POD_CREATED , weblogicDomainUID , spec .getAsName ());
294
- if (result != null ) {
295
- sko .getPod ().set (result );
296
- }
297
- return doNext (packet );
298
- }
299
- });
300
- return doNext (create , packet );
301
- } else if (!isExplicitRestartThisServer && validateCurrentPod (adminPod , result )) {
302
- // existing Pod has correct spec
303
- LOGGER .fine (MessageKeys .ADMIN_POD_EXISTS , weblogicDomainUID , spec .getAsName ());
304
- sko .getPod ().set (result );
305
- return doNext (packet );
306
- } else {
307
- // we need to update the Pod
308
- Step replace = new CyclePodStep (
309
- AdminPodStep .this ,
310
- podName , namespace , adminPod , MessageKeys .ADMIN_POD_REPLACED ,
311
- weblogicDomainUID , spec .getAsName (), sko , next );
312
- return doNext (replace , packet );
313
- }
314
- }
315
- });
316
-
317
- return doNext (read , packet );
337
+ // Make it protected to so that it can be unit tested:
338
+ protected String getInternalOperatorCertFile (Packet packet ) {
339
+ ConfigMapConsumer configMapHelper = packet .getSPI (ConfigMapConsumer .class );
340
+ return configMapHelper .get (INTERNAL_OPERATOR_CERT_FILE );
318
341
}
319
342
}
320
343
@@ -463,13 +486,105 @@ private static <T> boolean compareUnordered(List<T> a, List<T> b) {
463
486
return true ;
464
487
}
465
488
466
- private static class ManagedPodStep extends Step {
489
+ // Make this public so that it can be unit tested
490
+ public static class ManagedPodStep extends Step {
467
491
public ManagedPodStep (Step next ) {
468
492
super (next );
469
493
}
470
494
471
495
@ Override
472
496
public NextAction apply (Packet packet ) {
497
+ // Compute the desired pod configuration for the managed server
498
+ V1Pod pod = computeManagedPodConfig (packet );
499
+
500
+ // Verify if Kubernetes api server has a matching Pod
501
+ // Create or replace, if necessary
502
+ V1ObjectMeta metadata = pod .getMetadata ();
503
+ String podName = metadata .getName ();
504
+ String namespace = metadata .getNamespace ();
505
+ String weblogicDomainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
506
+ String weblogicServerName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
507
+ String weblogicClusterName = metadata .getLabels ().get (LabelConstants .CLUSTERNAME_LABEL );
508
+
509
+ DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
510
+
511
+ @ SuppressWarnings ("unchecked" )
512
+ List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
513
+ @ SuppressWarnings ("unchecked" )
514
+ List <String > explicitRestartClusters = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_CLUSTERS );
515
+
516
+ boolean isExplicitRestartThisServer =
517
+ (explicitRestartServers != null && explicitRestartServers .contains (weblogicServerName )) ||
518
+ (explicitRestartClusters != null && weblogicClusterName != null && explicitRestartClusters .contains (weblogicClusterName ));
519
+
520
+ ServerKubernetesObjects created = new ServerKubernetesObjects ();
521
+ ServerKubernetesObjects current = info .getServers ().putIfAbsent (weblogicServerName , created );
522
+ ServerKubernetesObjects sko = current != null ? current : created ;
523
+
524
+ // First, verify there existing Pod
525
+ Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
526
+ @ Override
527
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
528
+ Map <String , List <String >> responseHeaders ) {
529
+ if (statusCode == CallBuilder .NOT_FOUND ) {
530
+ return onSuccess (packet , null , statusCode , responseHeaders );
531
+ }
532
+ return super .onFailure (packet , e , statusCode , responseHeaders );
533
+ }
534
+
535
+ @ Override
536
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
537
+ Map <String , List <String >> responseHeaders ) {
538
+ if (result == null ) {
539
+ Step create = CallBuilder .create ().createPodAsync (namespace , pod , new ResponseStep <V1Pod >(next ) {
540
+ @ Override
541
+ public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
542
+ Map <String , List <String >> responseHeaders ) {
543
+ return super .onFailure (ManagedPodStep .this , packet , e , statusCode , responseHeaders );
544
+ }
545
+
546
+ @ Override
547
+ public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
548
+ Map <String , List <String >> responseHeaders ) {
549
+
550
+ LOGGER .info (MessageKeys .MANAGED_POD_CREATED , weblogicDomainUID , weblogicServerName );
551
+ if (result != null ) {
552
+ sko .getPod ().set (result );
553
+ }
554
+ return doNext (packet );
555
+ }
556
+ });
557
+ return doNext (DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , create ), packet );
558
+ } else if (!isExplicitRestartThisServer && validateCurrentPod (pod , result )) {
559
+ // existing Pod has correct spec
560
+ LOGGER .fine (MessageKeys .MANAGED_POD_EXISTS , weblogicDomainUID , weblogicServerName );
561
+ sko .getPod ().set (result );
562
+ return doNext (packet );
563
+ } else {
564
+ // we need to update the Pod
565
+ // defer to Pod rolling step
566
+ Step replace = new CyclePodStep (
567
+ ManagedPodStep .this ,
568
+ podName , namespace , pod , MessageKeys .MANAGED_POD_REPLACED ,
569
+ weblogicDomainUID , weblogicServerName , sko , next );
570
+ synchronized (packet ) {
571
+ @ SuppressWarnings ("unchecked" )
572
+ Map <String , StepAndPacket > rolling = (Map <String , StepAndPacket >) packet .get (ProcessingConstants .SERVERS_TO_ROLL );
573
+ if (rolling != null ) {
574
+ rolling .put (weblogicServerName , new StepAndPacket (
575
+ DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , replace ), packet .clone ()));
576
+ }
577
+ }
578
+ return doEnd (packet );
579
+ }
580
+ }
581
+ });
582
+
583
+ return doNext (read , packet );
584
+ }
585
+
586
+ // Make this protected so that it can be unit tested
587
+ protected V1Pod computeManagedPodConfig (Packet packet ) {
473
588
DomainPresenceInfo info = packet .getSPI (DomainPresenceInfo .class );
474
589
475
590
Domain dom = info .getDomain ();
@@ -494,15 +609,6 @@ public NextAction apply(Packet packet) {
494
609
if (cluster != null )
495
610
weblogicClusterName = cluster .getClusterName ();
496
611
497
- @ SuppressWarnings ("unchecked" )
498
- List <String > explicitRestartServers = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_SERVERS );
499
- @ SuppressWarnings ("unchecked" )
500
- List <String > explicitRestartClusters = (List <String >) packet .get (ProcessingConstants .EXPLICIT_RESTART_CLUSTERS );
501
-
502
- boolean isExplicitRestartThisServer =
503
- (explicitRestartServers != null && explicitRestartServers .contains (weblogicServerName )) ||
504
- (explicitRestartClusters != null && weblogicClusterName != null && explicitRestartClusters .contains (weblogicClusterName ));
505
-
506
612
String imageName = spec .getImage ();
507
613
if (imageName == null || imageName .length () == 0 ) {
508
614
imageName = KubernetesConstants .DEFAULT_IMAGE ;
@@ -648,72 +754,7 @@ public NextAction apply(Packet packet) {
648
754
// come for free with the WLS docker container with the correct values.
649
755
overrideContainerWeblogicEnvVars (spec , weblogicServerName , container );
650
756
651
- // Verify if Kubernetes api server has a matching Pod
652
- // Create or replace, if necessary
653
- ServerKubernetesObjects created = new ServerKubernetesObjects ();
654
- ServerKubernetesObjects current = info .getServers ().putIfAbsent (weblogicServerName , created );
655
- ServerKubernetesObjects sko = current != null ? current : created ;
656
-
657
- // First, verify there existing Pod
658
- Step read = CallBuilder .create ().readPodAsync (podName , namespace , new ResponseStep <V1Pod >(next ) {
659
- @ Override
660
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
661
- Map <String , List <String >> responseHeaders ) {
662
- if (statusCode == CallBuilder .NOT_FOUND ) {
663
- return onSuccess (packet , null , statusCode , responseHeaders );
664
- }
665
- return super .onFailure (packet , e , statusCode , responseHeaders );
666
- }
667
-
668
- @ Override
669
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
670
- Map <String , List <String >> responseHeaders ) {
671
- if (result == null ) {
672
- Step create = CallBuilder .create ().createPodAsync (namespace , pod , new ResponseStep <V1Pod >(next ) {
673
- @ Override
674
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
675
- Map <String , List <String >> responseHeaders ) {
676
- return super .onFailure (ManagedPodStep .this , packet , e , statusCode , responseHeaders );
677
- }
678
-
679
- @ Override
680
- public NextAction onSuccess (Packet packet , V1Pod result , int statusCode ,
681
- Map <String , List <String >> responseHeaders ) {
682
-
683
- LOGGER .info (MessageKeys .MANAGED_POD_CREATED , weblogicDomainUID , weblogicServerName );
684
- if (result != null ) {
685
- sko .getPod ().set (result );
686
- }
687
- return doNext (packet );
688
- }
689
- });
690
- return doNext (DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , create ), packet );
691
- } else if (!isExplicitRestartThisServer && validateCurrentPod (pod , result )) {
692
- // existing Pod has correct spec
693
- LOGGER .fine (MessageKeys .MANAGED_POD_EXISTS , weblogicDomainUID , weblogicServerName );
694
- sko .getPod ().set (result );
695
- return doNext (packet );
696
- } else {
697
- // we need to update the Pod
698
- // defer to Pod rolling step
699
- Step replace = new CyclePodStep (
700
- ManagedPodStep .this ,
701
- podName , namespace , pod , MessageKeys .MANAGED_POD_REPLACED ,
702
- weblogicDomainUID , weblogicServerName , sko , next );
703
- synchronized (packet ) {
704
- @ SuppressWarnings ("unchecked" )
705
- Map <String , StepAndPacket > rolling = (Map <String , StepAndPacket >) packet .get (ProcessingConstants .SERVERS_TO_ROLL );
706
- if (rolling != null ) {
707
- rolling .put (weblogicServerName , new StepAndPacket (
708
- DomainStatusUpdater .createProgressingStep (DomainStatusUpdater .MANAGED_SERVERS_STARTING_PROGRESS_REASON , false , replace ), packet .clone ()));
709
- }
710
- }
711
- return doEnd (packet );
712
- }
713
- }
714
- });
715
-
716
- return doNext (read , packet );
757
+ return pod ;
717
758
}
718
759
}
719
760
0 commit comments