forked from TrueCloudLab/frostfs-node
[#1377] oid, cid: Upgrade SDK package
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f65898a354
commit
f15e6e888f
118 changed files with 1455 additions and 886 deletions
|
@ -3,6 +3,7 @@ package loadroute
|
|||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller"
|
||||
|
@ -85,12 +86,17 @@ type loadWriter struct {
|
|||
}
|
||||
|
||||
func (w *loadWriter) Put(a container.UsedSpaceAnnouncement) error {
|
||||
cnr, ok := a.ContainerID()
|
||||
if !ok {
|
||||
return errors.New("missing container in load announcement")
|
||||
}
|
||||
|
||||
w.routeMtx.Lock()
|
||||
defer w.routeMtx.Unlock()
|
||||
|
||||
key := routeKey{
|
||||
epoch: a.Epoch(),
|
||||
cid: a.ContainerID().String(),
|
||||
cid: cnr.EncodeToString(),
|
||||
}
|
||||
|
||||
routeValues, ok := w.mRoute[key]
|
||||
|
|
|
@ -2,6 +2,7 @@ package placementrouter
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
loadroute "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/route"
|
||||
|
@ -19,9 +20,14 @@ func (b *Builder) NextStage(a container.UsedSpaceAnnouncement, passed []loadrout
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), a.ContainerID())
|
||||
cnr, ok := a.ContainerID()
|
||||
if !ok {
|
||||
return nil, errors.New("missing container in load announcement")
|
||||
}
|
||||
|
||||
placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), &cnr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not build placement %s: %w", a.ContainerID(), err)
|
||||
return nil, fmt.Errorf("could not build placement %s: %w", cnr, err)
|
||||
}
|
||||
|
||||
res := make([]loadroute.ServerInfo, 0, len(placement))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package loadstorage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
|
@ -63,12 +64,17 @@ func New(_ Prm) *Storage {
|
|||
//
|
||||
// Always returns nil error.
|
||||
func (s *Storage) Put(a container.UsedSpaceAnnouncement) error {
|
||||
cnr, ok := a.ContainerID()
|
||||
if !ok {
|
||||
return errors.New("missing container in load announcement")
|
||||
}
|
||||
|
||||
s.mtx.Lock()
|
||||
|
||||
{
|
||||
key := storageKey{
|
||||
epoch: a.Epoch(),
|
||||
cid: a.ContainerID().String(),
|
||||
cid: cnr.EncodeToString(),
|
||||
}
|
||||
|
||||
estimations, ok := s.mItems[key]
|
||||
|
|
|
@ -39,7 +39,9 @@ func TestStorage(t *testing.T) {
|
|||
iterCounter++
|
||||
|
||||
require.Equal(t, epoch, ai.Epoch())
|
||||
require.Equal(t, a.ContainerID(), ai.ContainerID())
|
||||
cnr1, _ := a.ContainerID()
|
||||
cnr2, _ := ai.ContainerID()
|
||||
require.Equal(t, cnr1, cnr2)
|
||||
require.Equal(t, finalEstimation(opinions), ai.UsedSpace())
|
||||
|
||||
return nil
|
||||
|
|
|
@ -3,6 +3,7 @@ package container
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
|
@ -68,19 +69,33 @@ func (s *morphExecutor) Put(ctx containerSvc.ContextWithToken, body *container.P
|
|||
|
||||
cnr.SetSessionToken(tok)
|
||||
|
||||
cid, err := s.wrt.Put(cnr)
|
||||
idCnr, err := s.wrt.Put(cnr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var idCnrV2 refs.ContainerID
|
||||
idCnr.WriteToV2(&idCnrV2)
|
||||
|
||||
res := new(container.PutResponseBody)
|
||||
res.SetContainerID(cid.ToV2())
|
||||
res.SetContainerID(&idCnrV2)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *morphExecutor) Delete(ctx containerSvc.ContextWithToken, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) {
|
||||
id := cid.NewFromV2(body.GetContainerID())
|
||||
idV2 := body.GetContainerID()
|
||||
if idV2 == nil {
|
||||
return nil, errors.New("missing container ID")
|
||||
}
|
||||
|
||||
var id cid.ID
|
||||
|
||||
err := id.ReadFromV2(*idV2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid container ID: %w", err)
|
||||
}
|
||||
|
||||
sig := body.GetSignature().GetSign()
|
||||
|
||||
tok := session.NewTokenFromV2(ctx.SessionToken)
|
||||
|
@ -90,11 +105,11 @@ func (s *morphExecutor) Delete(ctx containerSvc.ContextWithToken, body *containe
|
|||
|
||||
var rmWitness containercore.RemovalWitness
|
||||
|
||||
rmWitness.SetContainerID(id)
|
||||
rmWitness.SetContainerID(&id)
|
||||
rmWitness.SetSignature(sig)
|
||||
rmWitness.SetSessionToken(tok)
|
||||
|
||||
err := s.wrt.Delete(rmWitness)
|
||||
err = s.wrt.Delete(rmWitness)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -103,9 +118,19 @@ func (s *morphExecutor) Delete(ctx containerSvc.ContextWithToken, body *containe
|
|||
}
|
||||
|
||||
func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody) (*container.GetResponseBody, error) {
|
||||
id := cid.NewFromV2(body.GetContainerID())
|
||||
idV2 := body.GetContainerID()
|
||||
if idV2 == nil {
|
||||
return nil, errors.New("missing container ID")
|
||||
}
|
||||
|
||||
cnr, err := s.rdr.Get(id)
|
||||
var id cid.ID
|
||||
|
||||
err := id.ReadFromV2(*idV2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid container ID: %w", err)
|
||||
}
|
||||
|
||||
cnr, err := s.rdr.Get(&id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -128,7 +153,7 @@ func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBod
|
|||
|
||||
cidList := make([]refs.ContainerID, len(cnrs))
|
||||
for i := range cnrs {
|
||||
cidList[i] = *cnrs[i].ToV2()
|
||||
cnrs[i].WriteToV2(&cidList[i])
|
||||
}
|
||||
|
||||
res := new(container.ListResponseBody)
|
||||
|
@ -159,9 +184,19 @@ func (s *morphExecutor) SetExtendedACL(ctx containerSvc.ContextWithToken, body *
|
|||
}
|
||||
|
||||
func (s *morphExecutor) GetExtendedACL(ctx context.Context, body *container.GetExtendedACLRequestBody) (*container.GetExtendedACLResponseBody, error) {
|
||||
id := cid.NewFromV2(body.GetContainerID())
|
||||
idV2 := body.GetContainerID()
|
||||
if idV2 == nil {
|
||||
return nil, errors.New("missing container ID")
|
||||
}
|
||||
|
||||
table, err := s.rdr.GetEACL(id)
|
||||
var id cid.ID
|
||||
|
||||
err := id.ReadFromV2(*idV2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid container ID: %w", err)
|
||||
}
|
||||
|
||||
table, err := s.rdr.GetEACL(&id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -5,12 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
||||
containerSvcMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph"
|
||||
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -46,6 +48,11 @@ func TestInvalidToken(t *testing.T) {
|
|||
m := mock{}
|
||||
e := containerSvcMorph.NewExecutor(m, m)
|
||||
|
||||
cnr := cidtest.ID()
|
||||
|
||||
var cnrV2 refs.ContainerID
|
||||
cnr.WriteToV2(&cnrV2)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
op func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) error
|
||||
|
@ -60,7 +67,10 @@ func TestInvalidToken(t *testing.T) {
|
|||
{
|
||||
name: "delete",
|
||||
op: func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) (err error) {
|
||||
_, err = e.Delete(ctx, new(container.DeleteRequestBody))
|
||||
var reqBody container.DeleteRequestBody
|
||||
reqBody.SetContainerID(&cnrV2)
|
||||
|
||||
_, err = e.Delete(ctx, &reqBody)
|
||||
return
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue