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

Commit 66733ad

Browse files
committed
labels: Fix bugs
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
1 parent 46cbe5f commit 66733ad

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

glustercli/cmd/label-list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ func init() {
2323
func labelListHandler(cmd *cobra.Command) error {
2424
var infos api.LabelListResp
2525
var err error
26-
labelname := cmd.Flags().Args()[0]
2726

28-
infos, err = client.LabelList(labelname)
27+
infos, err = client.LabelList()
2928
if err != nil {
3029
return err
3130
}
@@ -48,7 +47,7 @@ func labelListHandler(cmd *cobra.Command) error {
4847
var labelListCmd = &cobra.Command{
4948
Use: "list",
5049
Short: helpLabelListCmd,
51-
Args: cobra.ExactArgs(1),
50+
Args: cobra.NoArgs,
5251
Run: labelListCmdRun,
5352
}
5453

glustercli/cmd/snapshot-create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
flagSnapshotCreateForce bool
1919
flagSnapshotCreateTimestamp bool
2020
flagSnapshotCreateDescription string
21+
flagSnapshotCreateLabel string
2122

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

3638
snapshotCmd.AddCommand(snapshotCreateCmd)
3739
}
@@ -46,6 +48,7 @@ func snapshotCreateCmdRun(cmd *cobra.Command, args []string) {
4648
Force: flagSnapshotCreateForce,
4749
TimeStamp: flagSnapshotCreateTimestamp,
4850
Description: flagSnapshotCreateDescription,
51+
SnapLabel: flagSnapshotCreateLabel,
4952
}
5053

5154
snap, err := client.SnapshotCreate(req)

glusterd2/commands/snapshot/commands.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,35 @@ func (c *Command) Routes() route.Routes {
8888
route.Route{
8989
Name: "LabelInfo",
9090
Method: "GET",
91-
Pattern: "snapshots/labels/{labelname}",
91+
Pattern: "/snapshots/labels/{labelname}",
9292
Version: 1,
9393
ResponseType: utils.GetTypeString((*api.LabelGetResp)(nil)),
9494
HandlerFunc: labelInfoHandler},
9595
route.Route{
9696
Name: "LabelListAll",
9797
Method: "GET",
98-
Pattern: "snapshots/labels/list",
98+
Pattern: "/snapshots/labels/list/all",
9999
Version: 1,
100100
ResponseType: utils.GetTypeString((*api.LabelListResp)(nil)),
101101
HandlerFunc: labelListHandler},
102102
route.Route{
103103
Name: "LabelDelete",
104104
Method: "DELETE",
105-
Pattern: "snapshots/labels/{labelname}",
105+
Pattern: "/snapshots/labels/{labelname}",
106106
Version: 1,
107107
HandlerFunc: labelDeleteHandler},
108108
route.Route{
109109
Name: "LabelConfigSet",
110110
Method: "POST",
111-
Pattern: "snapshots/labels/{labelname}/config",
111+
Pattern: "/snapshots/labels/{labelname}/config",
112112
Version: 1,
113113
RequestType: utils.GetTypeString((*api.LabelSetReq)(nil)),
114114
ResponseType: utils.GetTypeString((*api.LabelConfigResp)(nil)),
115115
HandlerFunc: labelConfigSetHandler},
116116
route.Route{
117117
Name: "LabelConfigReset",
118118
Method: "DELETE",
119-
Pattern: "snapshots/labels/{labelname}/config",
119+
Pattern: "/snapshots/labels/{labelname}/config",
120120
Version: 1,
121121
RequestType: utils.GetTypeString((*api.LabelResetReq)(nil)),
122122
ResponseType: utils.GetTypeString((*api.LabelConfigResp)(nil)),

glusterd2/commands/snapshot/label-reset.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {
5252

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

55+
if labelname == (label.DefaultLabel).Name {
56+
errMsg := "Default label cannot be edited."
57+
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
58+
return
59+
}
60+
5561
txn, err := transaction.NewTxnWithLocks(ctx, labelname)
5662
if err != nil {
5763
status, err := restutils.ErrToStatusCode(err)
@@ -67,13 +73,13 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {
6773
return
6874
}
6975

70-
labelInfo, err = updateResetLabel(labelInfo, &req)
71-
if err != nil {
76+
if err := validateLabel(labelInfo); err != nil {
7277
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
7378
return
7479
}
7580

76-
if err := validateLabel(labelInfo); err != nil {
81+
labelInfo, err = updateResetLabel(labelInfo, &req)
82+
if err != nil {
7783
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
7884
return
7985
}
@@ -108,5 +114,5 @@ func labelConfigResetHandler(w http.ResponseWriter, r *http.Request) {
108114

109115
resp := createLabelConfigResp(labelInfo)
110116
restutils.SetLocationHeader(r, w, labelInfo.Name)
111-
restutils.SendHTTPResponse(ctx, w, http.StatusCreated, resp)
117+
restutils.SendHTTPResponse(ctx, w, http.StatusNoContent, resp)
112118
}

glusterd2/commands/snapshot/snapshot-create.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ func validateSnapLimits(info *label.Info, data *txnData) error {
775775

776776
} else {
777777

778-
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)
778+
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)
779779

780780
log.WithField("volume", info.Name).Warn(msg)
781781
}
@@ -914,13 +914,16 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
914914

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

919920
victim := &data.Victim
920-
if err := txn.Lock(victim.ParentVolume); err != nil {
921-
status, err := restutils.ErrToStatusCode(err)
922-
restutils.SendHTTPError(ctx, w, status, err)
923-
return
921+
if req.VolName != victim.ParentVolume {
922+
if err := txn.Lock(victim.ParentVolume); err != nil {
923+
status, err := restutils.ErrToStatusCode(err)
924+
restutils.SendHTTPError(ctx, w, status, err)
925+
return
926+
}
924927
}
925928
if err := txn.Lock(victim.SnapVolinfo.Name); err != nil {
926929
status, err := restutils.ErrToStatusCode(err)
@@ -1001,5 +1004,6 @@ func createSnapInfoResp(snap *snapshot.Snapinfo) *api.SnapInfo {
10011004
ParentVolName: snap.ParentVolume,
10021005
Description: snap.Description,
10031006
CreatedAt: snap.CreatedAt,
1007+
SnapLabel: snap.SnapLabel,
10041008
}
10051009
}

pkg/restclient/label.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func (c *Client) LabelReset(req api.LabelResetReq, labelname string) error {
2727
}
2828

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

0 commit comments

Comments
 (0)