From 012cea1add724cd5a515f8b2e050eafc96ad32ef Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 15 Sep 2020 11:03:15 +0300 Subject: [PATCH] [#142] sdk/container: Use placement policy from neofs-api v2.0 Signed-off-by: Alex Vanin --- pkg/client/client_test.go | 13 +++++++++++-- pkg/container/opts.go | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index c3d7b0d..3aebaab 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/container" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-crypto/test" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -35,10 +36,18 @@ func TestExample(t *testing.T) { cli, err = client.New(key, client.WithGRPCConnection(conn)) require.NoError(t, err) + replica := new(netmap.Replica) + replica.SetCount(2) + replica.SetSelector("*") + + policy := new(netmap.PlacementPolicy) + policy.SetContainerBackupFactor(2) + policy.SetReplicas([]*netmap.Replica{replica}) + // this container has random nonce and it does not set owner id - cnr, err := container.New( + cnr := container.New( container.WithAttribute("CreatedAt", time.Now().String()), - container.WithPolicy("PUT 3 In *"), + container.WithPolicy(policy), container.WithReadOnlyBasicACL(), ) require.NoError(t, err) diff --git a/pkg/container/opts.go b/pkg/container/opts.go index 52f663d..106f52b 100644 --- a/pkg/container/opts.go +++ b/pkg/container/opts.go @@ -3,6 +3,7 @@ package container import ( "github.com/google/uuid" "github.com/nspcc-dev/neofs-api-go/pkg/acl" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/owner" ) @@ -18,7 +19,7 @@ type ( containerOptions struct { acl uint32 - policy string + policy *netmap.PlacementPolicy attributes []attribute owner *owner.ID nonce uuid.UUID @@ -91,9 +92,8 @@ func WithNEO3Wallet(w *owner.NEO3Wallet) NewOption { }) } -func WithPolicy(policy string) NewOption { +func WithPolicy(policy *netmap.PlacementPolicy) NewOption { return newFuncContainerOption(func(option *containerOptions) { - // todo: make sanity check and store binary structure option.policy = policy }) }