Skip to content

Commit

Permalink
feat(object): add trace log
Browse files Browse the repository at this point in the history
with #21965691

Signed-off-by: yhjiango <[email protected]>
  • Loading branch information
yhjiango committed Mar 18, 2024
1 parent d6c9a2c commit dd0b94b
Show file tree
Hide file tree
Showing 36 changed files with 1,867 additions and 2,055 deletions.
41 changes: 21 additions & 20 deletions console/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/samsarahq/thunder/graphql"
"github.com/samsarahq/thunder/graphql/schemabuilder"

"github.com/cubefs/cubefs/console/cutil"
. "github.com/cubefs/cubefs/objectnode"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/graphql/client"
"github.com/cubefs/cubefs/sdk/graphql/client/user"
"github.com/cubefs/cubefs/util/log"
"github.com/samsarahq/thunder/graphql"
"github.com/samsarahq/thunder/graphql/schemabuilder"
)

type FileService struct {
Expand Down Expand Up @@ -82,12 +83,12 @@ func (fs *FileService) listFile(ctx context.Context, args struct {
return nil, err
}

volume, err := fs.manager.Volume(args.VolName)
volume, err := fs.manager.Volume(ctx, args.VolName)
if err != nil {
return nil, err
}

result, err := volume.ListFilesV1(&args.Request)
result, err := volume.ListFilesV1(ctx, &args.Request)
if err != nil {
return nil, err
}
Expand All @@ -114,12 +115,12 @@ func (fs *FileService) createDir(ctx context.Context, args struct {
return nil, err
}

volume, err := fs.manager.Volume(args.VolName)
volume, err := fs.manager.Volume(ctx, args.VolName)
if err != nil {
return nil, err
}

return volume.PutObject(args.Path, nil, &PutFileOption{
return volume.PutObject(ctx, args.Path, nil, &PutFileOption{
MIMEType: ValueContentTypeDirectory,
Tagging: nil,
Metadata: nil,
Expand All @@ -140,7 +141,7 @@ func (fs *FileService) deleteDir(ctx context.Context, args struct {
return nil, err
}

volume, err := fs.manager.Volume(args.VolName)
volume, err := fs.manager.Volume(ctx, args.VolName)
if err != nil {
return nil, err
}
Expand All @@ -149,7 +150,7 @@ func (fs *FileService) deleteDir(ctx context.Context, args struct {
return nil, err
}

if err := volume.DeletePath(args.Path + "/"); err != nil {
if err := volume.DeletePath(ctx, args.Path+"/"); err != nil {
return nil, err
}

Expand All @@ -164,7 +165,7 @@ func _deleteDir(ctx context.Context, volume *Volume, path string, marker string)
}

for {
result, err := volume.ListFilesV1(&ListFilesV1Option{
result, err := volume.ListFilesV1(ctx, &ListFilesV1Option{
Prefix: path,
Delimiter: "/",
Marker: marker,
Expand All @@ -175,13 +176,13 @@ func _deleteDir(ctx context.Context, volume *Volume, path string, marker string)
if err := _deleteDir(ctx, volume, prefixe, ""); err != nil {
return err
}
if err := volume.DeletePath(prefixe + "/"); err != nil {
if err := volume.DeletePath(ctx, prefixe+"/"); err != nil {
return err
}
}

for _, info := range result.Files {
if err := volume.DeletePath(info.Path); err != nil {
if err := volume.DeletePath(ctx, info.Path); err != nil {
return err
}
}
Expand Down Expand Up @@ -212,12 +213,12 @@ func (fs *FileService) deleteFile(ctx context.Context, args struct {
return nil, err
}

volume, err := fs.manager.Volume(args.VolName)
volume, err := fs.manager.Volume(ctx, args.VolName)
if err != nil {
return nil, err
}

if err := volume.DeletePath(args.Path); err != nil {
if err := volume.DeletePath(ctx, args.Path); err != nil {
return nil, err
}

Expand All @@ -238,11 +239,11 @@ func (fs *FileService) fileMeta(ctx context.Context, args struct {
return nil, err
}

volume, err := fs.manager.Volume(args.VolName)
volume, err := fs.manager.Volume(ctx, args.VolName)
if err != nil {
return nil, err
}
info, _, err = volume.ObjectMeta(args.Path)
info, _, err = volume.ObjectMeta(ctx, args.Path)
return
// return volume.ObjectMeta(args.Path)
}
Expand Down Expand Up @@ -320,20 +321,20 @@ func (fs *FileService) DownFile(writer http.ResponseWriter, request *http.Reques
return fmt.Errorf("not found path in get param ?path=[your path]")
}

volume, err := fs.manager.Volume(volName)
volume, err := fs.manager.Volume(ctx, volName)
if err != nil {
return err
}

meta, _, err := volume.ObjectMeta(path)
meta, _, err := volume.ObjectMeta(ctx, path)
if err != nil {
return err
}

writer.Header().Set("Content-Type", "application/octet-stream")
writer.Header().Set("Content-Length", strconv.FormatInt(meta.Size, 10))

if err := volume.ReadFile(path, writer, 0, uint64(meta.Size)); err != nil {
if err := volume.ReadFile(ctx, path, writer, 0, uint64(meta.Size)); err != nil {
return err
}

Expand Down Expand Up @@ -378,7 +379,7 @@ func (fs *FileService) UpLoadFile(writer http.ResponseWriter, request *http.Requ
return fmt.Errorf("not found path in get param ?path=[your path]")
}

volume, err := fs.manager.Volume(volName)
volume, err := fs.manager.Volume(ctx, volName)
if err != nil {
return err
}
Expand All @@ -390,7 +391,7 @@ func (fs *FileService) UpLoadFile(writer http.ResponseWriter, request *http.Requ

filepath := path + "/" + header.Filename

object, err := volume.PutObject(filepath, file, &PutFileOption{
object, err := volume.PutObject(ctx, filepath, file, &PutFileOption{
MIMEType: header.Header.Get("Content-Type"),
Tagging: nil,
Metadata: nil,
Expand Down
4 changes: 2 additions & 2 deletions objectnode/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"encoding/xml"
"net/http"

"github.com/cubefs/cubefs/blobstore/util/log"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
)

const (
Expand Down Expand Up @@ -232,7 +232,7 @@ func (acp *AccessControlPolicy) XmlMarshal() ([]byte, error) {
func (acp *AccessControlPolicy) Encode() string {
data, err := json.Marshal(acp)
if err != nil {
log.LogWarnf("acl json marshal failed: %v", err)
log.Warnf("acl json marshal failed: %v", err)
}
return string(data)
}
38 changes: 25 additions & 13 deletions objectnode/acl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package objectnode

import (
"context"
"encoding/json"
"encoding/xml"
"fmt"
Expand Down Expand Up @@ -46,12 +47,15 @@ func IsApiSupportByObjectAcl(apiName proto.Action) bool {
return false
}

func ParseACL(req *http.Request, owner string, hasBodyAcl, needDefault bool) (acl *AccessControlPolicy, err error) {
func ParseACL(req *http.Request, owner string, hasBodyAcl, needDefault bool) (*AccessControlPolicy, error) {
cannedAcl, hasCannedAcl := req.Header[XAmzAcl]
hasGrantAcl := hasGrantAclHeader(req.Header)
if err = hasConflictAcl(hasCannedAcl, hasGrantAcl, hasBodyAcl); err != nil {
err := hasConflictAcl(hasCannedAcl, hasGrantAcl, hasBodyAcl)
if err != nil {
return nil, err
}

var acl *AccessControlPolicy
switch {
case hasCannedAcl:
acl, err = ParseCannedAcl(cannedAcl[0], owner)
Expand All @@ -65,9 +69,10 @@ func ParseACL(req *http.Request, owner string, hasBodyAcl, needDefault bool) (ac
}
return nil, nil
}
if err != nil {
if err != nil || acl == nil {
return nil, err
}

return acl, acl.IsValid()
}

Expand Down Expand Up @@ -105,12 +110,14 @@ func ParseGrantAclWithinHeader(reqHeader http.Header, owner string) (*AccessCont

func ParseAclFromRequestBody(body io.Reader, owner string) (acl *AccessControlPolicy, err error) {
if err = xml.NewDecoder(body).Decode(&acl); err != nil {
return nil, ErrMalformedACL
err = ErrMalformedACL
return
}
if acl.GetOwner() != owner {
return nil, AccessDenied
err = AccessDenied
}
return acl, nil

return
}

func CreateDefaultACL(owner string) *AccessControlPolicy {
Expand Down Expand Up @@ -158,10 +165,12 @@ func parseGrantValue(grantValue string) (grants []grant, err error) {
for _, pair := range pairs {
kv := strings.Split(pair, "=")
if len(kv) != 2 || kv[0] == "" || kv[1] == "" {
return nil, InvalidArgument
err = InvalidArgument
return
}
grants = append(grants, grant{key: kv[0], value: kv[1]})
}

return
}

Expand All @@ -178,16 +187,17 @@ func addGrants(acl *AccessControlPolicy, grants []grant, permission string) {
}
}

func putBucketACL(vol *Volume, acp *AccessControlPolicy) error {
func putBucketACL(ctx context.Context, vol *Volume, acp *AccessControlPolicy) error {
data, err := json.Marshal(acp)
if err != nil {
return err
}
return vol.store.Put(vol.name, bucketRootPath, XAttrKeyOSSACL, data)

return vol.store.Put(ctx, vol.name, bucketRootPath, XAttrKeyOSSACL, data)
}

func getObjectACL(vol *Volume, path string, needDefault bool) (*AccessControlPolicy, error) {
xAttr, err := vol.GetXAttr(path, XAttrKeyOSSACL)
func getObjectACL(ctx context.Context, vol *Volume, path string, needDefault bool) (*AccessControlPolicy, error) {
xAttr, err := vol.GetXAttr(ctx, path, XAttrKeyOSSACL)
if err != nil || xAttr == nil {
return nil, err
}
Expand All @@ -203,13 +213,15 @@ func getObjectACL(vol *Volume, path string, needDefault bool) (*AccessControlPol
} else if needDefault {
acp = CreateDefaultACL(vol.owner)
}

return acp, err
}

func putObjectACL(vol *Volume, path string, acp *AccessControlPolicy) error {
func putObjectACL(ctx context.Context, vol *Volume, path string, acp *AccessControlPolicy) error {
data, err := json.Marshal(acp)
if err != nil {
return err
}
return vol.SetXAttr(path, XAttrKeyOSSACL, data, false)

return vol.SetXAttr(ctx, path, XAttrKeyOSSACL, data, false)
}
Loading

0 comments on commit dd0b94b

Please sign in to comment.