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: api to get virtual group family id from SP #244

Merged
merged 1 commit into from
Apr 25, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

env:
GreenfieldTag: v1.6.0
GreenfieldStorageProviderTag: v1.6.3
GreenfieldStorageProviderTag: feat-get-recommended-vgf
GOPRIVATE: github.com/bnb-chain
GH_ACCESS_TOKEN: ${{ secrets.GH_TOKEN }}
MYSQL_USER: root
Expand Down
46 changes: 40 additions & 6 deletions client/api_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
"time"

sdkmath "cosmossdk.io/math"

ctypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/rs/zerolog/log"

"github.com/bnb-chain/greenfield-go-sdk/pkg/utils"
"github.com/bnb-chain/greenfield-go-sdk/types"

gnfdsdk "github.com/bnb-chain/greenfield/sdk/types"
gnfdTypes "github.com/bnb-chain/greenfield/types"
"github.com/bnb-chain/greenfield/types/s3util"
permTypes "github.com/bnb-chain/greenfield/x/permission/types"
storageTypes "github.com/bnb-chain/greenfield/x/storage/types"
virtualgroupTypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"

"github.com/bnb-chain/greenfield-go-sdk/pkg/utils"
"github.com/bnb-chain/greenfield-go-sdk/types"
)

// IBucketClient interface defines functions related to bucket.
Expand Down Expand Up @@ -60,6 +60,7 @@ type IBucketClient interface {
ListBucketsByPaymentAccount(ctx context.Context, paymentAccount string, opts types.ListBucketsByPaymentAccountOptions) (types.ListBucketsByPaymentAccountResult, error)
SetBucketFlowRateLimit(ctx context.Context, bucketName string, paymentAddr, bucketOwner sdk.AccAddress, flowRateLimit sdkmath.Int, opt types.SetBucketFlowRateLimitOption) (string, error)
GetPaymentAccountFlowRateLimit(ctx context.Context, paymentAddr, bucketOwner sdk.AccAddress, bucketName string) (*storageTypes.QueryPaymentAccountBucketFlowRateLimitResponse, error)
GetRecommendedVirtualGroupFamilyIDBySPID(ctx context.Context, spID uint32) (uint32, error)
}

// GetCreateBucketApproval - Send create bucket approval request to SP and returns the signature info for the approval of preCreating resources.
Expand Down Expand Up @@ -175,9 +176,9 @@ func (c *Client) CreateBucket(ctx context.Context, bucketName string, primaryAdd
return "", err
}

familyID, err := c.QuerySpOptimalGlobalVirtualGroupFamily(ctx, sp.Id, virtualgroupTypes.Strategy_Oldest_Create_Time)
familyID, err := c.GetRecommendedVirtualGroupFamilyIDBySPID(ctx, sp.Id)
if err != nil {
log.Error().Msg(fmt.Sprintf("failed to query sp ptimal vgf: %s", err.Error()))
log.Error().Msg(fmt.Sprintf("failed to query sp vgf: %s", err.Error()))
var signedMsg *storageTypes.MsgCreateBucket
signedMsg, err = c.GetCreateBucketApproval(ctx, createBucketMsg)
if err != nil {
Expand Down Expand Up @@ -1229,3 +1230,36 @@ func (c *Client) getMigrationStateFromSP(ctx context.Context, bucketName string,

return migrationProgress, nil
}

func (c *Client) GetRecommendedVirtualGroupFamilyIDBySPID(ctx context.Context, spID uint32) (uint32, error) {
endpoint, err := c.getSPUrlByID(spID)
if err != nil {
log.Error().Msg(fmt.Sprintf("route endpoint by sp ID: %d failed, err: %s", spID, err.Error()))
return 0, err
}
return c.getRecommendedVirtualGroupFamilyIDBySPEndpoint(ctx, endpoint)
}

func (c *Client) getRecommendedVirtualGroupFamilyIDBySPEndpoint(ctx context.Context, endpoint *url.URL) (uint32, error) {
reqMeta := requestMeta{
urlRelPath: "get-recommended-vgf",
}
sendOpt := sendOptions{
method: http.MethodGet,
adminInfo: AdminAPIInfo{
isAdminAPI: true,
adminVersion: types.AdminV1Version,
},
disableCloseBody: true,
}
resp, err := c.sendReq(ctx, reqMeta, &sendOpt, endpoint)
if err != nil {
return 0, err
}
vgf := types.VirtualGroupFamily{}
err = xml.NewDecoder(resp.Body).Decode(&vgf)
if err != nil {
return 0, err
}
return vgf.Id, nil
}
1 change: 0 additions & 1 deletion client/api_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ func (c *Client) putObject(ctx context.Context, bucketName, objectName string, o

func (c *Client) delegateCreateFolder(ctx context.Context, bucketName, objectName string, opts types.PutObjectOptions,
) (err error) {

var contentType string
if opts.ContentType != "" {
contentType = opts.ContentType
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/bnb-chain/greenfield/types/resource"

"cosmossdk.io/math"

"github.com/stretchr/testify/suite"

"github.com/bnb-chain/greenfield-go-sdk/client"
Expand Down Expand Up @@ -304,7 +305,6 @@ func (s *StorageTestSuite) Test_Object() {
err = s.Client.DelegateUpdateObjectContent(s.ClientContext, bucketName, objectName2, newObjectSize, bytes.NewReader(newBuffer.Bytes()), types.PutObjectOptions{})
s.Require().NoError(err)
s.WaitSealObject(bucketName, objectName2)

}

func (s *StorageTestSuite) Test_Group() {
Expand Down
5 changes: 5 additions & 0 deletions types/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,8 @@ type PolicyMeta struct {
// ExpirationTime defines the expiration time of permission
ExpirationTime int64 `xml:"ExpirationTime"`
}

type VirtualGroupFamily struct {
XMLName xml.Name `xml:"VirtualGroupFamily"`
Id uint32 `xml:"Id"`
}
Loading