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

Edit volume api #704

Merged
merged 6 commits into from
May 10, 2018
Merged

Conversation

vpandey-RH
Copy link
Contributor

@vpandey-RH vpandey-RH commented Apr 26, 2018

Updates #462
API to edit metadata of the specified volume.

Signed-off-by: Vishal Pandey vpandey@redhat.com

route.Route{
Name: "VolumeEditMetadata",
Method: "POST",
Pattern: "/volumes/{volname}/edit-metadata",
Copy link
Member

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
Copy link
Member

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
}

Copy link
Member

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

@rishubhjain
Copy link
Contributor

@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.
@prashanthpai what would you suggest?

@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch 6 times, most recently from 35523cc to 7384518 Compare April 26, 2018 13:37
@prashanthpai
Copy link
Contributor

@vpandey-RH Create a volume edit API as suggested by @rishubhjain.

In future, if we allow editing volume name, we can re-use it.

Copy link
Contributor

@prashanthpai prashanthpai left a 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)
Copy link
Contributor

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()

Copy link
Contributor

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.

@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch from 7384518 to 6dcab26 Compare April 30, 2018 09:02
@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch from 6dcab26 to 862088d Compare April 30, 2018 09:10
@vpandey-RH vpandey-RH changed the title Edit volume metadata api Edit volume api May 2, 2018
Method: "POST",
Pattern: "/volumes/{volname}/edit",
Version: 1,
RequestType: utils.GetTypeString((*api.VolumeGetResp)(nil)),
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@vpandey-RH vpandey-RH May 2, 2018

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()
Copy link
Contributor

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!

Copy link
Contributor Author

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 ?

Copy link
Contributor

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

"owner": "gd2tests",
},
}
_, err = client.EditVolume(volname, editMetadataReq)
Copy link
Contributor

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.

Copy link
Contributor Author

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)),
Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a createEditVolumeResp

@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch 2 times, most recently from 6fae0b6 to f002609 Compare May 3, 2018 16:36
@vpandey-RH
Copy link
Contributor Author

retest this please

@@ -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
Copy link
Contributor

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)
Copy link
Contributor

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{
Copy link
Contributor

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

brickPaths = append(brickPaths, brickPath)
}

createReq := api.VolCreateReq{
Copy link
Contributor

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.

@prashanthpai
Copy link
Contributor

Also, refer to the issue this fixes in the PR message on top. Updates #<issue-number>

@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch from f002609 to 6c3a1ef Compare May 8, 2018 07:41
@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch from 59c1fd3 to 11fece9 Compare May 8, 2018 10:47
// VolEditReq represents a volume metadata edit request
type VolEditReq struct {
Metadata map[string]string `json:"metadata"`
MetadataDel bool `json:"metadatadel"`
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

@vpandey-RH vpandey-RH May 10, 2018

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 ?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, handled it.

@@ -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"
Copy link
Contributor

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"

// 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")
Copy link
Contributor

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"

// 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")
Copy link
Contributor

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.

@@ -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",
Copy link
Contributor

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>
@vpandey-RH vpandey-RH force-pushed the edit-volume-metadata-API branch from dd54a87 to 406542b Compare May 10, 2018 07:21
@vpandey-RH
Copy link
Contributor Author

retest this please

@prashanthpai prashanthpai merged commit f3f1029 into gluster:master May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants