@@ -403,7 +403,7 @@ func (r *DataguardBrokerReconciler) setupDataguardBrokerConfiguration(m *dbapi.D
403
403
404
404
// Update Databases
405
405
r .updateReconcileStatus (m , sidbReadyPod , ctx , req )
406
- }
406
+ }
407
407
408
408
eventReason := "DG Configuration up to date"
409
409
eventMsg := ""
@@ -657,26 +657,28 @@ func (r *DataguardBrokerReconciler) setupDataguardBrokerConfigurationForGivenDB(
657
657
}
658
658
659
659
// ## SET PROPERTY FASTSTARTFAILOVERTARGET FOR EACH DATABASE TO ALL OTHER DATABASES IN DG CONFIG .
660
- for i := 0 ; i < len (databases ); i ++ {
661
- out , err = dbcommons .ExecCommand (r , r .Config , standbyDatabaseReadyPod .Name , standbyDatabaseReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
662
- fmt .Sprintf ("dgmgrl sys@%s \" EDIT DATABASE %s SET PROPERTY FASTSTARTFAILOVERTARGET=%s\" < admin.pwd" , primaryConnectString ,
663
- strings .Split (databases [i ], ":" )[0 ], getFSFOTargets (i , databases )))
664
- if err != nil {
665
- log .Error (err , err .Error ())
666
- return requeueY
667
- }
668
- log .Info ("SETTING FSFO TARGET OUTPUT" )
669
- log .Info (out )
660
+ if (m .Spec .FastStartFailOver .Enable == true ){
661
+ for i := 0 ; i < len (databases ); i ++ {
662
+ out , err = dbcommons .ExecCommand (r , r .Config , standbyDatabaseReadyPod .Name , standbyDatabaseReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
663
+ fmt .Sprintf ("dgmgrl sys@%s \" EDIT DATABASE %s SET PROPERTY FASTSTARTFAILOVERTARGET=%s\" < admin.pwd" , primaryConnectString ,
664
+ strings .Split (databases [i ], ":" )[0 ], getFSFOTargets (i , databases )))
665
+ if err != nil {
666
+ log .Error (err , err .Error ())
667
+ return requeueY
668
+ }
669
+ log .Info ("SETTING FSFO TARGET OUTPUT" )
670
+ log .Info (out )
670
671
671
- out , err = dbcommons .ExecCommand (r , r .Config , standbyDatabaseReadyPod .Name , standbyDatabaseReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
672
- fmt .Sprintf ("dgmgrl sys@%s \" SHOW DATABASE %s FASTSTARTFAILOVERTARGET\" < admin.pwd" , primaryConnectString , strings .Split (databases [i ], ":" )[0 ]))
673
- if err != nil {
674
- log .Error (err , err .Error ())
675
- return requeueY
676
- }
677
- log .Info ("FSFO TARGETS OF " + databases [i ])
678
- log .Info (out )
672
+ out , err = dbcommons .ExecCommand (r , r .Config , standbyDatabaseReadyPod .Name , standbyDatabaseReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
673
+ fmt .Sprintf ("dgmgrl sys@%s \" SHOW DATABASE %s FASTSTARTFAILOVERTARGET\" < admin.pwd" , primaryConnectString , strings .Split (databases [i ], ":" )[0 ]))
674
+ if err != nil {
675
+ log .Error (err , err .Error ())
676
+ return requeueY
677
+ }
678
+ log .Info ("FSFO TARGETS OF " + databases [i ])
679
+ log .Info (out )
679
680
681
+ }
680
682
}
681
683
// Remove admin pwd file
682
684
_ , err = dbcommons .ExecCommand (r , r .Config , standbyDatabaseReadyPod .Name , standbyDatabaseReadyPod .Namespace , "" , ctx , req , true , "bash" , "-c" ,
@@ -694,6 +696,59 @@ func (r *DataguardBrokerReconciler) setupDataguardBrokerConfigurationForGivenDB(
694
696
return requeueN
695
697
}
696
698
699
+ // #############################################################################
700
+ //
701
+ // Remove up DG Configuration for a given StandbyDatabase - To be Tested
702
+ //
703
+ // #############################################################################
704
+ func (r * DataguardBrokerReconciler ) removeDataguardBrokerConfigurationForGivenDB ( m * dbapi.DataguardBroker ,n * dbapi.SingleInstanceDatabase ,standbyDatabase * dbapi.SingleInstanceDatabase , standbyDatabaseReadyPod corev1.Pod , sidbReadyPod corev1.Pod , ctx context.Context , req ctrl.Request ) ctrl.Result {
705
+ log := r .Log .WithValues ("removeDataguardBrokerConfigurationForGivenDB" , req .NamespacedName )
706
+
707
+ if standbyDatabaseReadyPod .Name == "" || sidbReadyPod .Name == "" {
708
+ return requeueY
709
+ }
710
+
711
+ // ## CHECK IF DG CONFIGURATION IS AVAILABLE IN PRIMARY DATABASE ##
712
+ out , err := dbcommons .ExecCommand (r , r .Config , sidbReadyPod .Name , sidbReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
713
+ fmt .Sprintf ("echo -e \" %s\" | dgmgrl / as sysdba" , dbcommons .DBShowConfigCMD ))
714
+
715
+ if err != nil {
716
+ log .Error (err , err .Error ())
717
+ return requeueY
718
+ }
719
+ log .Info ("Showconfiguration Output" )
720
+ log .Info (out )
721
+
722
+ if strings .Contains (out , "ORA-16525" ) {
723
+ log .Info ("ORA-16525: The Oracle Data Guard broker is not yet available on Primary" )
724
+ return requeueY
725
+ }
726
+
727
+ // ## REMOVING STANDBY DATABASE FROM DG CONFIGURATION ##
728
+ out , err = dbcommons .ExecCommand (r , r .Config , sidbReadyPod .Name , sidbReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
729
+ fmt .Sprintf (dbcommons .CreateDGMGRLScriptFile , dbcommons .RemoveStandbyDBFromDGConfgCMD ))
730
+
731
+ if err != nil {
732
+ log .Error (err , err .Error ())
733
+ return requeueY
734
+ }
735
+
736
+ // ## SHOW CONFIGURATION
737
+ out , err = dbcommons .ExecCommand (r , r .Config , sidbReadyPod .Name , sidbReadyPod .Namespace , "" , ctx , req , false , "bash" , "-c" ,
738
+ fmt .Sprintf ("echo -e \" %s\" | dgmgrl / as sysdba" , dbcommons .DBShowConfigCMD ))
739
+ if err != nil {
740
+ log .Error (err , err .Error ())
741
+ return requeueY
742
+ }
743
+ log .Info ("Showconfiguration Output" )
744
+ log .Info (out )
745
+ // Set DG Configured status to false for this standbyDatabase. so that in next reconcilation, we dont configure this again
746
+ standbyDatabase .Status .DgBrokerConfigured = false
747
+ r .Status ().Update (ctx , standbyDatabase )
748
+
749
+ return requeueN
750
+ }
751
+
697
752
// #############################################################################
698
753
//
699
754
// Return FSFO targets of each StandbyDatabase
@@ -976,6 +1031,33 @@ func (r *DataguardBrokerReconciler) manageDataguardBrokerDeletion(req ctrl.Reque
976
1031
// indicated by the deletion timestamp being set.
977
1032
isDataguardBrokerMarkedToBeDeleted := m .GetDeletionTimestamp () != nil
978
1033
if isDataguardBrokerMarkedToBeDeleted {
1034
+
1035
+ // Make a singleinstancedatabase with empty
1036
+ singleInstanceDatabase := & dbapi.SingleInstanceDatabase {}
1037
+ err := r .Get (ctx , types.NamespacedName {Namespace : req .Namespace , Name : m .Spec .PrimaryDatabaseRef }, singleInstanceDatabase )
1038
+ if err != nil {
1039
+ log .Error (err ,err .Error ())
1040
+ return requeueY ,err
1041
+ }
1042
+ // Get its POD
1043
+ // Validate if Primary Database Reference is ready
1044
+ result , sidbReadyPod , _ := r .validateSidbReadiness (m , singleInstanceDatabase , ctx , req )
1045
+ if result .Requeue {
1046
+ log .Info ("Reconcile queued" )
1047
+ return result , nil
1048
+ }
1049
+ // Get its Role
1050
+ out , err := dbcommons .GetDatabaseRole (sidbReadyPod , r , r .Config , ctx , req , singleInstanceDatabase .Spec .Edition )
1051
+ // check if its PRIMARY
1052
+ if strings .ToUpper (out ) != "PRIMARY" {
1053
+ eventReason := "Deletion"
1054
+ eventMsg := "DataGuard Broker cannot be deleted since primaryDatabaseRef is not in PRIMARY role"
1055
+ log .Info ("DataGuard Broker cannot be deleted since primaryDatabaseRef is not in PRIMARY role" )
1056
+ r .Recorder .Eventf (m , corev1 .EventTypeWarning , eventReason , eventMsg )
1057
+ return requeueN , nil
1058
+ }
1059
+ // if not PRIMARY throw error and log it
1060
+
979
1061
if controllerutil .ContainsFinalizer (m , dataguardBrokerFinalizer ) {
980
1062
// Run finalization logic for dataguardBrokerFinalizer. If the
981
1063
// finalization logic fails, don't remove the finalizer so
0 commit comments