Skip to content

Commit 41a613c

Browse files
committed
Fixing getSidPdbEdition function-2
1 parent b6fb409 commit 41a613c

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

commons/database/constants.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ const DataguardBrokerAddDBMaxAvailabilityCMD string = "ADD DATABASE ${ORACLE_SID
212212
"(CONNECT_DATA=(SERVICE_NAME=${ORACLE_SID}_DGMGRL)(INSTANCE_NAME=${ORACLE_SID})(SERVER=DEDICATED)))';" +
213213
"\nENABLE CONFIGURATION;"
214214

215-
const RemoveStandbyDBFromDGConfgCMD string = "DISABLE DATABASE ${ORACLE_SID};" +
216-
"\nREMOVE DATABASE ${ORACLE_SID};"
215+
const RemoveStandbyDBFromDGConfgCMD string = "DISABLE DATABASE ${ORACLE_SID};" +
216+
"\nREMOVE DATABASE ${ORACLE_SID};"
217217

218218
const DBShowConfigCMD string = "SHOW CONFIGURATION;"
219219

@@ -506,7 +506,7 @@ const SetApexUsers string = "\numask 177" +
506506
"\numask 022"
507507

508508
// Get Sid, Pdbname, Edition for prebuilt db
509-
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION,Edition;"
509+
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION;"
510510

511511
// Command to enable TCPS as a formatted string. The parameter would be the port at which TCPS is enabled.
512512
const EnableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE"

commons/database/utils.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,23 @@ func GetDatabaseRole(readyPod corev1.Pod, r client.Reader,
507507

508508
func GetDatabaseOpenMode(readyPod corev1.Pod, r client.Reader,
509509
config *rest.Config, ctx context.Context, req ctrl.Request, edition string) (string, error) {
510-
log := ctrllog.FromContext(ctx).WithValues("GetDatabaseOpenMode",req.NamespacedName)
510+
log := ctrllog.FromContext(ctx).WithValues("GetDatabaseOpenMode", req.NamespacedName)
511511

512-
out,err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "", ctx, req, false, "bash", "-c",
513-
fmt.Sprintf("echo -e \"%s\" | %s",GetDBOpenMode,SQLPlusCLI))
514-
if err != nil {
515-
return "",err
516-
}
517-
log.Info(out)
518-
if !strings.Contains(out, "no rows selected") && !strings.Contains(out, "ORA-") {
519-
out1 := strings.Replace(out, " ", "_", -1)
520-
// filtering output and storing databse_role in "database_role"
521-
databaseOpenMode := strings.Fields(out1)[2]
522-
// first 2 values in the slice will be column name(DATABASE_ROLE) and a seperator(--------------) .
523-
return databaseOpenMode, nil
524-
}
525-
return "", errors.New("database open mode is nil")
512+
out, err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "", ctx, req, false, "bash", "-c",
513+
fmt.Sprintf("echo -e \"%s\" | %s", GetDBOpenMode, SQLPlusCLI))
514+
if err != nil {
515+
return "", err
526516
}
517+
log.Info(out)
518+
if !strings.Contains(out, "no rows selected") && !strings.Contains(out, "ORA-") {
519+
out1 := strings.Replace(out, " ", "_", -1)
520+
// filtering output and storing databse_role in "database_role"
521+
databaseOpenMode := strings.Fields(out1)[2]
522+
// first 2 values in the slice will be column name(DATABASE_ROLE) and a seperator(--------------) .
523+
return databaseOpenMode, nil
524+
}
525+
return "", errors.New("database open mode is nil")
526+
}
527527

528528
// Returns true if any of the pod in 'pods' is with pod.Status.Phase == phase
529529
func IsAnyPodWithStatus(pods []corev1.Pod, phase corev1.PodPhase) (bool, corev1.Pod) {
@@ -590,29 +590,29 @@ func GetNodeIp(r client.Reader, ctx context.Context, req ctrl.Request) string {
590590
}
591591

592592
// GetSidPdbEdition to display sid, pdbname, edition in ConnectionString
593-
func GetSidPdbEdition(r client.Reader, config *rest.Config, ctx context.Context, req ctrl.Request) (string, string, string) {
593+
func GetSidPdbEdition(r client.Reader, config *rest.Config, ctx context.Context, req ctrl.Request) (string, string, string, error) {
594594

595-
log := ctrllog.FromContext(ctx).WithValues("GetNodeIp", req.NamespacedName)
595+
log := ctrllog.FromContext(ctx).WithValues("GetSidbPdbEdition", req.NamespacedName)
596596

597-
readyPod, _, _, _, err := FindPods(r, "", "", req.Name, req.Namespace, ctx, req)
597+
sidbReadyPod, _, _, _, err := FindPods(r, "", "", req.Name, req.Namespace, ctx, req)
598598
if err != nil {
599599
log.Error(err, err.Error())
600-
return "", "", ""
600+
return "", "", "", errors.New("error while fetching sidb ready pod for sidb " + req.Name)
601601
}
602-
if readyPod.Name != "" {
603-
out, err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "",
602+
if sidbReadyPod.Name != "" {
603+
out, err := ExecCommand(r, config, sidbReadyPod.Name, sidbReadyPod.Namespace, "",
604604
ctx, req, false, "bash", "-c", GetSidPdbEditionCMD)
605605
if err != nil {
606606
log.Error(err, err.Error())
607-
return "", "", ""
607+
return "", "", "", errors.New("error while execing GetSidPdbEditionCMD on sidb " + req.Name)
608608
}
609609
splitstr := strings.Split(out, ",")
610-
if len(splitstr) == 4 {
611-
return splitstr[0], splitstr[1], splitstr[2]
610+
if len(splitstr) == 3 {
611+
return splitstr[0], splitstr[1], splitstr[2], nil
612612
}
613613
}
614614

615-
return "", "", ""
615+
return "", "", "", errors.New("error while sidb ready pod name is nil")
616616
}
617617

618618
// Get Datapatch Status

0 commit comments

Comments
 (0)