57
57
import oracle .kubernetes .operator .work .NextAction ;
58
58
import oracle .kubernetes .operator .work .Packet ;
59
59
import oracle .kubernetes .operator .work .Step ;
60
- import oracle .kubernetes .weblogic .domain .model .Configuration ;
61
60
import oracle .kubernetes .weblogic .domain .model .Domain ;
62
- import oracle .kubernetes .weblogic .domain .model .DomainCondition ;
63
- import oracle .kubernetes .weblogic .domain .model .DomainConditionType ;
64
- import oracle .kubernetes .weblogic .domain .model .DomainSpec ;
65
61
import oracle .kubernetes .weblogic .domain .model .DomainStatus ;
66
- import oracle .kubernetes .weblogic .domain .model .Model ;
67
- import oracle .kubernetes .weblogic .domain .model .OnlineUpdate ;
68
62
import oracle .kubernetes .weblogic .domain .model .ServerEnvVars ;
69
63
import oracle .kubernetes .weblogic .domain .model .ServerSpec ;
70
64
import oracle .kubernetes .weblogic .domain .model .Shutdown ;
73
67
import static oracle .kubernetes .operator .IntrospectorConfigMapConstants .NUM_CONFIG_MAPS ;
74
68
import static oracle .kubernetes .operator .LabelConstants .INTROSPECTION_STATE_LABEL ;
75
69
import static oracle .kubernetes .operator .LabelConstants .MII_UPDATED_RESTART_REQUIRED_LABEL ;
76
- import static oracle .kubernetes .operator .logging .MessageKeys .MII_DOMAIN_DYNAMICALLY_UPDATED ;
70
+ import static oracle .kubernetes .operator .LabelConstants .MODEL_IN_IMAGE_DOMAINZIP_HASH ;
71
+ import static oracle .kubernetes .operator .ProcessingConstants .MII_DYNAMIC_UPDATE_SUCCESS ;
77
72
78
73
public abstract class PodStepContext extends BasePodStepContext {
79
74
@@ -94,6 +89,7 @@ public abstract class PodStepContext extends BasePodStepContext {
94
89
private final String miiModelSecretsHash ;
95
90
private final String miiDomainZipHash ;
96
91
private final String domainRestartVersion ;
92
+ private boolean addRestartRequiredLabel ;
97
93
98
94
PodStepContext (Step conflictStep , Packet packet ) {
99
95
super (packet .getSpi (DomainPresenceInfo .class ));
@@ -379,10 +375,6 @@ private Step patchCurrentPod(V1Pod currentPod, Step next) {
379
375
return createProgressingStep (patchPod (currentPod , next ));
380
376
}
381
377
382
- private Step patchRunningPod (V1Pod currentPod , V1Pod updatedPod , Step next , boolean addRestartRequiredLabel ) {
383
- return createProgressingStep (patchPod (currentPod , updatedPod , next , addRestartRequiredLabel ));
384
- }
385
-
386
378
protected Step patchPod (V1Pod currentPod , Step next ) {
387
379
JsonPatchBuilder patchBuilder = Json .createPatchBuilder ();
388
380
KubernetesUtils .addPatches (
@@ -394,50 +386,18 @@ protected Step patchPod(V1Pod currentPod, Step next) {
394
386
new V1Patch (patchBuilder .build ().toString ()), patchResponse (next ));
395
387
}
396
388
397
- // Method for online update
398
- protected Step patchPod (V1Pod currentPod , V1Pod updatedPod , Step next , boolean addRestartRequiredLabel ) {
399
- JsonPatchBuilder patchBuilder = Json .createPatchBuilder ();
400
- Map <String , String > updatedLabels = Optional .ofNullable (updatedPod )
401
- .map (V1Pod ::getMetadata )
402
- .map (V1ObjectMeta ::getLabels )
403
- .orElse (null );
404
-
405
- Map <String , String > updatedAnnotations = Optional .ofNullable (updatedPod )
406
- .map (V1Pod ::getMetadata )
407
- .map (V1ObjectMeta ::getAnnotations )
408
- .orElse (null );
409
- if (updatedLabels != null ) {
410
- String introspectVersion = Optional .ofNullable (info )
411
- .map (DomainPresenceInfo ::getDomain )
412
- .map (Domain ::getSpec )
413
- .map (DomainSpec ::getIntrospectVersion )
414
- .orElse (null );
415
- if (introspectVersion != null ) {
416
- updatedLabels .put (INTROSPECTION_STATE_LABEL , introspectVersion );
417
- if (addRestartRequiredLabel ) {
418
- updatedLabels .put (MII_UPDATED_RESTART_REQUIRED_LABEL , "true" );
419
- }
420
- }
421
-
422
- KubernetesUtils .addPatches (
423
- patchBuilder , "/metadata/labels/" , getLabels (currentPod ), updatedLabels );
424
- }
425
- if (updatedAnnotations != null ) {
426
- KubernetesUtils .addPatches (
427
- patchBuilder , "/metadata/annotations/" , getAnnotations (currentPod ),
428
- updatedAnnotations );
429
- }
430
- return new CallBuilder ()
431
- .patchPodAsync (getPodName (), getNamespace (), getDomainUid (),
432
- new V1Patch (patchBuilder .build ().toString ()), patchResponse (next ));
433
- }
434
-
435
389
private Map <String , String > getNonHashedPodLabels () {
436
390
Map <String ,String > result = new HashMap <>(getPodLabels ());
391
+ Optional .ofNullable (miiDomainZipHash )
392
+ .ifPresent (h -> result .put (MODEL_IN_IMAGE_DOMAINZIP_HASH , formatHashLabel (h )));
437
393
438
394
Optional .ofNullable (getDomain ().getSpec ().getIntrospectVersion ())
439
395
.ifPresent (version -> result .put (INTROSPECTION_STATE_LABEL , version ));
440
396
397
+ if (addRestartRequiredLabel ) {
398
+ result .put (MII_UPDATED_RESTART_REQUIRED_LABEL , "true" );
399
+ }
400
+
441
401
return result ;
442
402
}
443
403
@@ -485,7 +445,8 @@ private boolean mustPatchPod(V1Pod currentPod) {
485
445
private boolean canUseCurrentPod (V1Pod currentPod ) {
486
446
487
447
boolean useCurrent =
488
- AnnotationHelper .getHash (getPodModel ()).equals (AnnotationHelper .getHash (currentPod ));
448
+ AnnotationHelper .getHash (getPodModel ()).equals (AnnotationHelper .getHash (currentPod ))
449
+ && canUseNewDomainZip (currentPod );
489
450
490
451
if (!useCurrent && AnnotationHelper .getDebugString (currentPod ).length () > 0 ) {
491
452
LOGGER .fine (
@@ -497,6 +458,28 @@ private boolean canUseCurrentPod(V1Pod currentPod) {
497
458
return useCurrent ;
498
459
}
499
460
461
+ private boolean canUseNewDomainZip (V1Pod currentPod ) {
462
+ String dynamicUpdateResult = packet .getValue (ProcessingConstants .MII_DYNAMIC_UPDATE );
463
+
464
+ if (miiDomainZipHash == null || isDomainZipUnchanged (currentPod )) {
465
+ return true ;
466
+ } else if (dynamicUpdateResult == null ) {
467
+ return false ;
468
+ } else if (dynamicUpdateResult .equals (MII_DYNAMIC_UPDATE_SUCCESS )) {
469
+ return true ;
470
+ } else if (getDomain ().getMiiNonDynamicChangesMethod () == MIINonDynamicChangesMethod .CommitUpdateOnly ) {
471
+ addRestartRequiredLabel = true ;
472
+ return true ;
473
+ } else {
474
+ return false ;
475
+ }
476
+ }
477
+
478
+ private boolean isDomainZipUnchanged (V1Pod currentPod ) {
479
+ return formatHashLabel (miiDomainZipHash )
480
+ .equals (currentPod .getMetadata ().getLabels ().get (MODEL_IN_IMAGE_DOMAINZIP_HASH ));
481
+ }
482
+
500
483
private String getReasonToRecycle (V1Pod currentPod ) {
501
484
PodCompatibility compatibility = new PodCompatibility (getPodModel (), currentPod );
502
485
return compatibility .getIncompatibility ();
@@ -540,6 +523,8 @@ V1Pod withNonHashedElements(V1Pod pod) {
540
523
getPodAnnotations ().entrySet ().stream ()
541
524
.filter (PodStepContext ::isPatchableItem )
542
525
.forEach (e -> metadata .putAnnotationsItem (e .getKey (), e .getValue ()));
526
+ Optional .ofNullable (miiDomainZipHash )
527
+ .ifPresent (hash -> addHashLabel (metadata , LabelConstants .MODEL_IN_IMAGE_DOMAINZIP_HASH , hash ));
543
528
544
529
setTerminationGracePeriod (pod );
545
530
getContainer (pod ).map (V1Container ::getEnv ).ifPresent (this ::updateEnv );
@@ -625,8 +610,6 @@ LabelConstants.CLUSTERRESTARTVERSION_LABEL, getServerSpec().getClusterRestartVer
625
610
.putLabelsItem (
626
611
LabelConstants .SERVERRESTARTVERSION_LABEL , getServerSpec ().getServerRestartVersion ());
627
612
628
- Optional .ofNullable (miiDomainZipHash )
629
- .ifPresent (hash -> addHashLabel (metadata , LabelConstants .MODEL_IN_IMAGE_DOMAINZIP_HASH , hash ));
630
613
Optional .ofNullable (miiModelSecretsHash )
631
614
.ifPresent (hash -> addHashLabel (metadata , LabelConstants .MODEL_IN_IMAGE_MODEL_SECRETS_HASH , hash ));
632
615
return metadata ;
@@ -915,50 +898,14 @@ private class VerifyPodStep extends BaseStep {
915
898
public NextAction apply (Packet packet ) {
916
899
V1Pod currentPod = info .getServerPod (getServerName ());
917
900
// reset introspect failure job count - if any
918
-
919
901
Optional .ofNullable (packet .getSpi (DomainPresenceInfo .class ))
920
902
.map (DomainPresenceInfo ::getDomain )
921
903
.map (Domain ::getStatus )
922
904
.ifPresent (DomainStatus ::resetIntrospectJobFailureCount );
923
905
924
- String dynamicUpdateResult = Optional .ofNullable ((String )packet .get (ProcessingConstants .MII_DYNAMIC_UPDATE ))
925
- .orElse (null );
926
-
927
906
if (currentPod == null ) {
928
907
return doNext (createNewPod (getNext ()), packet );
929
908
} else if (!canUseCurrentPod (currentPod )) {
930
- if (shouldNotRestartAfterOnlineUpdate (dynamicUpdateResult )) {
931
- Map <String , String > labels = Optional .of (currentPod )
932
- .map (V1Pod ::getMetadata )
933
- .map (V1ObjectMeta ::getLabels )
934
- .orElse (new HashMap <>());
935
- String serverName = "" ;
936
- if (labels .containsKey (LabelConstants .SERVERNAME_LABEL )) {
937
- serverName = labels .get (LabelConstants .SERVERNAME_LABEL );
938
- }
939
- LOGGER .fine (MII_DOMAIN_DYNAMICALLY_UPDATED , info .getDomain ().getDomainUid (), serverName );
940
- logPodExists ();
941
- //Create dummy meta data for patching
942
- V1Pod updatedPod = AnnotationHelper .withSha256Hash (createPodRecipe ());
943
- V1ObjectMeta updatedMetaData = new V1ObjectMeta ();
944
-
945
- updatedMetaData .putAnnotationsItem ("weblogic.sha256" ,
946
- updatedPod .getMetadata ().getAnnotations ().get ("weblogic.sha256" ));
947
- if (miiDomainZipHash != null ) {
948
- updatedMetaData .putLabelsItem (LabelConstants .MODEL_IN_IMAGE_DOMAINZIP_HASH ,
949
- formatHashLabel (miiDomainZipHash ));
950
- }
951
- updatedPod .setMetadata (updatedMetaData );
952
- boolean addRestartRequiredLabel = false ;
953
- // if the introspector job tells it needs restart, update the condition with the needed attributes
954
- if (ProcessingConstants .MII_DYNAMIC_UPDATE_RESTART_REQUIRED .equals (dynamicUpdateResult )) {
955
- setOnlineUpdateNeedRestartCondition (packet );
956
- addRestartRequiredLabel = true ;
957
- } else {
958
- setOnlineUpdateSuccessCondition ();
959
- }
960
- return doNext (patchRunningPod (currentPod , updatedPod , getNext (), addRestartRequiredLabel ), packet );
961
- }
962
909
LOGGER .info (
963
910
MessageKeys .CYCLING_POD ,
964
911
Objects .requireNonNull (currentPod .getMetadata ()).getName (),
@@ -971,64 +918,6 @@ public NextAction apply(Packet packet) {
971
918
return doNext (packet );
972
919
}
973
920
}
974
-
975
- private boolean shouldNotRestartAfterOnlineUpdate (String dynamicUpdateResult ) {
976
- boolean result = false ;
977
- if (ProcessingConstants .MII_DYNAMIC_UPDATE_SUCCESS .equals (dynamicUpdateResult )) {
978
- result = true ;
979
- } else if (ProcessingConstants .MII_DYNAMIC_UPDATE_RESTART_REQUIRED .equals (dynamicUpdateResult )) {
980
- result = MIINonDynamicChangesMethod .CommitUpdateOnly .equals (
981
- Optional .ofNullable (info )
982
- .map (DomainPresenceInfo ::getDomain )
983
- .map (Domain ::getSpec )
984
- .map (DomainSpec ::getConfiguration )
985
- .map (Configuration ::getModel )
986
- .map (Model ::getOnlineUpdate )
987
- .map (OnlineUpdate ::getOnNonDynamicChanges )
988
- .orElse (MIINonDynamicChangesMethod .CommitUpdateOnly ));
989
- }
990
- return result ;
991
- }
992
-
993
- private void setOnlineUpdateNeedRestartCondition (Packet packet ) {
994
- String dynamicUpdateRollBackFile = Optional .ofNullable ((String )packet .get (
995
- ProcessingConstants .MII_DYNAMIC_UPDATE_WDTROLLBACKFILE ))
996
- .orElse ("" );
997
- String message = String .format ("%s\n %s" ,
998
- LOGGER .formatMessage (MessageKeys .MII_DOMAIN_UPDATED_POD_RESTART_REQUIRED ), dynamicUpdateRollBackFile );
999
- updateDomainConditions (message , DomainConditionType .ConfigChangesPendingRestart );
1000
- }
1001
-
1002
- private void setOnlineUpdateSuccessCondition () {
1003
- // updateDomainConditions("Online update successful. No restart necessary",
1004
- // DomainConditionType.OnlineUpdateComplete);
1005
- }
1006
-
1007
- @ SuppressWarnings ("SameParameterValue" )
1008
- private void updateDomainConditions (String message , DomainConditionType domainSourceType ) {
1009
- DomainCondition onlineUpdateCondition = new DomainCondition (domainSourceType );
1010
- String introspectVersion = Optional .ofNullable (info )
1011
- .map (DomainPresenceInfo ::getDomain )
1012
- .map (Domain ::getSpec )
1013
- .map (DomainSpec ::getIntrospectVersion )
1014
- .orElse ("" );
1015
-
1016
- onlineUpdateCondition
1017
- .withMessage (message )
1018
- .withReason ("Online update applied, introspectVersion updated to " + introspectVersion )
1019
- .withStatus ("True" );
1020
-
1021
- Optional .ofNullable (info )
1022
- .map (DomainPresenceInfo ::getDomain )
1023
- .map (Domain ::getStatus )
1024
- .ifPresent (o -> o .removeConditionIf (c -> c .getType () == DomainConditionType .ConfigChangesPendingRestart ));
1025
-
1026
- Optional .ofNullable (info )
1027
- .map (DomainPresenceInfo ::getDomain )
1028
- .map (Domain ::getStatus )
1029
- .ifPresent (o -> o .addCondition (onlineUpdateCondition ));
1030
- }
1031
-
1032
921
}
1033
922
1034
923
private abstract class BaseResponseStep extends ResponseStep <V1Pod > {
0 commit comments