[#142] sdk/container: Use placement policy from neofs-api v2.0
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
1cbfb337a7
commit
012cea1add
2 changed files with 14 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue