From 6b176e8769d82fd4ad4eda8c97aea643be1f26fa Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 11 Jun 2021 18:29:49 +0300 Subject: [PATCH] [#613] pkg/reputation: Move manager building to `pkg` Move `managers` package to `pkg` since it can be reused in other packages. Signed-off-by: Pavel Karpy --- cmd/neofs-node/reputation.go | 6 +++--- .../services}/reputation/common/managers.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) rename {cmd/neofs-node => pkg/services}/reputation/common/managers.go (88%) diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 7a4dc7c05..b4e02ebe9 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -68,11 +68,11 @@ func initReputationService(c *cfg) { LocalKey: localKey, } - managerBuilder := common.NewManagerBuilder( - common.ManagersPrm{ + managerBuilder := reputationcommon.NewManagerBuilder( + reputationcommon.ManagersPrm{ NetMapSource: nmSrc, }, - common.WithLogger(c.log), + reputationcommon.WithLogger(c.log), ) localRouteBuilder := localroutes.New( diff --git a/cmd/neofs-node/reputation/common/managers.go b/pkg/services/reputation/common/managers.go similarity index 88% rename from cmd/neofs-node/reputation/common/managers.go rename to pkg/services/reputation/common/managers.go index e9260a410..9cddc8094 100644 --- a/cmd/neofs-node/reputation/common/managers.go +++ b/pkg/services/reputation/common/managers.go @@ -2,12 +2,12 @@ package common import ( "bytes" + "fmt" "github.com/nspcc-dev/hrw" apiNetmap "github.com/nspcc-dev/neofs-api-go/pkg/netmap" netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" - "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -36,10 +36,10 @@ type ManagersPrm struct { // // The created managerBuilder does not require additional // initialization and is completely ready for work. -func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) common.ManagerBuilder { +func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) ManagerBuilder { switch { case prm.NetMapSource == nil: - PanicOnPrmValue("NetMapSource", prm.NetMapSource) + panic(fmt.Sprintf("invalid NetMapSource (%T):%v", prm.NetMapSource, prm.NetMapSource)) } o := defaultMngOpts() @@ -57,7 +57,7 @@ func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) common.ManagerBuilder // BuildManagers sorts nodes in NetMap with HRW algorithms and // takes the next node after the current one as the only manager. -func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]common.ServerInfo, error) { +func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error) { nm, err := mb.nmSrc.GetNetMapByEpoch(epoch) if err != nil { return nil, err @@ -78,7 +78,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]co managerIndex = 0 } - return []common.ServerInfo{nodes[managerIndex]}, nil + return []ServerInfo{nodes[managerIndex]}, nil } }