-
Notifications
You must be signed in to change notification settings - Fork 82
Edit volume api #704
Edit volume api #704
Conversation
route.Route{ | ||
Name: "VolumeEditMetadata", | ||
Method: "POST", | ||
Pattern: "/volumes/{volname}/edit-metadata", |
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.
s/edit-metadata/metadata
e2e/1
Outdated
@@ -0,0 +1,422 @@ | |||
package e2e |
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.
what is this file?
restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, err) | ||
return | ||
} | ||
|
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.
Add one more validation to not allow Metadata set if key name starts with _
. Keys starting with _
can be reserved for internal use. Refer: https://github.com/gluster/glusterd2/pull/603/files#diff-b3cf3c6dd98c4e29314e6f748f518b21R29
@vpandey-RH Look at #603, I think we wont be needing a separate api rest point for editing metadata , instead we can do it in edit volume api itself. |
35523cc
to
7384518
Compare
@vpandey-RH Create a volume edit API as suggested by @rishubhjain. In future, if we allow editing volume name, we can re-use it. |
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.
Keep the handler simple. There is no need for transaction here. You're only updating metadata on the store. You just have to take lock on volume name.
|
||
var req api.VolEditMetadataReq | ||
if err := restutils.UnmarshalRequest(r, &req); err != nil { | ||
restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, err) |
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.
Return 400 (BadRequest)
// Transaction which starts self heal daemon on all nodes with atleast one brick. | ||
txn := transaction.NewTxn(ctx) | ||
defer txn.Cleanup() | ||
|
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.
This doesn't need a transaction at all. There's no need to notify clients either.
7384518
to
6dcab26
Compare
6dcab26
to
862088d
Compare
Method: "POST", | ||
Pattern: "/volumes/{volname}/edit", | ||
Version: 1, | ||
RequestType: utils.GetTypeString((*api.VolumeGetResp)(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.
Please set RequestType
and ResponseType
correctly.
|
||
//Lock on Volume Name | ||
lock, unlock := transaction.CreateLockFuncs(volname) | ||
// Taking a lock outside the txn as volinfo.Nodes() must also |
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.
This comment is not valid as there is no txn here. Remove.
} | ||
} | ||
|
||
v.Metadata = req.Metadata |
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.
You'll have to replace each key, value individually.
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.
I thought we were overwriting the Metadata with every edit request?
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.
You are over-writing individual keys only.
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.
what I have implemented, will replace the metadata with new metadata that is sent as part of POST parameter but I get it I need to overwrite keywise.
txn := transaction.NewTxn(ctx) | ||
defer txn.Cleanup() | ||
|
||
txn.Nodes = v.Nodes() |
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.
Like mentioned previously, this should not be a transaction as it's only run on one node!
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.
But I need to run a transaction step for updating the volfile ?
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.
the volfile needs no updation as metadata isn't used for volfile generation
e2e/volume_ops_test.go
Outdated
"owner": "gd2tests", | ||
}, | ||
} | ||
_, err = client.EditVolume(volname, editMetadataReq) |
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.
You will have to check the response body. Also, test the replace key cases.
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.
Added the check for the response as well as for the new volinfo generated after the changes.
Pattern: "/volumes/{volname}/edit", | ||
Version: 1, | ||
RequestType: utils.GetTypeString((*api.VolEditReq)(nil)), | ||
ResponseType: utils.GetTypeString((*api.VolumeGetResp)(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.
This should be api.VolumeEditResp
which can be an alias.
} | ||
if err := volume.AddOrUpdateVolumeFunc(v); err != nil { | ||
logger.WithError(err).WithField( | ||
"volume", v.Name).Debug("failed to store volume info") |
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.
This is a serious issue - as there is no response sent back to the client, it will hang.
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.
Added a http error response.
"volume", v.Name).Debug("failed to store volume info") | ||
return | ||
} | ||
resp := createVolumeGetResp(v) |
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.
Create a createEditVolumeResp
6fae0b6
to
f002609
Compare
retest this please |
pkg/api/volume_resp.go
Outdated
@@ -95,3 +95,6 @@ type VolumeListResp []VolumeGetResp | |||
|
|||
// OptionGroupListResp is the response sent for a group list request. | |||
type OptionGroupListResp []OptionGroup | |||
|
|||
// VolumeEditResp is the response sent for a edit volume request | |||
type VolumeEditResp VolumeGetResp |
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.
This should alias to VolumeInfo
defer unlock(ctx) | ||
|
||
//validate volume name | ||
v, err := volume.GetVolume(volname) |
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.
Use volinfo
as variable name, to maintain consistency with rest of he codebase.
@@ -127,6 +127,14 @@ func (c *Command) Routes() route.Routes { | |||
Pattern: "/volfiles", | |||
Version: 1, | |||
HandlerFunc: volfilesListHandler}, | |||
route.Route{ |
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.
You have to regenerate the API documentation and include the changes that'll be done on doc/endpoints.md
in this PR:
# Start glusterd2
$ curl -o endpoints.json -s -X GET http://127.0.0.1:24007/endpoints
$ go build pkg/tools/generate-doc.go
$ ./generate-doc
e2e/volume_ops_test.go
Outdated
brickPaths = append(brickPaths, brickPath) | ||
} | ||
|
||
createReq := api.VolCreateReq{ |
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.
Do not create a new volume. Please re-use the volume used in other tests. See example in line 56 to line 62.
Also, refer to the issue this fixes in the PR message on top. Updates |
f002609
to
6c3a1ef
Compare
59c1fd3
to
11fece9
Compare
pkg/api/volume_req.go
Outdated
// VolEditReq represents a volume metadata edit request | ||
type VolEditReq struct { | ||
Metadata map[string]string `json:"metadata"` | ||
MetadataDel bool `json:"metadatadel"` |
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.
Rename this as DeleteMetadata
and json string as delete-metadata
volinfo, err = client.Volumes(volname) | ||
r.Nil(err) | ||
err = validateVolumeEdit(volinfo[0], editMetadataReq, resp) | ||
r.Nil(err) |
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.
This is good work and the kind of tests I want to see in all PRs 👍
P.S: You can remove these extra lines.
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.
@prashanthpai Which extra lines are you referring to here ?
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.
The blank ones after this
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.
Yeah, handled it.
glustercli/cmd/volume.go
Outdated
@@ -27,6 +27,7 @@ const ( | |||
helpVolumeListCmd = "List all Gluster Volumes" | |||
helpVolumeStatusCmd = "Get Gluster Volume Status" | |||
helpVolumeExpandCmd = "Expand a Gluster Volume" | |||
helpVolumeEditCmd = "Edit Volinfo properties of a Gluster Volume" |
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.
This isn't true. Right now, this is limited to metadata only. In future, we may allow renaming volumes.
It can be - "Edit metadata (key-value pairs) of a volume. Glusterd2 will not interpret these key and value in any way"
glustercli/cmd/volume.go
Outdated
// Volume Edit | ||
volumeEditCmd.Flags().StringVar(&flagCmdMetadataKey, "key", "", "Metadata Key") | ||
volumeEditCmd.Flags().StringVar(&flagCmdMetadataValue, "value", "", "Metadata Value") | ||
volumeEditCmd.Flags().BoolVar(&flagCmdDeleteMetadata, "delete", false, "Metadata Delete Flag") |
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.
The help string can be "Delete metadata"
glustercli/cmd/volume.go
Outdated
// Volume Edit | ||
volumeEditCmd.Flags().StringVar(&flagCmdMetadataKey, "key", "", "Metadata Key") | ||
volumeEditCmd.Flags().StringVar(&flagCmdMetadataValue, "value", "", "Metadata Value") | ||
volumeEditCmd.Flags().BoolVar(&flagCmdDeleteMetadata, "delete", false, "Metadata Delete Flag") |
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.
As key
and value
flags must always be present, you can use MarkFlagRequired API provided by cobra.
glustercli/cmd/volume.go
Outdated
@@ -412,3 +424,28 @@ var volumeExpandCmd = &cobra.Command{ | |||
fmt.Printf("%s Volume expanded successfully\n", vol.Name) | |||
}, | |||
} | |||
|
|||
var volumeEditCmd = &cobra.Command{ | |||
Use: "edit <volname> flags", |
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.
edit-metadata <volname> --key <key> --value <value> [--delete]
keys can be edited/deleted one at a time. Signed-off-by: Vishal Pandey <vpandey@redhat.com>
dd54a87
to
406542b
Compare
retest this please |
Updates #462
API to edit metadata of the specified volume.
Signed-off-by: Vishal Pandey vpandey@redhat.com