[#339] services/netmap: Use dynamic node information
Replace static NodeInfo structure with NodeState interface that provides method to read node information in runtime. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f83fbe1422
commit
c77d346016
1 changed files with 20 additions and 7 deletions
|
@ -9,27 +9,40 @@ import (
|
||||||
|
|
||||||
type executorSvc struct {
|
type executorSvc struct {
|
||||||
version *pkg.Version
|
version *pkg.Version
|
||||||
localNodeInfo *netmap.NodeInfo
|
state NodeState
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecutionService(ni *netmap.NodeInfo, v *pkg.Version) netmap.Service {
|
// NodeState encapsulates information
|
||||||
if ni == nil || v == nil {
|
// about current node state.
|
||||||
|
type NodeState interface {
|
||||||
|
// Must return current node state
|
||||||
|
// in NeoFS API v2 NodeInfo structure.
|
||||||
|
LocalNodeInfo() (*netmap.NodeInfo, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExecutionService(s NodeState, v *pkg.Version) netmap.Service {
|
||||||
|
if s == nil || v == nil {
|
||||||
// this should never happen, otherwise it programmers bug
|
// this should never happen, otherwise it programmers bug
|
||||||
panic("can't create netmap execution service")
|
panic("can't create netmap execution service")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &executorSvc{
|
return &executorSvc{
|
||||||
version: v,
|
version: v,
|
||||||
localNodeInfo: ni,
|
state: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *executorSvc) LocalNodeInfo(
|
func (s *executorSvc) LocalNodeInfo(
|
||||||
_ context.Context,
|
_ context.Context,
|
||||||
_ *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
|
_ *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
|
||||||
|
ni, err := s.state.LocalNodeInfo()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
body := new(netmap.LocalNodeInfoResponseBody)
|
body := new(netmap.LocalNodeInfoResponseBody)
|
||||||
body.SetVersion(s.version.ToV2())
|
body.SetVersion(s.version.ToV2())
|
||||||
body.SetNodeInfo(s.localNodeInfo)
|
body.SetNodeInfo(ni)
|
||||||
|
|
||||||
resp := new(netmap.LocalNodeInfoResponse)
|
resp := new(netmap.LocalNodeInfoResponse)
|
||||||
resp.SetBody(body)
|
resp.SetBody(body)
|
||||||
|
|
Loading…
Reference in a new issue