-
Notifications
You must be signed in to change notification settings - Fork 82
Rebalance missing validation and code refactor #986
base: master
Are you sure you want to change the base?
Changes from all commits
7a35c21
486e079
ef84e98
68f8011
6f60a76
a6c3f10
acbb488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
helpRebalanceCmd = "Gluster Rebalance" | ||
helpRebalanceStartCmd = "Start rebalance operation for gluster volume" | ||
helpRebalanceStatusCmd = "Status of rebalance operation" | ||
helpRebalanceStopCmd = "Stop rebalance operation" | ||
) | ||
|
||
var ( | ||
flagRebalanceStartCmdForce bool | ||
flagRebalanceStartCmdFixLayout bool | ||
) | ||
|
||
var rebalanceCmd = &cobra.Command{ | ||
Use: "volume rebalance", | ||
Short: helpRebalanceCmd, | ||
} | ||
|
||
func init() { | ||
|
||
// Rebalance Start | ||
rebalanceStartCmd.Flags().BoolVar(&flagRebalanceStartCmdForce, "force", false, "Force") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description of the flags can be a little bit more elaborate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now I am following the trend set by volumestart, will update both of them with more description in the next PR |
||
rebalanceStartCmd.Flags().BoolVar(&flagRebalanceStartCmdFixLayout, "fixlayout", false, "FixLayout") | ||
rebalanceCmd.AddCommand(rebalanceStartCmd) | ||
|
||
RootCmd.AddCommand(rebalanceCmd) | ||
} | ||
|
||
var rebalanceStartCmd = &cobra.Command{ | ||
Use: "<VOLNAME> start [flags]", | ||
Short: helpRebalanceStartCmd, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
volname := cmd.Flags().Args()[0] | ||
var err error | ||
if flagRebalanceStartCmdForce { | ||
err = client.RebalanceStart(volname, "force") | ||
} else if flagRebalanceStartCmdFixLayout { | ||
err = client.RebalanceStart(volname, "fix-layout") | ||
} else { | ||
err = client.RebalanceStart(volname, "") | ||
} | ||
if err != nil { | ||
if verbose { | ||
log.WithError(err).WithField("volume", volname).Error("rebalance start failed") | ||
} | ||
failure("rebalance start failed", err, 1) | ||
} | ||
fmt.Printf("Rebalance for %s started successfully\n", volname) | ||
}, | ||
} | ||
|
||
var rebalanceStopCmd = &cobra.Command{ | ||
Use: "<VOLNAME> stop", | ||
Short: helpRebalanceStopCmd, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
volname := cmd.Flags().Args()[0] | ||
err := client.RebalanceStop(volname) | ||
if err != nil { | ||
if verbose { | ||
log.WithError(err).WithField("volume", volname).Error("Rebalance stop failed") | ||
} | ||
failure("rebalance start failed", err, 1) | ||
} | ||
fmt.Printf("Rebalance for %s stopped successfully\n", volname) | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package restclient | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
rebalanceapi "github.com/gluster/glusterd2/plugins/rebalance/api" | ||
) | ||
|
||
// RebalanceStart starts rebalance process for given volume | ||
func (c *Client) RebalanceStart(volname string, option string) error { | ||
req := rebalanceapi.StartReq{ | ||
Option: option, | ||
} | ||
url := fmt.Sprintf("/v1/volumes/%s/rebalance/start", volname) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing import fmt package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return c.post(url, req, http.StatusOK, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, where are you importing HTTP package? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
// RebalanceStop stops rebalance process for given volume | ||
func (c *Client) RebalanceStop(volname string) error { | ||
url := fmt.Sprintf("/v1/volumes/%s/rebalance/stop", volname) | ||
return c.post(url, nil, http.StatusOK, nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where ever its required place add
Long
command to give more information about this CLI command to usersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok