Skip to content

Commit

Permalink
Use db ids of target cluster id during failover (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
posriniv authored Nov 5, 2024
1 parent c24aca2 commit 0594891
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 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
7 changes: 5 additions & 2 deletions cmd/dr/failover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ 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()
sourceClusterId := drInfo.GetSourceClusterId()
clusterId := drInfo.GetTargetClusterId()
namespacesResp, r, err := authApi.GetClusterNamespaces(clusterId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down Expand Up @@ -93,7 +96,7 @@ var failoverDrCmd = &cobra.Command{
msg := fmt.Sprintf("Failover is in progress for the DR %s ", formatter.Colorize(drName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_DR_FAILOVER, []string{"FAILED", "SUCCEEDED"}, msg)
returnStatus, err := authApi.WaitForTaskCompletion(sourceClusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_DR_FAILOVER, []string{"FAILED", "SUCCEEDED"}, msg)
if err != nil {
logrus.Fatalf("error when getting task status: %s", err)
}
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 0594891

Please sign in to comment.