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>
This commit is contained in:
parent
9f8eb0fd51
commit
65be09d3db
16 changed files with 100 additions and 125 deletions
|
@ -139,7 +139,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
||||||
}
|
}
|
||||||
|
|
||||||
cnr := container.New()
|
cnr := container.New()
|
||||||
cnr.SetPlacementPolicy(placementPolicy)
|
cnr.SetPlacementPolicy(placementPolicy.ToV2())
|
||||||
cnr.SetBasicACL(basicACL)
|
cnr.SetBasicACL(basicACL)
|
||||||
cnr.SetAttributes(attributes)
|
cnr.SetAttributes(attributes)
|
||||||
cnr.SetNonce(nonce[:])
|
cnr.SetNonce(nonce[:])
|
||||||
|
@ -531,7 +531,7 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = policy.FromJSON([]byte(policyString))
|
result, err = netmap.PlacementPolicyFromJSON([]byte(policyString))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
printVerbose("Parsed JSON encoded policy")
|
printVerbose("Parsed JSON encoded policy")
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -684,7 +684,8 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("placement policy:")
|
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) {
|
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-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2
|
||||||
github.com/multiformats/go-multihash v0.0.13 // indirect
|
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/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/neofs-crypto v0.3.0
|
||||||
github.com/nspcc-dev/tzhash v1.4.0
|
github.com/nspcc-dev/tzhash v1.4.0
|
||||||
github.com/panjf2000/ants/v2 v2.3.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.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 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/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.20201106062850-d704795dcc7b h1:JYitHXAKvqJc4cgicDgDJY+d2JiKR77xdczGH+CqfUU=
|
||||||
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/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.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.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
|
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))
|
require.Error(t, CheckFormat(c))
|
||||||
|
|
||||||
policy := new(netmap.PlacementPolicy)
|
policy := new(netmap.PlacementPolicy)
|
||||||
c.SetPlacementPolicy(policy)
|
c.SetPlacementPolicy(policy.ToV2())
|
||||||
|
|
||||||
require.Error(t, CheckFormat(c))
|
require.Error(t, CheckFormat(c))
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]netmapv2.NodeInfo, 0, len(rawNodeInfos))
|
result := make([]netmap.NodeInfo, 0, len(rawNodeInfos))
|
||||||
|
|
||||||
for i := range rawNodeInfos {
|
for i := range rawNodeInfos {
|
||||||
nodeInfo, err := peerInfoFromStackItem(rawNodeInfos[i])
|
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")
|
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) {
|
func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) {
|
||||||
|
|
|
@ -6,26 +6,25 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"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"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/test"
|
"github.com/nspcc-dev/neofs-node/pkg/util/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCleanupTable(t *testing.T) {
|
func TestCleanupTable(t *testing.T) {
|
||||||
infos := []netmapv2.NodeInfo{
|
infos := []netmap.NodeInfo{
|
||||||
newNodeInfo(&test.DecodeKey(1).PublicKey),
|
newNodeInfo(&test.DecodeKey(1).PublicKey),
|
||||||
newNodeInfo(&test.DecodeKey(2).PublicKey),
|
newNodeInfo(&test.DecodeKey(2).PublicKey),
|
||||||
newNodeInfo(&test.DecodeKey(3).PublicKey),
|
newNodeInfo(&test.DecodeKey(3).PublicKey),
|
||||||
}
|
}
|
||||||
|
|
||||||
networkMap, err := netmap.NewNetmap(netmap.NodesFromV2(infos))
|
networkMap, err := netmap.NewNetmap(netmap.NodesFromInfo(infos))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
mapInfos := map[string]struct{}{
|
mapInfos := map[string]struct{}{
|
||||||
hex.EncodeToString(infos[0].GetPublicKey()): {},
|
hex.EncodeToString(infos[0].PublicKey()): {},
|
||||||
hex.EncodeToString(infos[1].GetPublicKey()): {},
|
hex.EncodeToString(infos[1].PublicKey()): {},
|
||||||
hex.EncodeToString(infos[2].GetPublicKey()): {},
|
hex.EncodeToString(infos[2].PublicKey()): {},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("update", func(t *testing.T) {
|
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) {
|
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.flag(key)
|
||||||
|
|
||||||
c.update(networkMap, 2)
|
c.update(networkMap, 2)
|
||||||
|
@ -55,7 +54,7 @@ func TestCleanupTable(t *testing.T) {
|
||||||
c := newCleanupTable(true, 1)
|
c := newCleanupTable(true, 1)
|
||||||
c.update(networkMap, 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.True(t, c.touch(key, 11))
|
||||||
require.EqualValues(t, 11, c.lastAccess[key].epoch)
|
require.EqualValues(t, 11, c.lastAccess[key].epoch)
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ func TestCleanupTable(t *testing.T) {
|
||||||
c := newCleanupTable(true, 1)
|
c := newCleanupTable(true, 1)
|
||||||
c.update(networkMap, 1)
|
c.update(networkMap, 1)
|
||||||
|
|
||||||
key := hex.EncodeToString(infos[1].GetPublicKey())
|
key := hex.EncodeToString(infos[1].PublicKey())
|
||||||
c.flag(key)
|
c.flag(key)
|
||||||
require.True(t, c.lastAccess[key].removeFlag)
|
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) {
|
t.Run("some nodes to remove", func(t *testing.T) {
|
||||||
cnt := 0
|
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
|
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))
|
n.SetPublicKey(crypto.MarshalPublicKey(key))
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (w Wrapper) GetNetMap(diff uint64) (*netmap.Netmap, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rawPeers := peers.Peers() // slice of serialized node infos
|
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 {
|
for _, peer := range rawPeers {
|
||||||
grpcNodeInfo := new(grpcNetmap.NodeInfo) // transport representation of struct
|
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)
|
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)
|
return netmap.NewNetmap(nodes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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 {
|
func Encode(p *netmap.PlacementPolicy) []string {
|
||||||
|
@ -14,9 +14,9 @@ func Encode(p *netmap.PlacementPolicy) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
replicas = p.GetReplicas()
|
replicas = p.Replicas()
|
||||||
selectors = p.GetSelectors()
|
selectors = p.Selectors()
|
||||||
filters = p.GetFilters()
|
filters = p.Filters()
|
||||||
)
|
)
|
||||||
|
|
||||||
// 1 for container backup factor
|
// 1 for container backup factor
|
||||||
|
@ -26,7 +26,7 @@ func Encode(p *netmap.PlacementPolicy) []string {
|
||||||
encodeReplicas(replicas, &result)
|
encodeReplicas(replicas, &result)
|
||||||
|
|
||||||
// then backup factor
|
// then backup factor
|
||||||
if backupFactor := p.GetContainerBackupFactor(); backupFactor != 0 {
|
if backupFactor := p.ContainerBackupFactor(); backupFactor != 0 {
|
||||||
result = append(result, fmt.Sprintf("CBF %d", backupFactor))
|
result = append(result, fmt.Sprintf("CBF %d", backupFactor))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ func encodeReplicas(replicas []*netmap.Replica, dst *[]string) {
|
||||||
|
|
||||||
for _, replica := range replicas {
|
for _, replica := range replicas {
|
||||||
builder.WriteString("REP ")
|
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(" IN ")
|
||||||
builder.WriteString(s)
|
builder.WriteString(s)
|
||||||
}
|
}
|
||||||
|
@ -61,15 +61,15 @@ func encodeSelectors(selectors []*netmap.Selector, dst *[]string) {
|
||||||
|
|
||||||
for _, selector := range selectors {
|
for _, selector := range selectors {
|
||||||
builder.WriteString("SELECT ")
|
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")
|
builder.WriteString(" IN")
|
||||||
|
|
||||||
switch selector.GetClause() {
|
switch selector.Clause() {
|
||||||
case netmap.Same:
|
case netmap.ClauseSame:
|
||||||
builder.WriteString(" SAME ")
|
builder.WriteString(" SAME ")
|
||||||
case netmap.Distinct:
|
case netmap.ClauseDistinct:
|
||||||
builder.WriteString(" DISTINCT ")
|
builder.WriteString(" DISTINCT ")
|
||||||
default:
|
default:
|
||||||
builder.WriteString(" ")
|
builder.WriteString(" ")
|
||||||
|
@ -78,12 +78,12 @@ func encodeSelectors(selectors []*netmap.Selector, dst *[]string) {
|
||||||
builder.WriteString(a)
|
builder.WriteString(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if f := selector.GetFilter(); f != "" {
|
if f := selector.Filter(); f != "" {
|
||||||
builder.WriteString(" FROM ")
|
builder.WriteString(" FROM ")
|
||||||
builder.WriteString(f)
|
builder.WriteString(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n := selector.GetName(); n != "" {
|
if n := selector.Name(); n != "" {
|
||||||
builder.WriteString(" AS ")
|
builder.WriteString(" AS ")
|
||||||
builder.WriteString(n)
|
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 {
|
func encodeFilter(filter *netmap.Filter) string {
|
||||||
builder := new(strings.Builder)
|
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(k)
|
||||||
builder.WriteString(" ")
|
builder.WriteString(" ")
|
||||||
builder.WriteString(operationString(filter.GetOp()))
|
builder.WriteString(filter.Operation().String())
|
||||||
builder.WriteString(" ")
|
builder.WriteString(" ")
|
||||||
builder.WriteString(filter.GetValue())
|
builder.WriteString(filter.Value())
|
||||||
} else if n := filter.GetName(); unspecified && n != "" {
|
} else if n := filter.Name(); unspecified && n != "" {
|
||||||
builder.WriteString("@")
|
builder.WriteString("@")
|
||||||
builder.WriteString(n)
|
builder.WriteString(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, subfilter := range filter.GetFilters() {
|
for i, subfilter := range filter.InnerFilters() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
builder.WriteString(" ")
|
builder.WriteString(" ")
|
||||||
builder.WriteString(operationString(filter.GetOp()))
|
builder.WriteString(filter.Operation().String())
|
||||||
builder.WriteString(" ")
|
builder.WriteString(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.WriteString(encodeFilter(subfilter))
|
builder.WriteString(encodeFilter(subfilter))
|
||||||
}
|
}
|
||||||
|
|
||||||
if n := filter.GetName(); n != "" && !unspecified {
|
if n := filter.Name(); n != "" && !unspecified {
|
||||||
builder.WriteString(" AS ")
|
builder.WriteString(" AS ")
|
||||||
builder.WriteString(n)
|
builder.WriteString(n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
sdknm "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -48,10 +47,10 @@ func Parse(s string) (*netmap.PlacementPolicy, error) {
|
||||||
seenSelectors := map[string]bool{}
|
seenSelectors := map[string]bool{}
|
||||||
ss := make([]*netmap.Selector, 0, len(q.Selectors))
|
ss := make([]*netmap.Selector, 0, len(q.Selectors))
|
||||||
for _, qs := range 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)
|
return nil, fmt.Errorf("%w: '%s'", ErrUnknownFilter, qs.Filter)
|
||||||
}
|
}
|
||||||
s := new(netmap.Selector)
|
s := netmap.NewSelector()
|
||||||
switch len(qs.Bucket) {
|
switch len(qs.Bucket) {
|
||||||
case 1: // only bucket
|
case 1: // only bucket
|
||||||
s.SetAttribute(qs.Bucket[0])
|
s.SetAttribute(qs.Bucket[0])
|
||||||
|
@ -71,7 +70,7 @@ func Parse(s string) (*netmap.PlacementPolicy, error) {
|
||||||
|
|
||||||
rs := make([]*netmap.Replica, 0, len(q.Replicas))
|
rs := make([]*netmap.Replica, 0, len(q.Replicas))
|
||||||
for _, qr := range q.Replicas {
|
for _, qr := range q.Replicas {
|
||||||
r := new(netmap.Replica)
|
r := netmap.NewReplica()
|
||||||
if qr.Selector != "" {
|
if qr.Selector != "" {
|
||||||
if !seenSelectors[qr.Selector] {
|
if !seenSelectors[qr.Selector] {
|
||||||
return nil, fmt.Errorf("%w: '%s'", ErrUnknownSelector, 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 := new(netmap.PlacementPolicy)
|
||||||
p.SetFilters(fs)
|
p.SetFilters(fs...)
|
||||||
p.SetSelectors(ss)
|
p.SetSelectors(ss...)
|
||||||
p.SetReplicas(rs)
|
p.SetReplicas(rs...)
|
||||||
p.SetContainerBackupFactor(q.CBF)
|
p.SetContainerBackupFactor(q.CBF)
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func clauseFromString(s string) netmap.Clause {
|
func clauseFromString(s string) netmap.Clause {
|
||||||
switch strings.ToUpper(s) {
|
switch strings.ToUpper(s) {
|
||||||
case "SAME":
|
case "SAME":
|
||||||
return netmap.Same
|
return netmap.ClauseSame
|
||||||
case "DISTINCT":
|
case "DISTINCT":
|
||||||
return netmap.Distinct
|
return netmap.ClauseDistinct
|
||||||
default:
|
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
|
return fs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f := new(netmap.Filter)
|
f := netmap.NewFilter()
|
||||||
f.SetOp(netmap.OR)
|
f.SetOperation(netmap.OpOR)
|
||||||
f.SetFilters(fs)
|
f.SetInnerFilters(fs...)
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ func filterFromAndChain(expr *andChain, seen map[string]bool) (*netmap.Filter, e
|
||||||
if fe.Expr != nil {
|
if fe.Expr != nil {
|
||||||
f, err = filterFromSimpleExpr(fe.Expr, seen)
|
f, err = filterFromSimpleExpr(fe.Expr, seen)
|
||||||
} else {
|
} else {
|
||||||
f = new(netmap.Filter)
|
f = netmap.NewFilter()
|
||||||
f.SetName(fe.Reference)
|
f.SetName(fe.Reference)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -143,28 +143,28 @@ func filterFromAndChain(expr *andChain, seen map[string]bool) (*netmap.Filter, e
|
||||||
return fs[0], nil
|
return fs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f := new(netmap.Filter)
|
f := netmap.NewFilter()
|
||||||
f.SetOp(netmap.AND)
|
f.SetOperation(netmap.OpAND)
|
||||||
f.SetFilters(fs)
|
f.SetInnerFilters(fs...)
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterFromSimpleExpr(se *simpleExpr, seen map[string]bool) (*netmap.Filter, error) {
|
func filterFromSimpleExpr(se *simpleExpr, seen map[string]bool) (*netmap.Filter, error) {
|
||||||
f := new(netmap.Filter)
|
f := netmap.NewFilter()
|
||||||
f.SetKey(se.Key)
|
f.SetKey(se.Key)
|
||||||
switch se.Op {
|
switch se.Op {
|
||||||
case "EQ":
|
case "EQ":
|
||||||
f.SetOp(netmap.EQ)
|
f.SetOperation(netmap.OpEQ)
|
||||||
case "NE":
|
case "NE":
|
||||||
f.SetOp(netmap.NE)
|
f.SetOperation(netmap.OpNE)
|
||||||
case "GE":
|
case "GE":
|
||||||
f.SetOp(netmap.GE)
|
f.SetOperation(netmap.OpGE)
|
||||||
case "GT":
|
case "GT":
|
||||||
f.SetOp(netmap.GT)
|
f.SetOperation(netmap.OpGT)
|
||||||
case "LE":
|
case "LE":
|
||||||
f.SetOp(netmap.LE)
|
f.SetOperation(netmap.OpLE)
|
||||||
case "LT":
|
case "LT":
|
||||||
f.SetOp(netmap.LT)
|
f.SetOperation(netmap.OpLT)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%w: '%s'", ErrUnknownOp, se.Op)
|
return nil, fmt.Errorf("%w: '%s'", ErrUnknownOp, se.Op)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestSimple(t *testing.T) {
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleWithHRWB(t *testing.T) {
|
func TestSimpleWithHRWB(t *testing.T) {
|
||||||
|
@ -30,7 +30,7 @@ func TestSimpleWithHRWB(t *testing.T) {
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromSelect(t *testing.T) {
|
func TestFromSelect(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ SELECT 1 IN City FROM * AS SPB`
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/nspcc-dev/neofs-node/issues/46
|
// https://github.com/nspcc-dev/neofs-node/issues/46
|
||||||
|
@ -61,7 +61,7 @@ func TestFromSelectNoAttribute(t *testing.T) {
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
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)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
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)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleFilter(t *testing.T) {
|
func TestSimpleFilter(t *testing.T) {
|
||||||
|
@ -115,7 +115,7 @@ FILTER Rating GT 7 AS Good`
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterReference(t *testing.T) {
|
func TestFilterReference(t *testing.T) {
|
||||||
|
@ -137,7 +137,7 @@ FILTER @FromRU AND Rating GT 7 AS Good`
|
||||||
|
|
||||||
r, err := Parse(q)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterOps(t *testing.T) {
|
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)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithFilterPrecedence(t *testing.T) {
|
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)
|
r, err := Parse(q)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected, r)
|
require.EqualValues(t, expected, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidation(t *testing.T) {
|
func TestValidation(t *testing.T) {
|
||||||
|
|
|
@ -174,14 +174,14 @@ func lookupKeyInContainer(
|
||||||
owner, cid []byte,
|
owner, cid []byte,
|
||||||
cnr *container.Container) (bool, error) {
|
cnr *container.Container) (bool, error) {
|
||||||
|
|
||||||
cnrNodes, err := nm.GetContainerNodes(cnr.GetPlacementPolicy(), cid)
|
cnrNodes, err := nm.GetContainerNodes(netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()), cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
flatCnrNodes := cnrNodes.Flatten() // we need single array to iterate on
|
flatCnrNodes := cnrNodes.Flatten() // we need single array to iterate on
|
||||||
for i := range flatCnrNodes {
|
for i := range flatCnrNodes {
|
||||||
if bytes.Equal(flatCnrNodes[i].InfoV2.GetPublicKey(), owner) {
|
if bytes.Equal(flatCnrNodes[i].PublicKey(), owner) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmap.Pla
|
||||||
|
|
||||||
for i := range vs {
|
for i := range vs {
|
||||||
for j := range vs[i] {
|
for j := range vs[i] {
|
||||||
addr, err := network.AddressFromString(vs[i][j].NetworkAddress())
|
addr, err := network.AddressFromString(vs[i][j].Address())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: log error
|
// TODO: log error
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -77,14 +77,14 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
|
||||||
return nil, errors.Wrap(err, "could not build placement")
|
return nil, errors.Wrap(err, "could not build placement")
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := cfg.policy.GetReplicas()
|
rs := cfg.policy.Replicas()
|
||||||
rem := make([]int, 0, len(rs))
|
rem := make([]int, 0, len(rs))
|
||||||
|
|
||||||
for i := range rs {
|
for i := range rs {
|
||||||
cnt := cfg.rem
|
cnt := cfg.rem
|
||||||
|
|
||||||
if cnt == 0 {
|
if cnt == 0 {
|
||||||
cnt = int(rs[i].GetCount())
|
cnt = int(rs[i].Count())
|
||||||
}
|
}
|
||||||
|
|
||||||
rem = append(rem, cnt)
|
rem = append(rem, cnt)
|
||||||
|
@ -120,7 +120,7 @@ func (t *Traverser) Next() []*network.Address {
|
||||||
addrs := make([]*network.Address, 0, count)
|
addrs := make([]*network.Address, 0, count)
|
||||||
|
|
||||||
for i := 0; i < count; i++ {
|
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 {
|
if err != nil {
|
||||||
// TODO: log error
|
// TODO: log error
|
||||||
return nil
|
return nil
|
||||||
|
@ -181,7 +181,7 @@ func UseBuilder(b Builder) Option {
|
||||||
// ForContainer is a traversal container setting option.
|
// ForContainer is a traversal container setting option.
|
||||||
func ForContainer(cnr *container.Container) Option {
|
func ForContainer(cnr *container.Container) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.policy = cnr.GetPlacementPolicy()
|
c.policy = netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy())
|
||||||
c.addr.SetContainerID(container.CalculateID(cnr))
|
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/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"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"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,8 +18,7 @@ func (b testBuilder) BuildPlacement(*object.Address, *netmap.PlacementPolicy) ([
|
||||||
return b.vectors, nil
|
return b.vectors, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNode(v uint32) netmapV2.NodeInfo {
|
func testNode(v uint32) (n netmap.NodeInfo) {
|
||||||
n := netmapV2.NodeInfo{}
|
|
||||||
n.SetAddress("/ip4/0.0.0.0/tcp/" + strconv.Itoa(int(v)))
|
n.SetAddress("/ip4/0.0.0.0/tcp/" + strconv.Itoa(int(v)))
|
||||||
|
|
||||||
return n
|
return n
|
||||||
|
@ -55,14 +53,14 @@ func testPlacement(t *testing.T, ss, rs []int) ([]netmap.Nodes, *container.Conta
|
||||||
num := uint32(0)
|
num := uint32(0)
|
||||||
|
|
||||||
for i := range ss {
|
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++ {
|
for j := 0; j < ss[i]; j++ {
|
||||||
ns = append(ns, testNode(num))
|
ns = append(ns, testNode(num))
|
||||||
num++
|
num++
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes = append(nodes, netmap.NodesFromV2(ns))
|
nodes = append(nodes, netmap.NodesFromInfo(ns))
|
||||||
|
|
||||||
s := new(netmap.Replica)
|
s := new(netmap.Replica)
|
||||||
s.SetCount(uint32(rs[i]))
|
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 := new(netmap.PlacementPolicy)
|
||||||
policy.SetReplicas(replicas)
|
policy.SetReplicas(replicas...)
|
||||||
|
|
||||||
return nodes, container.New(container.WithPolicy(policy))
|
return nodes, container.New(container.WithPolicy(policy))
|
||||||
}
|
}
|
||||||
|
@ -98,7 +96,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
require.Len(t, addrs, len(nodes[i]))
|
require.Len(t, addrs, len(nodes[i]))
|
||||||
|
|
||||||
for j, n := range 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()
|
addrs := tr.Next()
|
||||||
require.Len(t, addrs, 1)
|
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())
|
require.Empty(t, tr.Next())
|
||||||
|
@ -166,7 +164,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
require.Len(t, addrs, replicas[curVector])
|
require.Len(t, addrs, replicas[curVector])
|
||||||
|
|
||||||
for j := range addrs {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
policy := cnr.GetPlacementPolicy()
|
policy := netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy())
|
||||||
|
|
||||||
nn, err := p.placementBuilder.BuildPlacement(addr, policy)
|
nn, err := p.placementBuilder.BuildPlacement(addr, policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,7 +33,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
replicas := policy.GetReplicas()
|
replicas := policy.Replicas()
|
||||||
|
|
||||||
for i := range nn {
|
for i := range nn {
|
||||||
select {
|
select {
|
||||||
|
@ -42,7 +42,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
||||||
default:
|
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:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
netAddr := nodes[i].NetworkAddress()
|
netAddr := nodes[i].Address()
|
||||||
|
|
||||||
log := p.log.With(zap.String("node", netAddr))
|
log := p.log.With(zap.String("node", netAddr))
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (p *Replicator) handleTask(ctx context.Context, task *Task) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
netAddr := task.nodes[i].NetworkAddress()
|
netAddr := task.nodes[i].Address()
|
||||||
|
|
||||||
log := p.log.With(zap.String("node", netAddr))
|
log := p.log.With(zap.String("node", netAddr))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue