75
75
import oracle .kubernetes .operator .work .NextAction ;
76
76
import oracle .kubernetes .operator .work .Packet ;
77
77
import oracle .kubernetes .operator .work .Step ;
78
- import oracle .kubernetes .weblogic .domain .v1 .ClusterStartup ;
79
78
import oracle .kubernetes .weblogic .domain .v1 .Domain ;
80
79
import oracle .kubernetes .weblogic .domain .v1 .DomainList ;
81
80
import oracle .kubernetes .weblogic .domain .v1 .DomainSpec ;
82
- import oracle .kubernetes .weblogic .domain .v1 .ServerStartup ;
83
81
84
82
/**
85
83
* A Kubernetes Operator for WebLogic.
@@ -275,60 +273,6 @@ public void onThrowable(Packet packet, Throwable throwable) {
275
273
//
276
274
// -----------------------------------------------------------------------------
277
275
278
- private static void normalizeDomainSpec (DomainSpec spec ) {
279
- // Normalize DomainSpec so that equals() will work correctly
280
- String imageName = spec .getImage ();
281
- if (isNotDefined (imageName )) {
282
- spec .setImage (imageName = KubernetesConstants .DEFAULT_IMAGE );
283
- }
284
- if (isNotDefined (spec .getImagePullPolicy ())) {
285
- spec .setImagePullPolicy ((imageName .endsWith (KubernetesConstants .LATEST_IMAGE_SUFFIX ))
286
- ? KubernetesConstants .ALWAYS_IMAGEPULLPOLICY
287
- : KubernetesConstants .IFNOTPRESENT_IMAGEPULLPOLICY );
288
- }
289
- if (spec .getExportT3Channels () == null ) {
290
- spec .setExportT3Channels (new ArrayList <>());
291
- }
292
- String startupControl = spec .getStartupControl ();
293
- if (isNotDefined (startupControl )) {
294
- spec .setStartupControl (StartupControlConstants .AUTO_STARTUPCONTROL );
295
- }
296
- if (spec .getServerStartup () == null ) {
297
- spec .setServerStartup (new ArrayList <>());
298
- } else {
299
- for (ServerStartup ss : spec .getServerStartup ()) {
300
- if (ss .getDesiredState () == null ) {
301
- ss .setDesiredState (WebLogicConstants .RUNNING_STATE );
302
- }
303
- if (ss .getEnv () == null ) {
304
- ss .setEnv (new ArrayList <>());
305
- }
306
- }
307
- }
308
- if (spec .getClusterStartup () == null ) {
309
- spec .setClusterStartup (new ArrayList <>());
310
- } else {
311
- for (ClusterStartup cs : spec .getClusterStartup ()) {
312
- if (cs .getDesiredState () == null ) {
313
- cs .setDesiredState (WebLogicConstants .RUNNING_STATE );
314
- }
315
- if (cs .getEnv () == null ) {
316
- cs .setEnv (new ArrayList <>());
317
- }
318
- if (cs .getReplicas () == null ) {
319
- cs .setReplicas (1 );
320
- }
321
- }
322
- }
323
- if (spec .getReplicas () == null ) {
324
- spec .setReplicas (1 );
325
- }
326
- }
327
-
328
- private static boolean isNotDefined (String value ) {
329
- return value == null || value .length () == 0 ;
330
- }
331
-
332
276
/**
333
277
* Restarts the admin server, if already running
334
278
*
@@ -454,13 +398,6 @@ public void onThrowable(Packet packet, Throwable throwable) {
454
398
}
455
399
}
456
400
457
- private static void cancelDomainStatusUpdating (DomainPresenceInfo info ) {
458
- ScheduledFuture <?> statusUpdater = info .getStatusUpdater ().getAndSet (null );
459
- if (statusUpdater != null ) {
460
- statusUpdater .cancel (true );
461
- }
462
- }
463
-
464
401
private static void doCheckAndCreateDomainPresence (Domain dom ) {
465
402
doCheckAndCreateDomainPresence (dom , false , false , null , null );
466
403
}
@@ -477,7 +414,7 @@ private static void doCheckAndCreateDomainPresence(Domain dom, boolean explicitR
477
414
|| explicitRestartClusters != null ;
478
415
479
416
DomainSpec spec = dom .getSpec ();
480
- normalizeDomainSpec (spec );
417
+ DomainPresenceControl . normalizeDomainSpec (spec );
481
418
String domainUID = spec .getDomainUID ();
482
419
483
420
DomainPresenceInfo created = new DomainPresenceInfo (dom );
@@ -599,7 +536,7 @@ private static void deleteDomainPresence(String namespace, String domainUID) {
599
536
600
537
DomainPresenceInfo info = domains .remove (domainUID );
601
538
if (info != null ) {
602
- cancelDomainStatusUpdating (info );
539
+ DomainPresenceControl . cancelDomainStatusUpdating (info );
603
540
}
604
541
domainUpdaters .startFiber (domainUID , new DeleteDomainStep (namespace , domainUID ), new Packet (),
605
542
new CompletionCallback () {
@@ -623,7 +560,7 @@ public void onThrowable(Packet packet, Throwable throwable) {
623
560
* @return the collection of target namespace names
624
561
*/
625
562
private static Collection <String > getTargetNamespaces (String namespace ) {
626
- Collection <String > targetNamespaces = new ArrayList <String >();
563
+ Collection <String > targetNamespaces = new ArrayList <>();
627
564
628
565
String tnValue = tuningAndConfig .get ("targetNamespaces" );
629
566
if (tnValue != null ) {
@@ -678,10 +615,6 @@ public static boolean getStopping() {
678
615
return stopping .get ();
679
616
}
680
617
681
- private static DomainWatcher createDomainWatcher (String namespace , String initialResourceVersion ) {
682
- return DomainWatcher .create (factory , namespace , initialResourceVersion , Main ::dispatchDomainWatch , stopping );
683
- }
684
-
685
618
private static EventWatcher createEventWatcher (String namespace , String initialResourceVersion ) {
686
619
return EventWatcher .create (factory , namespace , READINESS_PROBE_FAILURE_EVENT_FILTER , initialResourceVersion ,
687
620
Main ::dispatchEventWatch , stopping );
@@ -958,7 +891,7 @@ private static String getOperatorNamespace() {
958
891
private static class V1beta1IngressListResponseStep extends ResponseStep <V1beta1IngressList > {
959
892
private final String ns ;
960
893
961
- public V1beta1IngressListResponseStep (Step domainList , String ns ) {
894
+ V1beta1IngressListResponseStep (Step domainList , String ns ) {
962
895
super (domainList );
963
896
this .ns = ns ;
964
897
}
@@ -998,10 +931,10 @@ public NextAction onSuccess(Packet packet, V1beta1IngressList result, int status
998
931
private static class V1ServiceListResponseStep extends ResponseStep <V1ServiceList > {
999
932
private final String ns ;
1000
933
1001
- public V1ServiceListResponseStep (String ns , V1beta1IngressListResponseStep ingressListResponseStep ) {
1002
- super (Main .callBuilderFactory .create (). with ( $ -> {
1003
- $ .labelSelector = LabelConstants .DOMAINUID_LABEL + "," + LabelConstants .CREATEDBYOPERATOR_LABEL ;
1004
- }) .listIngressAsync (ns , ingressListResponseStep ));
934
+ V1ServiceListResponseStep (String ns , V1beta1IngressListResponseStep ingressListResponseStep ) {
935
+ super (Main .callBuilderFactory .create ()
936
+ . with ( $ -> $ .labelSelector = LabelConstants .DOMAINUID_LABEL + "," + LabelConstants .CREATEDBYOPERATOR_LABEL )
937
+ .listIngressAsync (ns , ingressListResponseStep ));
1005
938
this .ns = ns ;
1006
939
}
1007
940
@@ -1046,10 +979,10 @@ public NextAction onSuccess(Packet packet, V1ServiceList result, int statusCode,
1046
979
private static class V1EventListResponseStep extends ResponseStep <V1EventList > {
1047
980
private final String ns ;
1048
981
1049
- public V1EventListResponseStep (String ns , V1ServiceListResponseStep serviceListResponseStep ) {
1050
- super (Main .callBuilderFactory .create (). with ( $ -> {
1051
- $ .labelSelector = LabelConstants .DOMAINUID_LABEL + "," + LabelConstants .CREATEDBYOPERATOR_LABEL ;
1052
- }) .listServiceAsync (ns , serviceListResponseStep ));
982
+ V1EventListResponseStep (String ns , V1ServiceListResponseStep serviceListResponseStep ) {
983
+ super (Main .callBuilderFactory .create ()
984
+ . with ( $ -> $ .labelSelector = LabelConstants .DOMAINUID_LABEL + "," + LabelConstants .CREATEDBYOPERATOR_LABEL )
985
+ .listServiceAsync (ns , serviceListResponseStep ));
1053
986
this .ns = ns ;
1054
987
}
1055
988
@@ -1079,10 +1012,10 @@ public NextAction onSuccess(Packet packet, V1EventList result, int statusCode,
1079
1012
private static class V1PodListResponseStep extends ResponseStep <V1PodList > {
1080
1013
private final String ns ;
1081
1014
1082
- public V1PodListResponseStep (String ns , V1EventListResponseStep eventListResponseStep ) {
1083
- super (Main .callBuilderFactory .create (). with ( $ -> {
1084
- $ .fieldSelector = Main .READINESS_PROBE_FAILURE_EVENT_FILTER ;
1085
- }) .listEventAsync (ns , eventListResponseStep ));
1015
+ V1PodListResponseStep (String ns , V1EventListResponseStep eventListResponseStep ) {
1016
+ super (Main .callBuilderFactory .create ()
1017
+ . with ( $ -> $ .fieldSelector = Main .READINESS_PROBE_FAILURE_EVENT_FILTER )
1018
+ .listEventAsync (ns , eventListResponseStep ));
1086
1019
this .ns = ns ;
1087
1020
}
1088
1021
@@ -1122,7 +1055,7 @@ public NextAction onSuccess(Packet packet, V1PodList result, int statusCode,
1122
1055
private static class ExistingDomainListResponseStep extends ResponseStep <DomainList > {
1123
1056
private final String ns ;
1124
1057
1125
- public ExistingDomainListResponseStep (String ns ) {
1058
+ ExistingDomainListResponseStep (String ns ) {
1126
1059
super (null );
1127
1060
this .ns = ns ;
1128
1061
}
@@ -1137,18 +1070,23 @@ public NextAction onFailure(Packet packet, ApiException e, int statusCode,
1137
1070
}
1138
1071
1139
1072
@ Override
1140
- public NextAction onSuccess (Packet packet , DomainList result , int statusCode ,
1141
- Map <String , List <String >> responseHeaders ) {
1073
+ public NextAction onSuccess (Packet packet , DomainList result , int statusCode , Map <String , List <String >> responseHeaders ) {
1142
1074
if (result != null ) {
1143
1075
for (Domain dom : result .getItems ()) {
1144
1076
doCheckAndCreateDomainPresence (dom );
1145
1077
}
1146
1078
}
1147
1079
1148
- // main logic now happens in the watch handlers
1149
- domainWatchers .put (ns ,
1150
- createDomainWatcher (ns , result != null ? result .getMetadata ().getResourceVersion () : "" ));
1080
+ domainWatchers .put (ns , createDomainWatcher (ns , getResourceVersion (result )));
1151
1081
return doNext (packet );
1152
1082
}
1083
+
1084
+ String getResourceVersion (DomainList result ) {
1085
+ return result != null ? result .getMetadata ().getResourceVersion () : "" ;
1086
+ }
1087
+
1088
+ private static DomainWatcher createDomainWatcher (String namespace , String initialResourceVersion ) {
1089
+ return DomainWatcher .create (factory , namespace , initialResourceVersion , Main ::dispatchDomainWatch , stopping );
1090
+ }
1153
1091
}
1154
1092
}
0 commit comments