Skip to content

Commit

Permalink
Waiting for a task (#41)
Browse files Browse the repository at this point in the history
* Adding Waiting task
* Display task completion percentage
* Replaces underscore with dash (#42)
* Added waiting task for cluster, backup, vpc, vcp peering
* Changed Spinner library to support multiline output
* Added Read replica waiting
* Updated timeout
* Removed commented out code for backup deletion wait.
* Fix typo
* Added waiting to NAL assignment && Fixed NAL command
* resolve conflicts

---------

Co-authored-by: Srinivas Pothuraju <[email protected]>
  • Loading branch information
Etourneau Gwenn and posriniv authored Feb 6, 2023
1 parent 79a81c7 commit 1812916
Show file tree
Hide file tree
Showing 19 changed files with 464 additions and 38 deletions.
48 changes: 44 additions & 4 deletions cmd/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ var restoreBackupCmd = &cobra.Command{
logrus.Debugf("Full HTTP response: %v", r)
return
}
fmt.Printf("The backup %v is being restored onto the cluster %v", formatter.Colorize(backupID, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR))
msg := fmt.Sprintf("Backup %v is being restored onto the cluster %v", formatter.Colorize(backupID, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "RESTORE_BACKUP", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("Backup %v has been restored onto the cluster %v\n", formatter.Colorize(backupID, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR))
return
} else {
fmt.Println(msg)
}
},
}

Expand Down Expand Up @@ -132,15 +148,39 @@ var createBackupCmd = &cobra.Command{
logrus.Debugf("Full HTTP response: %v", response)
return
}
backupID := backupResp.GetData().Info.Id

msg := fmt.Sprintf("The backup for cluster %s is being created", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(*backupID, "BACKUP", "CREATE_BACKUP", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The backup for cluster %s has been created\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

respC, r, err := authApi.GetBackup(*backupID).Execute()
if err != nil {
logrus.Errorf("Error when calling `BackupApi.ListBackups`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
backupResp = respC
} else {
fmt.Println(msg)
}

backupsCtx := formatter.Context{
Output: os.Stdout,
Format: formatter.NewBackupFormat(viper.GetString("output")),
}

formatter.BackupWrite(backupsCtx, []ybmclient.BackupData{backupResp.GetData()})

fmt.Printf("The backup for cluster %s is being created\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
},
}

Expand All @@ -165,7 +205,7 @@ var deleteBackupCmd = &cobra.Command{
return
}

fmt.Printf("Backup %s was queued for deletion.", formatter.Colorize(backupID, formatter.GREEN_COLOR))
fmt.Printf("The backup %s is being queued for deletion.\n", formatter.Colorize(backupID, formatter.GREEN_COLOR))
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var _ = Describe("Backup", func() {
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Out).Should(gbytes.Say(fmt.Sprintf(
`Created On Expire On Clusters Description State Type Retains\(day\)
%s %s proficient-parrotfish scdasfdadfasdsad SUCCEEDED MANUAL 25`, formatter.FormatDate("2023-01-17T08:31:35.818Z"), formatter.FormatDate("2023-01-17T08:31:35.818Z"))))
`ID Created On Expire On Clusters Description State Type Retains\(day\)
7d08a5c3-8097-48f0-8019-da236e876ab9 %s %s proficient-parrotfish scdasfdadfasdsad SUCCEEDED MANUAL 25`, formatter.FormatDate("2023-01-17T08:31:35.818Z"), formatter.FormatDate("2023-01-17T08:31:35.818Z"))))
session.Kill()
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/cdcstream/cdc_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var getCdcStreamCmd = &cobra.Command{
return
}

resp, r, err := authApi.GetCdcStream(clusterID, cdcStreamID).Execute()
resp, r, err := authApi.GetCdcStream(cdcStreamID, clusterID).Execute()
if err != nil {
logrus.Errorf("Error when calling `CdcApi.GetCdcStream`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
Expand Down
19 changes: 18 additions & 1 deletion cmd/cluster/assign_nal_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/formatter"
)
Expand Down Expand Up @@ -58,7 +59,23 @@ var assignClusterCmd = &cobra.Command{
return
}

fmt.Printf("The cluster %s is being assigned the network allow list %s\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))
msg := fmt.Sprintf("The cluster %s is being assigned the network allow list %s", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterId, "CLUSTER", "EDIT_ALLOW_LIST", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been assigned the network allow list %s\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))

} else {
fmt.Println(msg)
}
},
}

Expand Down
32 changes: 29 additions & 3 deletions cmd/cluster/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,40 @@ var createClusterCmd = &cobra.Command{
return
}

clusterID := resp.GetData().Info.Id
clusterData := []ybmclient.ClusterData{resp.GetData()}

msg := fmt.Sprintf("The cluster %s is being created", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "CREATE_CLUSTER", []string{"FAILED", "SUCCEEDED"}, msg, 1800)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been created\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

respC, r, err := authApi.ListClusters().Name(clusterName).Execute()
if err != nil {
logrus.Errorf("Error when calling `ClusterApi.ListClusters`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData = respC.GetData()
} else {
fmt.Println(msg)
}

clustersCtx := formatter.Context{
Output: os.Stdout,
Format: formatter.NewClusterFormat(viper.GetString("output")),
}

formatter.ClusterWrite(clustersCtx, []ybmclient.ClusterData{resp.GetData()})

fmt.Printf("The cluster %s is being created\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
formatter.ClusterWrite(clustersCtx, clusterData)
},
}

Expand Down
17 changes: 16 additions & 1 deletion cmd/cluster/delete_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/formatter"
)
Expand Down Expand Up @@ -39,8 +40,22 @@ var deleteClusterCmd = &cobra.Command{
return
}

fmt.Printf("The cluster %s is scheduled for deletion\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
msg := fmt.Sprintf("The cluster %s is being deleted", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "DELETE_CLUSTER", []string{"FAILED", "SUCCEEDED"}, msg, 1800)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been deleted\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
return
}
fmt.Println(msg)
},
}

Expand Down
31 changes: 29 additions & 2 deletions cmd/cluster/pause_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,47 @@ var pauseClusterCmd = &cobra.Command{
logrus.Error(err)
return
}

resp, r, err := authApi.PauseCluster(clusterID).Execute()
if err != nil {
logrus.Errorf("Error when calling `ClusterApi.PauseCluster`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData := []ybmclient.ClusterData{resp.GetData()}

msg := fmt.Sprintf("The cluster %s is being paused", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "PAUSE_CLUSTER", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been paused\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

respC, r, err := authApi.ListClusters().Name(clusterName).Execute()
if err != nil {
logrus.Errorf("Error when calling `ClusterApi.ListClusters`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData = respC.GetData()
} else {
fmt.Println(msg)
}

clustersCtx := formatter.Context{
Output: os.Stdout,
Format: formatter.NewClusterFormat(viper.GetString("output")),
}

formatter.ClusterWrite(clustersCtx, []ybmclient.ClusterData{resp.GetData()})
formatter.ClusterWrite(clustersCtx, clusterData)

fmt.Printf("The cluster %s is being paused\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
},
}

Expand Down
31 changes: 28 additions & 3 deletions cmd/cluster/resume_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,39 @@ var resumeClusterCmd = &cobra.Command{
return
}

clusterData := []ybmclient.ClusterData{resp.GetData()}

msg := fmt.Sprintf("The cluster %s is being resumed", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "RESUME_CLUSTER", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been resumed\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

respC, r, err := authApi.ListClusters().Name(clusterName).Execute()
if err != nil {
logrus.Errorf("Error when calling `ClusterApi.ListClusters`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData = respC.GetData()
} else {
fmt.Println(msg)
}

clustersCtx := formatter.Context{
Output: os.Stdout,
Format: formatter.NewClusterFormat(viper.GetString("output")),
}

formatter.ClusterWrite(clustersCtx, []ybmclient.ClusterData{resp.GetData()})

fmt.Printf("The cluster %s is being resumed\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
formatter.ClusterWrite(clustersCtx, clusterData)
},
}

Expand Down
21 changes: 20 additions & 1 deletion cmd/cluster/unassign_nal_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/formatter"
)
Expand Down Expand Up @@ -57,6 +58,7 @@ var unassignClusterCmd = &cobra.Command{
}
if !nalFound {
logrus.Errorf("The allow list %s is not associated with the cluster %s", formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR))
return
}

_, r, err = authApi.EditClusterNetworkAllowLists(clusterId, allowListIds).Execute()
Expand All @@ -66,7 +68,24 @@ var unassignClusterCmd = &cobra.Command{
return
}

fmt.Printf("The cluster %s is being unassigned the network allow list %s\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))
msg := fmt.Sprintf("The cluster %s is being unassigned the network allow list %s", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterId, "CLUSTER", "EDIT_ALLOW_LIST", []string{"FAILED", "SUCCEEDED"}, msg, 600)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been unassigned the network allow list %s\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR), formatter.Colorize(newNetworkAllowListName, formatter.GREEN_COLOR))

} else {
fmt.Println(msg)
}

},
}

Expand Down
30 changes: 28 additions & 2 deletions cmd/cluster/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,40 @@ var updateClusterCmd = &cobra.Command{
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData := []ybmclient.ClusterData{resp.GetData()}

msg := fmt.Sprintf("The cluster %s is being updated", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

if viper.GetBool("wait") {
returnStatus, err := authApi.WaitForTaskCompletion(clusterID, "CLUSTER", "EDIT_CLUSTER", []string{"FAILED", "SUCCEEDED"}, msg, 1800)
if err != nil {
logrus.Errorf("error when getting task status: %s", err)
return
}
if returnStatus != "SUCCEEDED" {
logrus.Errorf("Operation failed with error: %s", returnStatus)
return
}
fmt.Printf("The cluster %s has been updated\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))

respC, r, err := authApi.ListClusters().Name(clusterName).Execute()
if err != nil {
logrus.Errorf("Error when calling `ClusterApi.ListClusters`: %s", ybmAuthClient.GetApiErrorDetails(err))
logrus.Debugf("Full HTTP response: %v", r)
return
}
clusterData = respC.GetData()
} else {
fmt.Println(msg)
}

clustersCtx := formatter.Context{
Output: os.Stdout,
Format: formatter.NewClusterFormat(viper.GetString("output")),
}

formatter.ClusterWrite(clustersCtx, []ybmclient.ClusterData{resp.GetData()})
formatter.ClusterWrite(clustersCtx, clusterData)

fmt.Printf("The cluster %s is being updated\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR))
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/nal/network_allow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var NalCmd = &cobra.Command{
}

var getNetworkAllowListCmd = &cobra.Command{
Use: "network-allow-list",
Use: "get",
Short: "Get network allow list in YugabyteDB Managed",
Long: "Get network allow list in YugabyteDB Managed",
Run: func(cmd *cobra.Command, args []string) {
Expand Down
Loading

0 comments on commit 1812916

Please sign in to comment.