diff --git a/glustercli/cmd/label-list.go b/glustercli/cmd/label-list.go index a633a40b4..3cd429d3c 100644 --- a/glustercli/cmd/label-list.go +++ b/glustercli/cmd/label-list.go @@ -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 } @@ -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, } diff --git a/glustercli/cmd/snapshot-create.go b/glustercli/cmd/snapshot-create.go index d6d1090d1..1aa3670f2 100644 --- a/glustercli/cmd/snapshot-create.go +++ b/glustercli/cmd/snapshot-create.go @@ -18,6 +18,7 @@ var ( flagSnapshotCreateForce bool flagSnapshotCreateTimestamp bool flagSnapshotCreateDescription string + flagSnapshotCreateLabel string snapshotCreateCmd = &cobra.Command{ Use: "create ", @@ -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) } @@ -46,6 +48,7 @@ func snapshotCreateCmdRun(cmd *cobra.Command, args []string) { Force: flagSnapshotCreateForce, TimeStamp: flagSnapshotCreateTimestamp, Description: flagSnapshotCreateDescription, + SnapLabel: flagSnapshotCreateLabel, } snap, err := client.SnapshotCreate(req) diff --git a/glusterd2/commands/snapshot/commands.go b/glusterd2/commands/snapshot/commands.go index 7607dae45..ccc8bfe44 100644 --- a/glusterd2/commands/snapshot/commands.go +++ b/glusterd2/commands/snapshot/commands.go @@ -88,27 +88,27 @@ 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)), @@ -116,7 +116,7 @@ func (c *Command) Routes() route.Routes { 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)), diff --git a/glusterd2/commands/snapshot/label-reset.go b/glusterd2/commands/snapshot/label-reset.go index 4b0843fa8..d13d727b3 100644 --- a/glusterd2/commands/snapshot/label-reset.go +++ b/glusterd2/commands/snapshot/label-reset.go @@ -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) @@ -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 } @@ -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) } diff --git a/glusterd2/commands/snapshot/snapshot-create.go b/glusterd2/commands/snapshot/snapshot-create.go index 24e7a204e..6d8e29008 100644 --- a/glusterd2/commands/snapshot/snapshot-create.go +++ b/glusterd2/commands/snapshot/snapshot-create.go @@ -775,7 +775,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) } @@ -914,13 +914,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) @@ -1001,5 +1004,6 @@ func createSnapInfoResp(snap *snapshot.Snapinfo) *api.SnapInfo { ParentVolName: snap.ParentVolume, Description: snap.Description, CreatedAt: snap.CreatedAt, + SnapLabel: snap.SnapLabel, } } diff --git a/pkg/restclient/label.go b/pkg/restclient/label.go index d03f2e983..152c28459 100644 --- a/pkg/restclient/label.go +++ b/pkg/restclient/label.go @@ -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 }