From e64706d7ea8d5c9bdfe2d9e8ae5bbc195f6941f3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 30 Oct 2022 16:45:20 -0700 Subject: [PATCH] fix up rebalance commands for 'mc' error conventions and usage (#4333) --- cmd/admin-rebalance-start.go | 24 ++++++++---------------- cmd/admin-rebalance-status.go | 34 +++++++++++++++------------------- cmd/admin-rebalance-stop.go | 18 +++++------------- 3 files changed, 28 insertions(+), 48 deletions(-) diff --git a/cmd/admin-rebalance-start.go b/cmd/admin-rebalance-start.go index 1482162c..3104e069 100644 --- a/cmd/admin-rebalance-start.go +++ b/cmd/admin-rebalance-start.go @@ -29,7 +29,7 @@ import ( var adminRebalanceStartCmd = cli.Command{ Name: "start", - Usage: "Start rebalance operation", + Usage: "start rebalance operation", Action: mainAdminRebalanceStart, OnUsageError: onUsageError, Before: setGlobalsFromContext, @@ -43,7 +43,6 @@ USAGE: FLAGS: {{range .VisibleFlags}}{{.}} {{end}} - EXAMPLES: 1. Start rebalance on a MinIO deployment with alias myminio {{.Prompt}} {{.HelpName}} myminio @@ -69,7 +68,7 @@ func (r rebalanceStartMsg) String() string { func mainAdminRebalanceStart(ctx *cli.Context) error { if len(ctx.Args()) != 1 { - cli.ShowCommandHelpAndExit(ctx, "rebalance", 1) + showCommandHelpAndExit(ctx, ctx.Command.Name, 1) } console.SetColor("rebalanceStartMsg", color.New(color.FgGreen)) @@ -78,23 +77,16 @@ func mainAdminRebalanceStart(ctx *cli.Context) error { aliasedURL := args.Get(0) // Create a new MinIO Admin Client - var pErr *probe.Error - client, pErr := newAdminClient(aliasedURL) - if pErr != nil { - fatalIf(pErr.Trace(aliasedURL), "Unable to initialize admin client") - return pErr.ToGoError() - } + client, err := newAdminClient(aliasedURL) + fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client") + + id, e := client.RebalanceStart(globalContext) + fatalIf(probe.NewError(e), "Unable to start rebalance") - var id string - var err error - id, err = client.RebalanceStart(globalContext) - if err != nil { - fatalIf(probe.NewError(err), "Failed to start rebalance") - return err - } printMsg(rebalanceStartMsg{ Target: aliasedURL, ID: id, }) + return nil } diff --git a/cmd/admin-rebalance-status.go b/cmd/admin-rebalance-status.go index 075bd810..4c50e10a 100644 --- a/cmd/admin-rebalance-status.go +++ b/cmd/admin-rebalance-status.go @@ -32,7 +32,7 @@ import ( var adminRebalanceStatusCmd = cli.Command{ Name: "status", - Usage: "Show status of an ongoing rebalance operation", + Usage: "summarize an ongoing rebalance operation", Action: mainAdminRebalanceStatus, OnUsageError: onUsageError, Before: setGlobalsFromContext, @@ -46,35 +46,32 @@ USAGE: FLAGS: {{range .VisibleFlags}}{{.}} {{end}} - EXAMPLES: - 1. Fetch status of an ongoing rebalance on a MinIO deployment with alias myminio + 1. Summarize ongoing rebalance on a MinIO deployment with alias myminio {{.Prompt}} {{.HelpName}} myminio `, } func mainAdminRebalanceStatus(ctx *cli.Context) error { if len(ctx.Args()) != 1 { - cli.ShowCommandHelpAndExit(ctx, "rebalance", 1) + showCommandHelpAndExit(ctx, ctx.Command.Name, 1) } args := ctx.Args() aliasedURL := args.Get(0) - var pErr *probe.Error - client, pErr := newAdminClient(aliasedURL) - if pErr != nil { - fatalIf(pErr.Trace(aliasedURL), "Unable to initialize admin client") - return pErr.ToGoError() + client, err := newAdminClient(aliasedURL) + if err != nil { + fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client") + return err.ToGoError() } - rInfo, err := client.RebalanceStatus(globalContext) - if err != nil { - fatalIf(probe.NewError(err), "Failed to get rebalance status") - } + rInfo, e := client.RebalanceStatus(globalContext) + fatalIf(probe.NewError(e), "Unable to get rebalance status") + if globalJSON { - b, err := json.Marshal(rInfo) - fatalIf(probe.NewError(err), "Failed to marshal json") + b, e := json.Marshal(rInfo) + fatalIf(probe.NewError(e), "Unable to marshal json") console.Println(string(b)) return nil } @@ -116,10 +113,9 @@ func mainAdminRebalanceStatus(ctx *cli.Context) error { } alignRights := make([]bool, len(rInfo.Pools)) tbl := console.NewTable(printColors, alignRights, 0) - err = tbl.DisplayTable([][]string{colHeaders, row}) - if err != nil { - return err - } + + e = tbl.DisplayTable([][]string{colHeaders, row}) + fatalIf(probe.NewError(e), "Unable to render table view") var b strings.Builder fmt.Fprintf(&b, "Summary: \n") diff --git a/cmd/admin-rebalance-stop.go b/cmd/admin-rebalance-stop.go index 5ecdcbb7..4bb9cc15 100644 --- a/cmd/admin-rebalance-stop.go +++ b/cmd/admin-rebalance-stop.go @@ -29,7 +29,7 @@ import ( var adminRebalanceStopCmd = cli.Command{ Name: "stop", - Usage: "Stop an ongoing rebalance operation", + Usage: "stop an ongoing rebalance operation", Action: mainAdminRebalanceStop, OnUsageError: onUsageError, Before: setGlobalsFromContext, @@ -43,7 +43,6 @@ USAGE: FLAGS: {{range .VisibleFlags}}{{.}} {{end}} - EXAMPLES: 1. Stop an ongoing rebalance on a MinIO deployment with alias myminio {{.Prompt}} {{.HelpName}} myminio @@ -68,7 +67,7 @@ func (r rebalanceStopMsg) String() string { func mainAdminRebalanceStop(ctx *cli.Context) error { if len(ctx.Args()) != 1 { - cli.ShowCommandHelpAndExit(ctx, "rebalance", 1) + showCommandHelpAndExit(ctx, ctx.Command.Name, 1) } console.SetColor("rebalanceStopMsg", color.New(color.FgGreen)) @@ -77,17 +76,10 @@ func mainAdminRebalanceStop(ctx *cli.Context) error { aliasedURL := args.Get(0) // Create a new MinIO Admin Client - var pErr *probe.Error - client, pErr := newAdminClient(aliasedURL) - if pErr != nil { - fatalIf(pErr.Trace(aliasedURL), "Unable to initialize admin client") - return pErr.ToGoError() - } + client, err := newAdminClient(aliasedURL) + fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client") - err := client.RebalanceStop(globalContext) - if err != nil { - fatalIf(probe.NewError(err), "Failed to stop rebalance operation ") - } + fatalIf(probe.NewError(client.RebalanceStop(globalContext)), "Unable to stop rebalance operation") printMsg(rebalanceStopMsg{ Target: aliasedURL,