Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add get object meta and get bucket meta apis #412

Merged
merged 4 commits into from
May 11, 2023

Conversation

annielz
Copy link
Collaborator

@annielz annielz commented May 10, 2023

Description

Add getObjectMeta and getBucketMeta apis in metadata service.

Rationale

Adding 2 apis for DCellar frontend optimization usage.

Example

getObjectMeta:
{bucket_name}.localhost:9033/{object_name}?object-meta
localhost:9033/{bucket_name}/{object_name}?object-meta

getBucketMeta:
{bucket_name}.localhost:9033?bucket-meta
localhost:9033/{bucket_name}?bucket-meta

Changes

Notable changes:

  • add 2 apis in metadata service

@@ -124,3 +124,124 @@ func (gateway *Gateway) listObjectsByBucketNameHandler(w http.ResponseWriter, r
w.Header().Set(model.ContentTypeHeader, model.ContentTypeJSONHeaderValue)
w.Write(b.Bytes())
}

// getObjectMetaByNameHandler handle get object info by name request
func (gateway *Gateway) getObjectByNameHandler(w http.ResponseWriter, r *http.Request) {

Choose a reason for hiding this comment

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

Rename getObjectByNameHandler to getObjectMetaByNameHandler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -26,6 +26,8 @@ const (
queryUploadProgressRouterName = "queryUploadProgress"
downloadObjectByUniversalEndpointName = "DownloadObjectByUniversalEndpoint"
viewObjectByUniversalEndpointName = "ViewObjectByUniversalEndpoint"
getObjectByNameRouterName = "getObjectByName"

Choose a reason for hiding this comment

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

getObjectMetaByName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Name(getBucketAndPaymentRouterName).
Methods(http.MethodGet).
Path("/bucket/payment").
HandlerFunc(g.getBucketWithPaymentHandler)

Choose a reason for hiding this comment

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

What happens if objectName=/bucket/payment?
It is best to modify the router and supplement the corresponding unit tests. It's easy to go wrong here.

Copy link
Collaborator Author

@annielz annielz May 10, 2023

Choose a reason for hiding this comment

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

Fixed, using query param instead and added unit tests.

Name(getObjectByNameRouterName).
Methods(http.MethodGet).
Path("/{object:.+}/metadata").
HandlerFunc(g.getObjectByNameHandler)

Choose a reason for hiding this comment

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

Ditto, what happens if objectName=/abc/metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, using query param instead.

@@ -85,7 +97,7 @@ func (g *Gateway) registerHandler(r *mux.Router) {
HandlerFunc(g.listObjectsByBucketNameHandler)
hostBucketRouter.NotFoundHandler = http.HandlerFunc(g.notFoundHandler)

// bucket list router, virtual-hosted style
// bucket list router, path style
bucketListRouter := r.Host(g.config.Domain).Subrouter()

Choose a reason for hiding this comment

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

If it is a path style, it does not need to match host.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Name(getBucketAndPaymentRouterName).
Methods(http.MethodGet).
Path("/bucket/payment").
HandlerFunc(g.getBucketWithPaymentHandler)

Choose a reason for hiding this comment

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

what happens if bucketName=bucket and objectName=payment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, using query param instead.

Name(getObjectByNameRouterName).
Methods(http.MethodGet).
Path("/{object:.+}/metadata").
HandlerFunc(g.getObjectByNameHandler)

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, using query param instead.

feat: modify long name

feat: sort import correctly

fix: typos

fix: typo
@annielz annielz force-pushed the feat-getobjectandbucketbyname branch from 2743b7e to d167387 Compare May 10, 2023 12:51
@annielz annielz force-pushed the feat-getobjectandbucketbyname branch from d167387 to f447c3c Compare May 10, 2023 12:56
@annielz annielz changed the title feat: add get object and get bucket with payment apis feat: add get object meta and get bucket meta apis May 10, 2023
model/const.go Outdated
// GetBucketMetaByNameQuery defines get bucket metadata query, which is used to route request
GetBucketMetaByNameQuery = "bucket-meta"
// GetObjectMetaByNameQuery defines get object metadata query, which is used to route request
GetObjectMetaByNameQuery = "object-meta"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is also suitable to remove ByName, because in our scene, the default is indexed by Name. (Maybe only ByObjectID needs to be pointed out).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense, I renamed them and related methods, thanks for the suggestion!

}()

if gateway.metadata == nil {
log.Error("failed to get object by name due to not config metadata")
Copy link
Collaborator

Choose a reason for hiding this comment

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

get object meta.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

ctx := log.Context(context.Background(), req)
resp, err := gateway.metadata.GetObjectByObjectNameAndBucketName(ctx, req)
if err != nil {
log.Errorf("failed to get object by object name and bucket name", "error", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed


m := jsonpb.Marshaler{EmitDefaults: true, OrigName: true, EnumsAsInts: true}
if err = m.Marshal(&b, resp); err != nil {
log.Errorf("failed to get object by object name and bucket name", "error", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

wantedRouterName: getObjectMetaByNameRouterName,
},
{
name: "Get object upload progress router, path style",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Polish name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

wantedRouterName: getBucketMetaByNameRouterName,
},
{
name: "Get bucket upload progress router, path style",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls add list user buckets router ut.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The list user buckets router ut is already there, named getUserBucketsRouterName.

@annielz annielz force-pushed the feat-getobjectandbucketbyname branch from 6f75b48 to 9b42fa6 Compare May 11, 2023 02:49
@annielz annielz merged commit 2f0d209 into develop May 11, 2023
joeylichang added a commit that referenced this pull request May 15, 2023
* feat: sp services add pprof

* feat:block syncer add read concurrency support

* fix: rename pprof var name

* fix:debug log

* fix: fix the content of sp readme

* feat: add universal endpoint view option (#383)

* feat: add universal endpoint view option

fix: imports

* fix: add space before comments

* fix: put header in right place (#385)

* feat: signer async send sealObject tx

* fix: simplify gnfd client signature test case

* fix: return function when get nonce on chain failed

* fix: annotation

* fix: cross region netroek opt

* feat: implement stop serving on testnet (#336)

* feat: localup shell adds generate sp.info and db.info function (#398)

* feat: localup shell adds generate sp.info and db.info function

* fix: fix reset db function name

* feat: support full-memory replicate task (#410)

* feat: add gc worker (#408)

* feat: bsdb switch (#402)

* feat: update metadata db config and startDBSwitchListener
* feat: update e2e config
* fix: rename bsdbflag and update config/config_template.toml

* feat:add upload download add bandwidth limit

* feat: list objects pagination & folder path (#404)

* feat: add pagination for list objects

* fix: define constant queries & update func name

* fix: update filter for listobjects when delimiter is empty

* fix: refine query name

* fix: nil config.SQLDBConfig (#413)

* feat: add get object meta and get bucket meta apis (#412)

* feat: add get object and get bucket with payment apis

feat: modify long name

feat: sort import correctly

fix: typos

fix: typo

* fix: address comments, change path params to query params

fix: typo

* feat: add unit tests for new apis

* fix: rename services and comments according to comments

fix: import position

* fix:BandwidthLimit config

* fix:bandwidth config

* feat: adapt greenfield v0.47 (#406)

* fix: upgrade greenfield version to v0.2.0 (#415)

Co-authored-by: VM <arimas@foxmail.com>

* feat: add dual db warm up support for blocksyncer (#401)

* feat: add dual db warm up support for blocksyncer

* feat: add stop main service logic

* feat: update chain version to v0.47 and some adapts

* fix: upgrade e2e ci greenfield version to v0.2.0 (#418)

Co-authored-by: VM <arimas@foxmail.com>

* docs: add v0.2.0 changelog (#417)

* docs: add v0.2.0 changelog

* fix: add blocksycner dual db feature in changelog

* docs: add localup shell feature in changelog

---------

Co-authored-by: actioncli <joeycli0919@qq.com>
Co-authored-by: krish-nr <krish.z@nodereal.io>
Co-authored-by: VM <arimas@foxmail.com>

* feat: replace github.com/gogo/protobuf with github.com/cosmos/gogoproto (#422)

---------

Co-authored-by: VM <arimas@foxmail.com>
Co-authored-by: constwz <changbohao30@gmail.com>
Co-authored-by: Annie <108039750+annielz@users.noreply.github.com>
Co-authored-by: j75689 <j75689@gmail.com>
Co-authored-by: constwz <122766871+constwz@users.noreply.github.com>
Co-authored-by: forcodedancing <just.haha.it@gmail.com>
Co-authored-by: VM <112189277+sysvm@users.noreply.github.com>
Co-authored-by: will-2012 <117156346+will-2012@users.noreply.github.com>
Co-authored-by: Barry <122767193+BarryTong65@users.noreply.github.com>
Co-authored-by: Chris Li <jingjunLi@users.noreply.github.com>
Co-authored-by: krish-z <122767080+krish-nr@users.noreply.github.com>
Co-authored-by: actioncli <joeycli0919@qq.com>
Co-authored-by: krish-nr <krish.z@nodereal.io>
Co-authored-by: yutianwu <wzxingbupt@gmail.com>
@sysvm sysvm deleted the feat-getobjectandbucketbyname branch May 26, 2023 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants