Skip to content

Commit

Permalink
Redesign DR commands to be more meaningful (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
posriniv authored Nov 14, 2024
1 parent 0bbbe97 commit f9afb9f
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 92 deletions.
33 changes: 33 additions & 0 deletions cmd/dr/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to Yugabyte, Inc. under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership. Yugabyte
// licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package config

import (
"github.com/spf13/cobra"
)

var ConfigCmd = &cobra.Command{
Use: "config",
Short: "Manage DR config",
Long: "Manage DR config",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
ConfigCmd.AddCommand()
}
22 changes: 11 additions & 11 deletions cmd/dr/create_dr.go → cmd/dr/config/create_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// specific language governing permissions and limitations
// under the License.

package dr
package config

import (
"fmt"
Expand All @@ -39,9 +39,9 @@ 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")
drName, _ := cmd.Flags().GetString("name")
sourceClusterName, _ := cmd.Flags().GetString("source-cluster")
targetClusterName, _ := cmd.Flags().GetString("target-cluster")
databases, _ := cmd.Flags().GetStringArray("databases")
sourceClusterId, err := authApi.GetClusterIdByName(sourceClusterName)
if err != nil {
Expand Down Expand Up @@ -111,13 +111,13 @@ var createDrCmd = &cobra.Command{
}

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] Source 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")
ConfigCmd.AddCommand(createDrCmd)
createDrCmd.Flags().String("name", "", "[REQUIRED] Name of the DR configuration.")
createDrCmd.MarkFlagRequired("name")
createDrCmd.Flags().String("source-cluster", "", "[REQUIRED] Source cluster in the DR configuration.")
createDrCmd.MarkFlagRequired("source-cluster")
createDrCmd.Flags().String("target-cluster", "", "[REQUIRED] Target cluster in the DR configuration.")
createDrCmd.MarkFlagRequired("target-cluster")
createDrCmd.Flags().StringArray("databases", []string{}, "[REQUIRED] Databases to be replicated. Please provide a comma separated list of database names <db-name-1>,<db-name-2>.")
createDrCmd.MarkFlagRequired("databases")
}
12 changes: 6 additions & 6 deletions cmd/dr/delete_dr.go → cmd/dr/config/delete_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// specific language governing permissions and limitations
// under the License.

package dr
package config

import (
"fmt"
Expand All @@ -33,7 +33,7 @@ var deleteDrCmd = &cobra.Command{
Long: `Delete DR`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("force", cmd.Flags().Lookup("force"))
drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
msg := fmt.Sprintf("Are you sure you want to delete dr: %s", drName)
err := util.ConfirmCommand(msg, viper.GetBool("force"))
if err != nil {
Expand All @@ -47,7 +47,7 @@ var deleteDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
if err != nil {
logrus.Fatal(err)
}
Expand Down Expand Up @@ -82,8 +82,8 @@ var deleteDrCmd = &cobra.Command{
}

func init() {
DrCmd.AddCommand(deleteDrCmd)
deleteDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration")
deleteDrCmd.MarkFlagRequired("dr-name")
ConfigCmd.AddCommand(deleteDrCmd)
deleteDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration")
deleteDrCmd.MarkFlagRequired("config")

}
10 changes: 5 additions & 5 deletions cmd/dr/describe_dr.go → cmd/dr/config/describe_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// specific language governing permissions and limitations
// under the License.

package dr
package config

import (
"os"
Expand All @@ -37,7 +37,7 @@ var describeDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
Expand All @@ -63,7 +63,7 @@ var describeDrCmd = &cobra.Command{
}

func init() {
DrCmd.AddCommand(describeDrCmd)
describeDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
describeDrCmd.MarkFlagRequired("dr-name")
ConfigCmd.AddCommand(describeDrCmd)
describeDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
describeDrCmd.MarkFlagRequired("config")
}
4 changes: 2 additions & 2 deletions cmd/dr/list_dr.go → cmd/dr/config/list_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// specific language governing permissions and limitations
// under the License.

package dr
package config

import (
"fmt"
Expand Down Expand Up @@ -59,5 +59,5 @@ var listDrCmd = &cobra.Command{
}

func init() {
DrCmd.AddCommand(listDrCmd)
ConfigCmd.AddCommand(listDrCmd)
}
10 changes: 5 additions & 5 deletions cmd/dr/update_dr.go → cmd/dr/config/update_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// specific language governing permissions and limitations
// under the License.

package dr
package config

import (
"fmt"
Expand All @@ -39,7 +39,7 @@ var updateDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
databases, _ := cmd.Flags().GetStringArray("databases")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
Expand Down Expand Up @@ -110,9 +110,9 @@ var updateDrCmd = &cobra.Command{
}

func init() {
DrCmd.AddCommand(updateDrCmd)
updateDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
updateDrCmd.MarkFlagRequired("dr-name")
ConfigCmd.AddCommand(updateDrCmd)
updateDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
updateDrCmd.MarkFlagRequired("config")
updateDrCmd.Flags().StringArray("databases", []string{}, "[REQUIRED] Databases to be replicated. Please provide a comma separated list of database names <db-name-1>,<db-name-2>.")
updateDrCmd.MarkFlagRequired("databases")
}
3 changes: 2 additions & 1 deletion cmd/dr/dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package dr

import (
"github.com/spf13/cobra"
"github.com/yugabyte/ybm-cli/cmd/dr/config"
)

var DrCmd = &cobra.Command{
Expand All @@ -29,5 +30,5 @@ var DrCmd = &cobra.Command{
}

func init() {
DrCmd.AddCommand()
DrCmd.AddCommand(config.ConfigCmd)
}
6 changes: 3 additions & 3 deletions cmd/dr/failover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var failoverDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
safetimes, _ := cmd.Flags().GetStringArray("safetimes")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
Expand Down Expand Up @@ -125,7 +125,7 @@ var failoverDrCmd = &cobra.Command{

func init() {
DrCmd.AddCommand(failoverDrCmd)
failoverDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
failoverDrCmd.MarkFlagRequired("dr-name")
failoverDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
failoverDrCmd.MarkFlagRequired("config")
failoverDrCmd.Flags().StringArray("safetimes", []string{}, "[OPTIONAL] Safetimes of the DR configuation. Please provide key value pairs <db-name-1>=<epoch-safe-time>,<db-name-2>=<epoch-safe-time>.")
}
6 changes: 3 additions & 3 deletions cmd/dr/pause_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var pauseDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
durationInMin, _ := cmd.Flags().GetInt32("duration")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
Expand Down Expand Up @@ -90,7 +90,7 @@ var pauseDrCmd = &cobra.Command{

func init() {
DrCmd.AddCommand(pauseDrCmd)
pauseDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
pauseDrCmd.MarkFlagRequired("dr-name")
pauseDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
pauseDrCmd.MarkFlagRequired("config")
pauseDrCmd.Flags().Int32("duration", 60, "[OPTIONAL] Duration in minutes.")
}
6 changes: 3 additions & 3 deletions cmd/dr/restart_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var restartDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
databases, _ := cmd.Flags().GetStringArray("databases")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
Expand Down Expand Up @@ -111,7 +111,7 @@ var restartDrCmd = &cobra.Command{

func init() {
DrCmd.AddCommand(restartDrCmd)
restartDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
restartDrCmd.MarkFlagRequired("dr-name")
restartDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
restartDrCmd.MarkFlagRequired("config")
restartDrCmd.Flags().StringArray("databases", []string{}, "[OPTIONAL] Databases to be restarted. Please provide a comma separated list of database names <db-name-1>,<db-name-2>.")
}
6 changes: 3 additions & 3 deletions cmd/dr/resume_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var resumeDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
Expand Down Expand Up @@ -87,6 +87,6 @@ var resumeDrCmd = &cobra.Command{

func init() {
DrCmd.AddCommand(resumeDrCmd)
resumeDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
resumeDrCmd.MarkFlagRequired("dr-name")
resumeDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
resumeDrCmd.MarkFlagRequired("config")
}
6 changes: 3 additions & 3 deletions cmd/dr/switchover_dr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var switchoverDrCmd = &cobra.Command{
}
authApi.GetInfo("", "")

drName, _ := cmd.Flags().GetString("dr-name")
drName, _ := cmd.Flags().GetString("config")
if err != nil {
logrus.Fatalf("Could not get cluster data: %s", ybmAuthClient.GetApiErrorDetails(err))
}
Expand Down Expand Up @@ -87,6 +87,6 @@ var switchoverDrCmd = &cobra.Command{

func init() {
DrCmd.AddCommand(switchoverDrCmd)
switchoverDrCmd.Flags().String("dr-name", "", "[REQUIRED] Name of the DR configuration.")
switchoverDrCmd.MarkFlagRequired("dr-name")
switchoverDrCmd.Flags().String("config", "", "[REQUIRED] Name of the DR configuration.")
switchoverDrCmd.MarkFlagRequired("config")
}
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"github.com/yugabyte/ybm-cli/cmd/vpc"

"github.com/yugabyte/ybm-cli/internal/log"
"github.com/yugabyte/ybm-cli/internal/releases"
)

var (
Expand All @@ -66,7 +65,7 @@ var rootCmd = &cobra.Command{
if strings.HasPrefix(cmd.CommandPath(), "ybm completion") {
return
}
releases.PrintUpgradeMessageIfNeeded()
//releases.PrintUpgradeMessageIfNeeded()

},
}
Expand Down
6 changes: 1 addition & 5 deletions docs/ybm_dr.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ ybm dr [flags]
### SEE ALSO

* [ybm](ybm.md) - ybm - Effortlessly manage your DB infrastructure on YugabyteDB Aeon (DBaaS) from command line!
* [ybm dr create](ybm_dr_create.md) - Create DR for a cluster
* [ybm dr delete](ybm_dr_delete.md) - Delete DR
* [ybm dr describe](ybm_dr_describe.md) - Describe DR
* [ybm dr config](ybm_dr_config.md) - Manage DR config
* [ybm dr failover](ybm_dr_failover.md) - Failover DR for a cluster
* [ybm dr list](ybm_dr_list.md) - List DRs for a given cluster
* [ybm dr pause](ybm_dr_pause.md) - Pause DR for a cluster
* [ybm dr restart](ybm_dr_restart.md) - Restart DR for a cluster
* [ybm dr resume](ybm_dr_resume.md) - Resume DR for a cluster
* [ybm dr switchover](ybm_dr_switchover.md) - Switchover DR for a cluster
* [ybm dr update](ybm_dr_update.md) - Update DR for a cluster

40 changes: 40 additions & 0 deletions docs/ybm_dr_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## ybm dr config

Manage DR config

### Synopsis

Manage DR config

```
ybm dr config [flags]
```

### Options

```
-h, --help help for config
```

### Options inherited from parent commands

```
-a, --apiKey string YugabyteDB Aeon account API key
--config string config file (default is $HOME/.ybm-cli.yaml)
--debug Use debug mode, same as --logLevel debug
-l, --logLevel string Select the desired log level format(info). Default to info
--no-color Disable colors in output , default to false
-o, --output string Select the desired output format (table, json, pretty). Default to table
--timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s)
--wait Wait until the task is completed, otherwise it will exit immediately, default to false
```

### SEE ALSO

* [ybm dr](ybm_dr.md) - Manage DR for a cluster.
* [ybm dr config create](ybm_dr_config_create.md) - Create DR for a cluster
* [ybm dr config delete](ybm_dr_config_delete.md) - Delete DR
* [ybm dr config describe](ybm_dr_config_describe.md) - Describe DR
* [ybm dr config list](ybm_dr_config_list.md) - List DRs for a given cluster
* [ybm dr config update](ybm_dr_config_update.md) - Update DR for a cluster

Loading

0 comments on commit f9afb9f

Please sign in to comment.