Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign CLI for DR to not take cluster name when not required #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cmd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/spf13/cobra"
"github.com/yugabyte/ybm-cli/cmd/cluster/cert"
connectionpooling "github.com/yugabyte/ybm-cli/cmd/cluster/connection-pooling"
dr "github.com/yugabyte/ybm-cli/cmd/cluster/dr"
encryption "github.com/yugabyte/ybm-cli/cmd/cluster/encryption"
log_exporter "github.com/yugabyte/ybm-cli/cmd/cluster/log-exporter"
"github.com/yugabyte/ybm-cli/cmd/cluster/namespace"
Expand Down Expand Up @@ -74,8 +73,4 @@ func init() {
util.AddCommandIfFeatureFlag(ClusterCmd, connectionpooling.ConnectionPoolingCmd, util.CONNECTION_POOLING)
connectionpooling.ConnectionPoolingCmd.PersistentFlags().StringVarP(&connectionpooling.ClusterName, "cluster-name", "c", "", "[REQUIRED] The name of the cluster.")
connectionpooling.ConnectionPoolingCmd.MarkPersistentFlagRequired("cluster-name")

util.AddCommandIfFeatureFlag(ClusterCmd, dr.DrCmd, util.DR)
dr.DrCmd.PersistentFlags().StringVarP(&dr.ClusterName, "cluster-name", "c", "", "[REQUIRED] The name of the cluster.")
dr.DrCmd.MarkPersistentFlagRequired("cluster-name")
}
5 changes: 4 additions & 1 deletion cmd/cluster/dr/create_dr.go → cmd/dr/create_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ var createDrCmd = &cobra.Command{
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
sourceClusterName, _ := cmd.Flags().GetString("source-cluster-name")
targetClusterName, _ := cmd.Flags().GetString("target-cluster-name")
databases, _ := cmd.Flags().GetStringArray("databases")
sourceClusterId, err := authApi.GetClusterIdByName(ClusterName)
sourceClusterId, err := authApi.GetClusterIdByName(sourceClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
Expand Down Expand Up @@ -113,6 +114,8 @@ func init() {
DrCmd.AddCommand(createDrCmd)
createDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
createDrCmd.MarkFlagRequired("dr-name")
createDrCmd.Flags().String("source-cluster-name", "", "[REQUIRED] Target cluster in the DR configuration.")
createDrCmd.MarkFlagRequired("source-cluster-name")
createDrCmd.Flags().String("target-cluster-name", "", "[REQUIRED] Target cluster in the DR configuration.")
createDrCmd.MarkFlagRequired("target-cluster-name")
createDrCmd.Flags().StringArray("databases", []string{}, "[REQUIRED] Databases to be replicated.")
Expand Down
9 changes: 4 additions & 5 deletions cmd/cluster/dr/delete_dr.go → cmd/dr/delete_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var deleteDrCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("force", cmd.Flags().Lookup("force"))
drName, _ := cmd.Flags().GetString("dr-name")
msg := fmt.Sprintf("Are you sure you want to delete dr-name: %s for cluster: %s", drName, ClusterName)
msg := fmt.Sprintf("Are you sure you want to delete dr: %s", drName)
err := util.ConfirmCommand(msg, viper.GetBool("force"))
if err != nil {
logrus.Fatal(err)
Expand All @@ -48,16 +48,15 @@ var deleteDrCmd = &cobra.Command{
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
clusterID, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatal(err)
}
drId, err := authApi.GetDrIdByName(clusterID, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}

r, err := authApi.DeleteXClusterDr(clusterID, drId).Execute()
r, err := authApi.DeleteXClusterDr(clusterId, drId).Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err))
Expand All @@ -66,7 +65,7 @@ var deleteDrCmd = &cobra.Command{
msg := fmt.Sprintf("The DR %s is being deleted", formatter.Colorize(drName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_DELETE_DR, []string{"FAILED", "SUCCEEDED"}, msg)
returnStatus, err := authApi.WaitForTaskCompletion(clusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_DELETE_DR, []string{"FAILED", "SUCCEEDED"}, msg)
if err != nil {
logrus.Fatalf("error when getting task status: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/describe_dr.go → cmd/dr/describe_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ var describeDrCmd = &cobra.Command{
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatalf("Could not get DR data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/cluster/dr/dr.go → cmd/dr/dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/spf13/cobra"
)

var ClusterName string

var DrCmd = &cobra.Command{
Use: "dr",
Short: "Manage DR for a cluster.",
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/failover_dr.go → cmd/dr/failover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ var failoverDrCmd = &cobra.Command{

drName, _ := cmd.Flags().GetString("dr-name")
safetimes, _ := cmd.Flags().GetStringArray("safetimes")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/list_dr.go → cmd/dr/list_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ var listDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatal(err)
}
resp, r, err := authApi.ListXClusterDr(clusterId).Execute()
resp, r, err := authApi.ListXClusterDr().Execute()
if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err))
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/pause_dr.go → cmd/dr/pause_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ var pauseDrCmd = &cobra.Command{

drName, _ := cmd.Flags().GetString("dr-name")
durationInMin, _ := cmd.Flags().GetInt32("duration")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/restart_dr.go → cmd/dr/restart_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ var restartDrCmd = &cobra.Command{

drName, _ := cmd.Flags().GetString("dr-name")
databases, _ := cmd.Flags().GetStringArray("databases")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/resume_dr.go → cmd/dr/resume_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ var resumeDrCmd = &cobra.Command{
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ var switchoverDrCmd = &cobra.Command{
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster/dr/update_dr.go → cmd/dr/update_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ var updateDrCmd = &cobra.Command{

drName, _ := cmd.Flags().GetString("dr-name")
databases, _ := cmd.Flags().GetStringArray("databases")
clusterId, err := authApi.GetClusterIdByName(ClusterName)
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
drId, err := authApi.GetDrIdByName(clusterId, drName)
drId, clusterId, err := authApi.GetDrDetailsByName(drName)
if err != nil {
logrus.Fatal(err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/yugabyte/ybm-cli/cmd/cdc"
"github.com/yugabyte/ybm-cli/cmd/cluster"
"github.com/yugabyte/ybm-cli/cmd/db_audit_logs_exporter"
"github.com/yugabyte/ybm-cli/cmd/dr"
"github.com/yugabyte/ybm-cli/cmd/integration"
"github.com/yugabyte/ybm-cli/cmd/metrics_exporter"
"github.com/yugabyte/ybm-cli/cmd/nal"
Expand Down Expand Up @@ -138,6 +139,7 @@ func init() {
rootCmd.AddCommand(user.UserCmd)
rootCmd.AddCommand(metrics_exporter.MetricsExporterCmd)
rootCmd.AddCommand(integration.IntegrationCmd)
util.AddCommandIfFeatureFlag(rootCmd, dr.DrCmd, util.DR)
util.AddCommandIfFeatureFlag(rootCmd, db_audit_logs_exporter.DbAuditLogsExporterCmd, util.DB_AUDIT_LOGS)
util.AddCommandIfFeatureFlag(rootCmd, tools.ToolsCmd, util.TOOLS)
util.AddCommandIfFeatureFlag(rootCmd, cdc.CdcCmd, util.CDC)
Expand Down
16 changes: 8 additions & 8 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@
return ybmclient.ClusterData{}, fmt.Errorf("could not get cluster data for cluster name: %s", clusterName)
}

func (a *AuthApiClient) GetDrByName(clusterId string, drName string) (ybmclient.XClusterDrData, error) {
drResp, resp, err := a.ListXClusterDr(clusterId).Execute()
func (a *AuthApiClient) GetDrByName(drName string) (ybmclient.XClusterDrData, error) {
drResp, resp, err := a.ListXClusterDr().Execute()
if err != nil {
b, _ := httputil.DumpResponse(resp, true)
logrus.Debug(string(b))
Expand Down Expand Up @@ -587,13 +587,13 @@
return "", fmt.Errorf("could not get cluster data for cluster name: %s", clusterName)
}

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

return "", fmt.Errorf("could not get dr data for dr name: %s", drName)
return "", "", fmt.Errorf("could not get dr data for dr name: %s", drName)
}

func (a *AuthApiClient) CreateCluster() ybmclient.ApiCreateClusterRequest {
Expand Down Expand Up @@ -1718,8 +1718,8 @@
return a.ApiClient.XclusterDrApi.GetXClusterDr(a.ctx, a.AccountID, a.ProjectID, clusterId, drId)
}

func (a *AuthApiClient) ListXClusterDr(clusterId string) ybmclient.ApiListXClusterDrRequest {
return a.ApiClient.XclusterDrApi.ListXClusterDr(a.ctx, a.AccountID, a.ProjectID, clusterId)
func (a *AuthApiClient) ListXClusterDr() ybmclient.ApiListXClusterDrRequest {
return a.ApiClient.XclusterDrApi.ListAllXClusterDrInAccount(a.ctx, a.AccountID, a.ProjectID)

Check failure on line 1722 in internal/client/client.go

View workflow job for this annotation

GitHub Actions / Build

a.ApiClient.XclusterDrApi.ListAllXClusterDrInAccount undefined (type openapi.XclusterDrApi has no field or method ListAllXClusterDrInAccount)
}

func (a *AuthApiClient) DeleteXClusterDr(clusterId string, drId string) ybmclient.ApiDeleteXClusterDrRequest {
Expand Down
Loading