forked from TrueCloudLab/frostfs-node
[#398] cmd/node: Serve NetmapService.NetworkInfo RPC
Implement `NetworkInfo` calls on full stack of Netmap services. Current epoch is read from node local state, magic number is read via `MagicNumber` call of morph client. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4c8d29ce46
commit
9073e198b9
7 changed files with 107 additions and 13 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
type executorSvc struct {
|
||||
version *pkg.Version
|
||||
state NodeState
|
||||
|
||||
netInfo NetworkInfo
|
||||
}
|
||||
|
||||
// NodeState encapsulates information
|
||||
|
@ -20,8 +22,16 @@ type NodeState interface {
|
|||
LocalNodeInfo() (*netmap.NodeInfo, error)
|
||||
}
|
||||
|
||||
func NewExecutionService(s NodeState, v *pkg.Version) netmap.Service {
|
||||
if s == nil || v == nil {
|
||||
// NetworkInfo encapsulates source of the
|
||||
// recent information about the NeoFS network.
|
||||
type NetworkInfo interface {
|
||||
// Must return recent network information.
|
||||
// in NeoFS API v2 NetworkInfo structure.
|
||||
Dump() (*netmap.NetworkInfo, error)
|
||||
}
|
||||
|
||||
func NewExecutionService(s NodeState, v *pkg.Version, netInfo NetworkInfo) netmap.Service {
|
||||
if s == nil || v == nil || netInfo == nil {
|
||||
// this should never happen, otherwise it programmers bug
|
||||
panic("can't create netmap execution service")
|
||||
}
|
||||
|
@ -29,6 +39,7 @@ func NewExecutionService(s NodeState, v *pkg.Version) netmap.Service {
|
|||
return &executorSvc{
|
||||
version: v,
|
||||
state: s,
|
||||
netInfo: netInfo,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,3 +60,20 @@ func (s *executorSvc) LocalNodeInfo(
|
|||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *executorSvc) NetworkInfo(
|
||||
_ context.Context,
|
||||
_ *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
|
||||
ni, err := s.netInfo.Dump()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := new(netmap.NetworkInfoResponseBody)
|
||||
body.SetNetworkInfo(ni)
|
||||
|
||||
resp := new(netmap.NetworkInfoResponse)
|
||||
resp.SetBody(body)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue