forked from TrueCloudLab/frostfs-node
[#35] Implement netmap source interface in morph wrapper
Netmap source interface used by object service to build placement based on current or previous network map. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
92fb384c09
commit
99d380c20b
1 changed files with 37 additions and 6 deletions
|
@ -1,12 +1,43 @@
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
// NetMap represents the NeoFS network map.
|
import (
|
||||||
// FIXME: correct the definition.
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
type NetMap struct{}
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
|
grpcNetmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
||||||
|
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
// GetNetMap receives information list about storage nodes
|
// GetNetMap receives information list about storage nodes
|
||||||
// through the Netmap contract call, composes network map
|
// through the Netmap contract call, composes network map
|
||||||
// from them and returns it.
|
// from them and returns it. With diff == 0 returns current
|
||||||
func (w *Wrapper) GetNetMap() (*NetMap, error) {
|
// network map, else return snapshot of previous network map.
|
||||||
panic("implement me")
|
func (w Wrapper) GetNetMap(diff uint64) (*netmap.Netmap, error) {
|
||||||
|
args := client.GetSnapshotArgs{}
|
||||||
|
args.SetDiff(diff)
|
||||||
|
|
||||||
|
peers, err := w.client.Snapshot(args)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rawPeers := peers.Peers() // slice of serialized node infos
|
||||||
|
infos := make([]v2netmap.NodeInfo, 0, len(rawPeers))
|
||||||
|
|
||||||
|
for _, peer := range rawPeers {
|
||||||
|
grpcNodeInfo := new(grpcNetmap.NodeInfo) // transport representation of struct
|
||||||
|
err = grpcNodeInfo.Unmarshal(peer)
|
||||||
|
if err != nil {
|
||||||
|
// consider unmarshalling into different major versions
|
||||||
|
// of NodeInfo structure, if there any
|
||||||
|
return nil, errors.Wrap(err, "can't unmarshal peer info")
|
||||||
|
}
|
||||||
|
|
||||||
|
v2 := v2netmap.NodeInfoFromGRPCMessage(grpcNodeInfo)
|
||||||
|
infos = append(infos, *v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes := netmap.NodesFromV2(infos)
|
||||||
|
|
||||||
|
return netmap.NewNetmap(nodes)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue