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

Provide total transfer size with the datatx protocol #3891

Merged
merged 2 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/datatx-transfer-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Enhancement: Provide data transfer size with datatx share

https://github.com/cs3org/reva/pull/3891
https://github.com/cs3org/reva/issues/2104
33 changes: 31 additions & 2 deletions internal/grpc/services/ocmshareprovider/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/sharedconf"
"github.com/cs3org/reva/pkg/storage/utils/walker"
"github.com/cs3org/reva/pkg/utils"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -71,6 +72,7 @@ type service struct {
client *client.OCMClient
gateway gateway.GatewayAPIClient
webappTmpl *template.Template
walker walker.Walker
}

func (c *config) init() {
Expand Down Expand Up @@ -134,13 +136,15 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
if err != nil {
return nil, err
}
walker := walker.NewWalker(gateway)

service := &service{
conf: c,
repo: repo,
client: client,
gateway: gateway,
webappTmpl: tpl,
walker: walker,
}

return service, nil
Expand Down Expand Up @@ -210,13 +214,38 @@ func (s *service) getWebappProtocol(share *ocm.Share) *ocmd.Webapp {
}

func (s *service) getDataTransferProtocol(ctx context.Context, share *ocm.Share) *ocmd.Datatx {
// TODO discover the size
var size uint64
// get the path of the share
statRes, err := s.gateway.Stat(ctx, &providerpb.StatRequest{
Ref: &providerpb.Reference{
ResourceId: share.ResourceId,
},
})
if err != nil {
panic(err)
gmgigi96 marked this conversation as resolved.
Show resolved Hide resolved
}

path := statRes.GetInfo().Path
err = s.walk(ctx, path, func(path string, info *providerpb.ResourceInfo, err error) error {
if info.Type == providerpb.ResourceType_RESOURCE_TYPE_FILE {
size += info.Size
}
return nil
})
if err != nil {
panic(err)
}
return &ocmd.Datatx{
SourceURI: s.webdavURL(ctx, share),
Size: 0,
Size: size,
}
}

// walk traverses the path recursively to discover all resources in the tree.
func (s *service) walk(ctx context.Context, path string, fn walker.WalkFunc) error {
return s.walker.Walk(ctx, path, fn)
}

func (s *service) getProtocols(ctx context.Context, share *ocm.Share) ocmd.Protocols {
var p ocmd.Protocols
for _, m := range share.AccessMethods {
Expand Down