forked from TrueCloudLab/frostfs-node
[#155] Update neofs-api-go with refactored pkg/netmap
Refactored pkg/netmap package provides JSON converters for NodeInfo and PlacementPolicy structures, that has been used by client applications. It also updates Node structure itself so it is a part of grpc <-> v2 <-> pkg conversion chain. Signed-off-by: Alex Vanin <alexey@nspcc.ru>support/v0.27
parent
9f8eb0fd51
commit
65be09d3db
|
@ -139,7 +139,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
|||
}
|
||||
|
||||
cnr := container.New()
|
||||
cnr.SetPlacementPolicy(placementPolicy)
|
||||
cnr.SetPlacementPolicy(placementPolicy.ToV2())
|
||||
cnr.SetBasicACL(basicACL)
|
||||
cnr.SetAttributes(attributes)
|
||||
cnr.SetNonce(nonce[:])
|
||||
|
@ -531,7 +531,7 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error)
|
|||
return result, nil
|
||||
}
|
||||
|
||||
result, err = policy.FromJSON([]byte(policyString))
|
||||
result, err = netmap.PlacementPolicyFromJSON([]byte(policyString))
|
||||
if err == nil {
|
||||
printVerbose("Parsed JSON encoded policy")
|
||||
return result, nil
|
||||
|
@ -684,7 +684,8 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) {
|
|||
}
|
||||
|
||||
fmt.Println("placement policy:")
|
||||
fmt.Println(strings.Join(policy.Encode(cnr.GetPlacementPolicy()), "\n"))
|
||||
cnrPolicy := netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy())
|
||||
fmt.Println(strings.Join(policy.Encode(cnrPolicy), "\n"))
|
||||
}
|
||||
|
||||
func parseEACL(eaclPath string) (*eacl.Table, error) {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -14,7 +14,7 @@ require (
|
|||
github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2
|
||||
github.com/multiformats/go-multihash v0.0.13 // indirect
|
||||
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201103083623-89a7a946dcd5
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201106062850-d704795dcc7b
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||
github.com/nspcc-dev/tzhash v1.4.0
|
||||
github.com/panjf2000/ants/v2 v2.3.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -275,8 +275,8 @@ github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:
|
|||
github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
|
||||
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b h1:gk5bZgpWOehaDVKI5vBDkcjXTpRkKqcvIb1h/vHnBH4=
|
||||
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b/go.mod h1:9s7LNp2lMgf0caH2t0sam4+WT2SIauXozwP0AdBqnEo=
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201103083623-89a7a946dcd5 h1:V5Yo8EA2S5iAG0hlKwfS7TcZqudPOHp/3MLG5/UpQ74=
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201103083623-89a7a946dcd5/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201106062850-d704795dcc7b h1:JYitHXAKvqJc4cgicDgDJY+d2JiKR77xdczGH+CqfUU=
|
||||
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201106062850-d704795dcc7b/go.mod h1:ZKpuPU2eHFyX5Ps4I70k1u/f+x6D2Ceb/t+BH8ll6cA=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestCheckFormat(t *testing.T) {
|
|||
require.Error(t, CheckFormat(c))
|
||||
|
||||
policy := new(netmap.PlacementPolicy)
|
||||
c.SetPlacementPolicy(policy)
|
||||
c.SetPlacementPolicy(policy.ToV2())
|
||||
|
||||
require.Error(t, CheckFormat(c))
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error
|
|||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]netmapv2.NodeInfo, 0, len(rawNodeInfos))
|
||||
result := make([]netmap.NodeInfo, 0, len(rawNodeInfos))
|
||||
|
||||
for i := range rawNodeInfos {
|
||||
nodeInfo, err := peerInfoFromStackItem(rawNodeInfos[i])
|
||||
|
@ -140,10 +140,10 @@ func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error
|
|||
return nil, errors.Wrap(err, "invalid RPC response")
|
||||
}
|
||||
|
||||
result = append(result, *nodeInfo)
|
||||
result = append(result, *netmap.NewNodeInfoFromV2(nodeInfo))
|
||||
}
|
||||
|
||||
return netmap.NewNetmap(netmap.NodesFromV2(result))
|
||||
return netmap.NewNetmap(netmap.NodesFromInfo(result))
|
||||
}
|
||||
|
||||
func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) {
|
||||
|
|
|
@ -6,26 +6,25 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
netmapv2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCleanupTable(t *testing.T) {
|
||||
infos := []netmapv2.NodeInfo{
|
||||
infos := []netmap.NodeInfo{
|
||||
newNodeInfo(&test.DecodeKey(1).PublicKey),
|
||||
newNodeInfo(&test.DecodeKey(2).PublicKey),
|
||||
newNodeInfo(&test.DecodeKey(3).PublicKey),
|
||||
}
|
||||
|
||||
networkMap, err := netmap.NewNetmap(netmap.NodesFromV2(infos))
|
||||
networkMap, err := netmap.NewNetmap(netmap.NodesFromInfo(infos))
|
||||
require.NoError(t, err)
|
||||
|
||||
mapInfos := map[string]struct{}{
|
||||
hex.EncodeToString(infos[0].GetPublicKey()): {},
|
||||
hex.EncodeToString(infos[1].GetPublicKey()): {},
|
||||
hex.EncodeToString(infos[2].GetPublicKey()): {},
|
||||
hex.EncodeToString(infos[0].PublicKey()): {},
|
||||
hex.EncodeToString(infos[1].PublicKey()): {},
|
||||
hex.EncodeToString(infos[2].PublicKey()): {},
|
||||
}
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
|
@ -42,7 +41,7 @@ func TestCleanupTable(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("update with flagged", func(t *testing.T) {
|
||||
key := hex.EncodeToString(infos[0].GetPublicKey())
|
||||
key := hex.EncodeToString(infos[0].PublicKey())
|
||||
c.flag(key)
|
||||
|
||||
c.update(networkMap, 2)
|
||||
|
@ -55,7 +54,7 @@ func TestCleanupTable(t *testing.T) {
|
|||
c := newCleanupTable(true, 1)
|
||||
c.update(networkMap, 1)
|
||||
|
||||
key := hex.EncodeToString(infos[1].GetPublicKey())
|
||||
key := hex.EncodeToString(infos[1].PublicKey())
|
||||
require.True(t, c.touch(key, 11))
|
||||
require.EqualValues(t, 11, c.lastAccess[key].epoch)
|
||||
|
||||
|
@ -67,7 +66,7 @@ func TestCleanupTable(t *testing.T) {
|
|||
c := newCleanupTable(true, 1)
|
||||
c.update(networkMap, 1)
|
||||
|
||||
key := hex.EncodeToString(infos[1].GetPublicKey())
|
||||
key := hex.EncodeToString(infos[1].PublicKey())
|
||||
c.flag(key)
|
||||
require.True(t, c.lastAccess[key].removeFlag)
|
||||
|
||||
|
@ -103,7 +102,7 @@ func TestCleanupTable(t *testing.T) {
|
|||
|
||||
t.Run("some nodes to remove", func(t *testing.T) {
|
||||
cnt := 0
|
||||
key := hex.EncodeToString(infos[1].GetPublicKey())
|
||||
key := hex.EncodeToString(infos[1].PublicKey())
|
||||
|
||||
require.False(t, c.touch(key, 4)) // one node was updated
|
||||
|
||||
|
@ -118,7 +117,7 @@ func TestCleanupTable(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func newNodeInfo(key *ecdsa.PublicKey) (n netmapv2.NodeInfo) {
|
||||
func newNodeInfo(key *ecdsa.PublicKey) (n netmap.NodeInfo) {
|
||||
n.SetPublicKey(crypto.MarshalPublicKey(key))
|
||||
return n
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func (w Wrapper) GetNetMap(diff uint64) (*netmap.Netmap, error) {
|
|||
}
|
||||
|
||||
rawPeers := peers.Peers() // slice of serialized node infos
|
||||
infos := make([]v2netmap.NodeInfo, 0, len(rawPeers))
|
||||
infos := make([]netmap.NodeInfo, 0, len(rawPeers))
|
||||
|
||||
for _, peer := range rawPeers {
|
||||
grpcNodeInfo := new(grpcNetmap.NodeInfo) // transport representation of struct
|
||||
|
@ -35,10 +35,10 @@ func (w Wrapper) GetNetMap(diff uint64) (*netmap.Netmap, error) {
|
|||
}
|
||||
|
||||
v2 := v2netmap.NodeInfoFromGRPCMessage(grpcNodeInfo)
|
||||
infos = append(infos, *v2)
|
||||
infos = append(infos, *netmap.NewNodeInfoFromV2(v2))
|
||||
}
|
||||
|
||||
nodes := netmap.NodesFromV2(infos)
|
||||
nodes := netmap.NodesFromInfo(infos)
|
||||
|
||||
return netmap.NewNetmap(nodes)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
)
|
||||
|
||||
func Encode(p *netmap.PlacementPolicy) []string {
|
||||
|
@ -14,9 +14,9 @@ func Encode(p *netmap.PlacementPolicy) []string {
|
|||
}
|
||||
|
||||
var (
|
||||
replicas = p.GetReplicas()
|
||||
selectors = p.GetSelectors()
|
||||
filters = p.GetFilters()
|
||||
replicas = p.Replicas()
|
||||
selectors = p.Selectors()
|
||||
filters = p.Filters()
|
||||
)
|
||||
|
||||
// 1 for container backup factor
|
||||
|
@ -26,7 +26,7 @@ func Encode(p *netmap.PlacementPolicy) []string {
|
|||
encodeReplicas(replicas, &result)
|
||||
|
||||
// then backup factor
|
||||
if backupFactor := p.GetContainerBackupFactor(); backupFactor != 0 {
|
||||
if backupFactor := p.ContainerBackupFactor(); backupFactor != 0 {
|
||||
result = append(result, fmt.Sprintf("CBF %d", backupFactor))
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,9 @@ func encodeReplicas(replicas []*netmap.Replica, dst *[]string) {
|
|||
|
||||
for _, replica := range replicas {
|
||||
builder.WriteString("REP ")
|
||||
builder.WriteString(strconv.FormatUint(uint64(replica.GetCount()), 10))
|
||||
builder.WriteString(strconv.FormatUint(uint64(replica.Count()), 10))
|
||||
|
||||
if s := replica.GetSelector(); s != "" {
|
||||
if s := replica.Selector(); s != "" {
|
||||
builder.WriteString(" IN ")
|
||||
builder.WriteString(s)
|
||||
}
|
||||
|
@ -61,15 +61,15 @@ func encodeSelectors(selectors []*netmap.Selector, dst *[]string) {
|
|||
|
||||
for _, selector := range selectors {
|
||||
builder.WriteString("SELECT ")
|
||||
builder.WriteString(strconv.FormatUint(uint64(selector.GetCount()), 10))
|
||||
builder.WriteString(strconv.FormatUint(uint64(selector.Count()), 10))
|
||||
|
||||
if a := selector.GetAttribute(); a != "" {
|
||||
if a := selector.Attribute(); a != "" {
|
||||
builder.WriteString(" IN")
|
||||
|
||||
switch selector.GetClause() {
|
||||
case netmap.Same:
|
||||
switch selector.Clause() {
|
||||
case netmap.ClauseSame:
|
||||
builder.WriteString(" SAME ")
|
||||
case netmap.Distinct:
|
||||
case netmap.ClauseDistinct:
|
||||
builder.WriteString(" DISTINCT ")
|
||||
default:
|
||||
builder.WriteString(" ")
|
||||
|
@ -78,12 +78,12 @@ func encodeSelectors(selectors []*netmap.Selector, dst *[]string) {
|
|||
builder.WriteString(a)
|
||||
}
|
||||
|
||||
if f := selector.GetFilter(); f != "" {
|
||||
if f := selector.Filter(); f != "" {
|
||||
builder.WriteString(" FROM ")
|
||||
builder.WriteString(f)
|
||||
}
|
||||
|
||||
if n := selector.GetName(); n != "" {
|
||||
if n := selector.Name(); n != "" {
|
||||
builder.WriteString(" AS ")
|
||||
builder.WriteString(n)
|
||||
}
|
||||
|
@ -106,55 +106,32 @@ func encodeFilters(filters []*netmap.Filter, dst *[]string) {
|
|||
}
|
||||
}
|
||||
|
||||
func operationString(operation netmap.Operation) string {
|
||||
switch operation {
|
||||
case netmap.EQ:
|
||||
return "EQ"
|
||||
case netmap.NE:
|
||||
return "NE"
|
||||
case netmap.GT:
|
||||
return "GT"
|
||||
case netmap.GE:
|
||||
return "GE"
|
||||
case netmap.LT:
|
||||
return "LT"
|
||||
case netmap.LE:
|
||||
return "LE"
|
||||
case netmap.OR:
|
||||
return "OR"
|
||||
case netmap.AND:
|
||||
return "AND"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func encodeFilter(filter *netmap.Filter) string {
|
||||
builder := new(strings.Builder)
|
||||
unspecified := filter.GetOp() == netmap.UnspecifiedOperation
|
||||
unspecified := filter.Operation() == 0
|
||||
|
||||
if k := filter.GetKey(); k != "" {
|
||||
if k := filter.Key(); k != "" {
|
||||
builder.WriteString(k)
|
||||
builder.WriteString(" ")
|
||||
builder.WriteString(operationString(filter.GetOp()))
|
||||
builder.WriteString(filter.Operation().String())
|
||||
builder.WriteString(" ")
|
||||
builder.WriteString(filter.GetValue())
|
||||
} else if n := filter.GetName(); unspecified && n != "" {
|
||||
builder.WriteString(filter.Value())
|
||||
} else if n := filter.Name(); unspecified && n != "" {
|
||||
builder.WriteString("@")
|
||||
builder.WriteString(n)
|
||||
}
|
||||
|
||||
for i, subfilter := range filter.GetFilters() {
|
||||
for i, subfilter := range filter.InnerFilters() {
|
||||
if i != 0 {
|
||||
builder.WriteString(" ")
|
||||
builder.WriteString(operationString(filter.GetOp()))
|
||||
builder.WriteString(filter.Operation().String())
|
||||
builder.WriteString(" ")
|
||||
}
|
||||
|
||||
builder.WriteString(encodeFilter(subfilter))
|
||||
}
|
||||
|
||||
if n := filter.GetName(); n != "" && !unspecified {
|
||||
if n := filter.Name(); n != "" && !unspecified {
|
||||
builder.WriteString(" AS ")
|
||||
builder.WriteString(n)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdknm "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -48,10 +47,10 @@ func Parse(s string) (*netmap.PlacementPolicy, error) {
|
|||
seenSelectors := map[string]bool{}
|
||||
ss := make([]*netmap.Selector, 0, len(q.Selectors))
|
||||
for _, qs := range q.Selectors {
|
||||
if qs.Filter != sdknm.MainFilterName && !seenFilters[qs.Filter] {
|
||||
if qs.Filter != netmap.MainFilterName && !seenFilters[qs.Filter] {
|
||||
return nil, fmt.Errorf("%w: '%s'", ErrUnknownFilter, qs.Filter)
|
||||
}
|
||||
s := new(netmap.Selector)
|
||||
s := netmap.NewSelector()
|
||||
switch len(qs.Bucket) {
|
||||
case 1: // only bucket
|
||||
s.SetAttribute(qs.Bucket[0])
|
||||
|
@ -71,7 +70,7 @@ func Parse(s string) (*netmap.PlacementPolicy, error) {
|
|||
|
||||
rs := make([]*netmap.Replica, 0, len(q.Replicas))
|
||||
for _, qr := range q.Replicas {
|
||||
r := new(netmap.Replica)
|
||||
r := netmap.NewReplica()
|
||||
if qr.Selector != "" {
|
||||
if !seenSelectors[qr.Selector] {
|
||||
return nil, fmt.Errorf("%w: '%s'", ErrUnknownSelector, qr.Selector)
|
||||
|
@ -86,21 +85,22 @@ func Parse(s string) (*netmap.PlacementPolicy, error) {
|
|||
}
|
||||
|
||||
p := new(netmap.PlacementPolicy)
|
||||
p.SetFilters(fs)
|
||||
p.SetSelectors(ss)
|
||||
p.SetReplicas(rs)
|
||||
p.SetFilters(fs...)
|
||||
p.SetSelectors(ss...)
|
||||
p.SetReplicas(rs...)
|
||||
p.SetContainerBackupFactor(q.CBF)
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func clauseFromString(s string) netmap.Clause {
|
||||
switch strings.ToUpper(s) {
|
||||
case "SAME":
|
||||
return netmap.Same
|
||||
return netmap.ClauseSame
|
||||
case "DISTINCT":
|
||||
return netmap.Distinct
|
||||
return netmap.ClauseDistinct
|
||||
default:
|
||||
return netmap.UnspecifiedClause
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,9 +117,9 @@ func filterFromOrChain(expr *orChain, seen map[string]bool) (*netmap.Filter, err
|
|||
return fs[0], nil
|
||||
}
|
||||
|
||||
f := new(netmap.Filter)
|
||||
f.SetOp(netmap.OR)
|
||||
f.SetFilters(fs)
|
||||
f := netmap.NewFilter()
|
||||
f.SetOperation(netmap.OpOR)
|
||||
f.SetInnerFilters(fs...)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ func filterFromAndChain(expr *andChain, seen map[string]bool) (*netmap.Filter, e
|
|||
if fe.Expr != nil {
|
||||
f, err = filterFromSimpleExpr(fe.Expr, seen)
|
||||
} else {
|
||||
f = new(netmap.Filter)
|
||||
f = netmap.NewFilter()
|
||||
f.SetName(fe.Reference)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -143,28 +143,28 @@ func filterFromAndChain(expr *andChain, seen map[string]bool) (*netmap.Filter, e
|
|||
return fs[0], nil
|
||||
}
|
||||
|
||||
f := new(netmap.Filter)
|
||||
f.SetOp(netmap.AND)
|
||||
f.SetFilters(fs)
|
||||
f := netmap.NewFilter()
|
||||
f.SetOperation(netmap.OpAND)
|
||||
f.SetInnerFilters(fs...)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func filterFromSimpleExpr(se *simpleExpr, seen map[string]bool) (*netmap.Filter, error) {
|
||||
f := new(netmap.Filter)
|
||||
f := netmap.NewFilter()
|
||||
f.SetKey(se.Key)
|
||||
switch se.Op {
|
||||
case "EQ":
|
||||
f.SetOp(netmap.EQ)
|
||||
f.SetOperation(netmap.OpEQ)
|
||||
case "NE":
|
||||
f.SetOp(netmap.NE)
|
||||
f.SetOperation(netmap.OpNE)
|
||||
case "GE":
|
||||
f.SetOp(netmap.GE)
|
||||
f.SetOperation(netmap.OpGE)
|
||||
case "GT":
|
||||
f.SetOp(netmap.GT)
|
||||
f.SetOperation(netmap.OpGT)
|
||||
case "LE":
|
||||
f.SetOp(netmap.LE)
|
||||
f.SetOperation(netmap.OpLE)
|
||||
case "LT":
|
||||
f.SetOp(netmap.LT)
|
||||
f.SetOperation(netmap.OpLT)
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: '%s'", ErrUnknownOp, se.Op)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestSimple(t *testing.T) {
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestSimpleWithHRWB(t *testing.T) {
|
||||
|
@ -30,7 +30,7 @@ func TestSimpleWithHRWB(t *testing.T) {
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestFromSelect(t *testing.T) {
|
||||
|
@ -45,7 +45,7 @@ SELECT 1 IN City FROM * AS SPB`
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
// https://github.com/nspcc-dev/neofs-node/issues/46
|
||||
|
@ -61,7 +61,7 @@ func TestFromSelectNoAttribute(t *testing.T) {
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
|
||||
})
|
||||
|
||||
|
@ -77,7 +77,7 @@ func TestFromSelectNoAttribute(t *testing.T) {
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ SELECT 1 IN DISTINCT Continent FROM *`
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestSimpleFilter(t *testing.T) {
|
||||
|
@ -115,7 +115,7 @@ FILTER Rating GT 7 AS Good`
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestFilterReference(t *testing.T) {
|
||||
|
@ -137,7 +137,7 @@ FILTER @FromRU AND Rating GT 7 AS Good`
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestFilterOps(t *testing.T) {
|
||||
|
@ -162,7 +162,7 @@ FILTER A GT 1 AND B GE 2 AND C LT 3 AND D LE 4
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestWithFilterPrecedence(t *testing.T) {
|
||||
|
@ -186,7 +186,7 @@ FILTER City EQ "SPB" AND SSD EQ true OR City EQ "SPB" AND Rating GE 5 AS SPBSSD`
|
|||
|
||||
r, err := Parse(q)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, r)
|
||||
require.EqualValues(t, expected, r)
|
||||
}
|
||||
|
||||
func TestValidation(t *testing.T) {
|
||||
|
|
|
@ -174,14 +174,14 @@ func lookupKeyInContainer(
|
|||
owner, cid []byte,
|
||||
cnr *container.Container) (bool, error) {
|
||||
|
||||
cnrNodes, err := nm.GetContainerNodes(cnr.GetPlacementPolicy(), cid)
|
||||
cnrNodes, err := nm.GetContainerNodes(netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()), cid)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
flatCnrNodes := cnrNodes.Flatten() // we need single array to iterate on
|
||||
for i := range flatCnrNodes {
|
||||
if bytes.Equal(flatCnrNodes[i].InfoV2.GetPublicKey(), owner) {
|
||||
if bytes.Equal(flatCnrNodes[i].PublicKey(), owner) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmap.Pla
|
|||
|
||||
for i := range vs {
|
||||
for j := range vs[i] {
|
||||
addr, err := network.AddressFromString(vs[i][j].NetworkAddress())
|
||||
addr, err := network.AddressFromString(vs[i][j].Address())
|
||||
if err != nil {
|
||||
// TODO: log error
|
||||
continue
|
||||
|
|
|
@ -77,14 +77,14 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
|
|||
return nil, errors.Wrap(err, "could not build placement")
|
||||
}
|
||||
|
||||
rs := cfg.policy.GetReplicas()
|
||||
rs := cfg.policy.Replicas()
|
||||
rem := make([]int, 0, len(rs))
|
||||
|
||||
for i := range rs {
|
||||
cnt := cfg.rem
|
||||
|
||||
if cnt == 0 {
|
||||
cnt = int(rs[i].GetCount())
|
||||
cnt = int(rs[i].Count())
|
||||
}
|
||||
|
||||
rem = append(rem, cnt)
|
||||
|
@ -120,7 +120,7 @@ func (t *Traverser) Next() []*network.Address {
|
|||
addrs := make([]*network.Address, 0, count)
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
addr, err := network.AddressFromString(t.vectors[0][i].NetworkAddress())
|
||||
addr, err := network.AddressFromString(t.vectors[0][i].Address())
|
||||
if err != nil {
|
||||
// TODO: log error
|
||||
return nil
|
||||
|
@ -181,7 +181,7 @@ func UseBuilder(b Builder) Option {
|
|||
// ForContainer is a traversal container setting option.
|
||||
func ForContainer(cnr *container.Container) Option {
|
||||
return func(c *cfg) {
|
||||
c.policy = cnr.GetPlacementPolicy()
|
||||
c.policy = netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy())
|
||||
c.addr.SetContainerID(container.CalculateID(cnr))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
netmapV2 "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -19,8 +18,7 @@ func (b testBuilder) BuildPlacement(*object.Address, *netmap.PlacementPolicy) ([
|
|||
return b.vectors, nil
|
||||
}
|
||||
|
||||
func testNode(v uint32) netmapV2.NodeInfo {
|
||||
n := netmapV2.NodeInfo{}
|
||||
func testNode(v uint32) (n netmap.NodeInfo) {
|
||||
n.SetAddress("/ip4/0.0.0.0/tcp/" + strconv.Itoa(int(v)))
|
||||
|
||||
return n
|
||||
|
@ -55,14 +53,14 @@ func testPlacement(t *testing.T, ss, rs []int) ([]netmap.Nodes, *container.Conta
|
|||
num := uint32(0)
|
||||
|
||||
for i := range ss {
|
||||
ns := make([]netmapV2.NodeInfo, 0, ss[i])
|
||||
ns := make([]netmap.NodeInfo, 0, ss[i])
|
||||
|
||||
for j := 0; j < ss[i]; j++ {
|
||||
ns = append(ns, testNode(num))
|
||||
num++
|
||||
}
|
||||
|
||||
nodes = append(nodes, netmap.NodesFromV2(ns))
|
||||
nodes = append(nodes, netmap.NodesFromInfo(ns))
|
||||
|
||||
s := new(netmap.Replica)
|
||||
s.SetCount(uint32(rs[i]))
|
||||
|
@ -71,7 +69,7 @@ func testPlacement(t *testing.T, ss, rs []int) ([]netmap.Nodes, *container.Conta
|
|||
}
|
||||
|
||||
policy := new(netmap.PlacementPolicy)
|
||||
policy.SetReplicas(replicas)
|
||||
policy.SetReplicas(replicas...)
|
||||
|
||||
return nodes, container.New(container.WithPolicy(policy))
|
||||
}
|
||||
|
@ -98,7 +96,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
require.Len(t, addrs, len(nodes[i]))
|
||||
|
||||
for j, n := range nodes[i] {
|
||||
require.Equal(t, n.NetworkAddress(), addrs[j].String())
|
||||
require.Equal(t, n.Address(), addrs[j].String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +124,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
addrs := tr.Next()
|
||||
require.Len(t, addrs, 1)
|
||||
|
||||
require.Equal(t, nodes[curVector][i].NetworkAddress(), addrs[0].String())
|
||||
require.Equal(t, nodes[curVector][i].Address(), addrs[0].String())
|
||||
}
|
||||
|
||||
require.Empty(t, tr.Next())
|
||||
|
@ -166,7 +164,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
require.Len(t, addrs, replicas[curVector])
|
||||
|
||||
for j := range addrs {
|
||||
require.Equal(t, nodes[curVector][i+j].NetworkAddress(), addrs[j].String())
|
||||
require.Equal(t, nodes[curVector][i+j].Address(), addrs[j].String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
|||
return
|
||||
}
|
||||
|
||||
policy := cnr.GetPlacementPolicy()
|
||||
policy := netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy())
|
||||
|
||||
nn, err := p.placementBuilder.BuildPlacement(addr, policy)
|
||||
if err != nil {
|
||||
|
@ -33,7 +33,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
|||
return
|
||||
}
|
||||
|
||||
replicas := policy.GetReplicas()
|
||||
replicas := policy.Replicas()
|
||||
|
||||
for i := range nn {
|
||||
select {
|
||||
|
@ -42,7 +42,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
|||
default:
|
||||
}
|
||||
|
||||
p.processNodes(ctx, addr, nn[i], replicas[i].GetCount())
|
||||
p.processNodes(ctx, addr, nn[i], replicas[i].Count())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes
|
|||
default:
|
||||
}
|
||||
|
||||
netAddr := nodes[i].NetworkAddress()
|
||||
netAddr := nodes[i].Address()
|
||||
|
||||
log := p.log.With(zap.String("node", netAddr))
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ func (p *Replicator) handleTask(ctx context.Context, task *Task) {
|
|||
default:
|
||||
}
|
||||
|
||||
netAddr := task.nodes[i].NetworkAddress()
|
||||
netAddr := task.nodes[i].Address()
|
||||
|
||||
log := p.log.With(zap.String("node", netAddr))
|
||||
|
||||
|
|
Loading…
Reference in New Issue