Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
labels: Fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammed Rafi KC <[email protected]>
  • Loading branch information
rafikc30 committed Sep 21, 2018
1 parent 0e7b522 commit 3bdaf9a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
5 changes: 2 additions & 3 deletions glustercli/cmd/label-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ func init() {
func labelListHandler(cmd *cobra.Command) error {
var infos api.LabelListResp
var err error
labelname := cmd.Flags().Args()[0]

infos, err = client.LabelList(labelname)
infos, err = client.LabelList()
if err != nil {
return err
}
Expand All @@ -48,7 +47,7 @@ func labelListHandler(cmd *cobra.Command) error {
var labelListCmd = &cobra.Command{
Use: "list",
Short: helpLabelListCmd,
Args: cobra.ExactArgs(1),
Args: cobra.NoArgs,
Run: labelListCmdRun,
}

Expand Down
3 changes: 3 additions & 0 deletions glustercli/cmd/snapshot-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
flagSnapshotCreateForce bool
flagSnapshotCreateTimestamp bool
flagSnapshotCreateDescription string
flagSnapshotCreateLabel string

snapshotCreateCmd = &cobra.Command{
Use: "create <snapname> <volname>",
Expand All @@ -32,6 +33,7 @@ func init() {
snapshotCreateCmd.Flags().StringVar(&flagSnapshotCreateDescription, "desctription", "", "Description of snapshot")
snapshotCreateCmd.Flags().BoolVar(&flagSnapshotCreateForce, "force", false, "Force")
snapshotCreateCmd.Flags().BoolVar(&flagSnapshotCreateTimestamp, "timestamp", false, "Append timestamp with snap name")
snapshotCreateCmd.Flags().StringVar(&flagSnapshotCreateLabel, "label", "defaultLabel", "Label name for the snapshot")

snapshotCmd.AddCommand(snapshotCreateCmd)
}
Expand All @@ -46,6 +48,7 @@ func snapshotCreateCmdRun(cmd *cobra.Command, args []string) {
Force: flagSnapshotCreateForce,
TimeStamp: flagSnapshotCreateTimestamp,
Description: flagSnapshotCreateDescription,
SnapLabel: flagSnapshotCreateLabel,
}

snap, err := client.SnapshotCreate(req)
Expand Down
10 changes: 5 additions & 5 deletions glusterd2/commands/snapshot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,35 @@ func (c *Command) Routes() route.Routes {
route.Route{
Name: "LabelInfo",
Method: "GET",
Pattern: "snapshots/labels/{labelname}",
Pattern: "/snapshots/labels/{labelname}",
Version: 1,
ResponseType: utils.GetTypeString((*api.LabelGetResp)(nil)),
HandlerFunc: labelInfoHandler},
route.Route{
Name: "LabelListAll",
Method: "GET",
Pattern: "snapshots/labels/list",
Pattern: "/snapshots/labels/list/all",
Version: 1,
ResponseType: utils.GetTypeString((*api.LabelListResp)(nil)),
HandlerFunc: labelListHandler},
route.Route{
Name: "LabelDelete",
Method: "DELETE",
Pattern: "snapshots/labels/{labelname}",
Pattern: "/snapshots/labels/{labelname}",
Version: 1,
HandlerFunc: labelDeleteHandler},
route.Route{
Name: "LabelConfigSet",
Method: "POST",
Pattern: "snapshots/labels/{labelname}/config",
Pattern: "/snapshots/labels/{labelname}/config",
Version: 1,
RequestType: utils.GetTypeString((*api.LabelSetReq)(nil)),
ResponseType: utils.GetTypeString((*api.LabelConfigResp)(nil)),
HandlerFunc: labelConfigSetHandler},
route.Route{
Name: "LabelConfigReset",
Method: "DELETE",
Pattern: "snapshots/labels/{labelname}/config",
Pattern: "/snapshots/labels/{labelname}/config",
Version: 1,
RequestType: utils.GetTypeString((*api.LabelResetReq)(nil)),
ResponseType: utils.GetTypeString((*api.LabelConfigResp)(nil)),
Expand Down
14 changes: 10 additions & 4 deletions glusterd2/commands/snapshot/label-reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {

labelname := mux.Vars(r)["labelname"]

if labelname == (label.DefaultLabel).Name {
errMsg := "Default label cannot be edited."
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
return
}

txn, err := transaction.NewTxnWithLocks(ctx, labelname)
if err != nil {
status, err := restutils.ErrToStatusCode(err)
Expand All @@ -67,13 +73,13 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {
return
}

labelInfo, err = updateResetLabel(labelInfo, &req)
if err != nil {
if err := validateLabel(labelInfo); err != nil {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
return
}

if err := validateLabel(labelInfo); err != nil {
labelInfo, err = updateResetLabel(labelInfo, &req)
if err != nil {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
return
}
Expand Down Expand Up @@ -108,5 +114,5 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {

resp := createLabelConfigResp(labelInfo)
restutils.SetLocationHeader(r, w, labelInfo.Name)
restutils.SendHTTPResponse(ctx, w, http.StatusCreated, resp)
restutils.SendHTTPResponse(ctx, w, http.StatusNoContent, resp)
}
16 changes: 10 additions & 6 deletions glusterd2/commands/snapshot/snapshot-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func validateSnapLimits(info *label.Info, data *txnData) error {

} else {

msg := fmt.Sprintf("The number of snapshots will reach the effective maximum soft limit of %v for the volume (%s). Please consider deleting older snapshots.", info.SnapMaxSoftLimit, info.Name)
msg := fmt.Sprintf("The number of snapshots will reach the effective maximum soft limit of %v for the label (%s). Please consider deleting older snapshots.", info.SnapMaxSoftLimit, info.Name)

log.WithField("volume", info.Name).Warn(msg)
}
Expand Down Expand Up @@ -913,13 +913,16 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {

if data.AutoDelete {
//If victim is selected as part of auto-delete then
//we need to take additional lock on snapshot name and parent volume name
//we need to take additional lock on snapshot name
//Lock on parent volume only requires if victim is for another volume

victim := &data.Victim
if err := txn.Lock(victim.ParentVolume); err != nil {
status, err := restutils.ErrToStatusCode(err)
restutils.SendHTTPError(ctx, w, status, err)
return
if req.VolName != victim.ParentVolume {
if err := txn.Lock(victim.ParentVolume); err != nil {
status, err := restutils.ErrToStatusCode(err)
restutils.SendHTTPError(ctx, w, status, err)
return
}
}
if err := txn.Lock(victim.SnapVolinfo.Name); err != nil {
status, err := restutils.ErrToStatusCode(err)
Expand Down Expand Up @@ -1000,5 +1003,6 @@ func createSnapInfoResp(snap *snapshot.Snapinfo) *api.SnapInfo {
ParentVolName: snap.ParentVolume,
Description: snap.Description,
SnapTime: (snap.CreatedAt).Format("Mon Jan _2 2006 15:04:05 GMT"),
SnapLabel: snap.SnapLabel,
}
}
4 changes: 2 additions & 2 deletions pkg/restclient/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (c *Client) LabelReset(req api.LabelResetReq, labelname string) error {
}

// LabelList returns list of all labels
func (c *Client) LabelList(labelname string) (api.LabelListResp, error) {
func (c *Client) LabelList() (api.LabelListResp, error) {
var labelinfos api.LabelListResp
err := c.get("/v1/snapshots/labels/list", nil, http.StatusOK, &labelinfos)
err := c.get("/v1/snapshots/labels/list/all", nil, http.StatusOK, &labelinfos)
return labelinfos, err
}

Expand Down

0 comments on commit 3bdaf9a

Please sign in to comment.