Skip to content

Commit

Permalink
use db ids of target cluster id during failover
Browse files Browse the repository at this point in the history
  • Loading branch information
posriniv committed Nov 5, 2024
1 parent c24aca2 commit f841620
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/dr/delete_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ var deleteDrCmd = &cobra.Command{
if err != nil {
logrus.Fatal(err)
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()

r, err := authApi.DeleteXClusterDr(clusterId, drId).Execute()
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/describe_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ var describeDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()
drResp, r, err := authApi.GetXClusterDr(clusterId, drId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/failover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ var failoverDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetTargetClusterId()
namespacesResp, r, err := authApi.GetClusterNamespaces(clusterId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/pause_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ var pauseDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()

pauseDrRequest := ybmclient.NewPauseDrRequestWithDefaults()
pauseDrRequest.SetDurationMinutes(durationInMin)
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/restart_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ var restartDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()
namespacesResp, r, err := authApi.GetClusterNamespaces(clusterId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/resume_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ var resumeDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()

response, err := authApi.ResumeXClusterDr(clusterId, drId).Execute()
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/switchover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ var switchoverDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()

response, err := authApi.SwitchoverXClusterDr(clusterId, drId).Execute()
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/dr/update_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ var updateDrCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
drInfo, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
drId := drInfo.GetId()
clusterId := drInfo.GetSourceClusterId()
namespacesResp, r, err := authApi.GetClusterNamespaces(clusterId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down
6 changes: 3 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,13 @@ func (a *AuthApiClient) GetClusterIdByName(clusterName string) (string, error) {
return "", fmt.Errorf("could not get cluster data for cluster name: %s", clusterName)
}

func (a *AuthApiClient) GetDrDetailsByName(drName string) (string, string, error) {
func (a *AuthApiClient) GetDrDetailsByName(drName string) (ybmclient.XClusterDrInfo, error) {
drData, err := a.GetDrByName(drName)
if err == nil {
return drData.Info.GetId(), drData.Info.GetSourceClusterId(), nil
return drData.GetInfo(), nil
}

return "", "", fmt.Errorf("Could not get data for the DR config %s", drName)
return ybmclient.XClusterDrInfo{}, fmt.Errorf("Could not get data for the DR config %s", drName)
}

func (a *AuthApiClient) CreateCluster() ybmclient.ApiCreateClusterRequest {
Expand Down

0 comments on commit f841620

Please sign in to comment.