From f6e56aa95681a975cfb36d651082e182da020952 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 21 Oct 2020 12:19:58 +0300 Subject: [PATCH] [#108] placement: Implement Builder from netmap source Implement placement.Builder interface on netmap.Source wrapper. Signed-off-by: Leonard Lyubich --- .../object_manager/placement/netmap.go | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/pkg/services/object_manager/placement/netmap.go b/pkg/services/object_manager/placement/netmap.go index c9abd8137..d08724eda 100644 --- a/pkg/services/object_manager/placement/netmap.go +++ b/pkg/services/object_manager/placement/netmap.go @@ -1,25 +1,45 @@ package placement import ( - "github.com/nspcc-dev/neofs-api-go/pkg/netmap" + netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/pkg/errors" ) type netMapBuilder struct { - nm *netmap.Netmap + nmSrc netmap.Source } -func NewNetworkMapBuilder(nm *netmap.Netmap) Builder { +type netMapSrc struct { + nm *netmapSDK.Netmap +} + +func NewNetworkMapBuilder(nm *netmapSDK.Netmap) Builder { return &netMapBuilder{ - nm: nm, + nmSrc: &netMapSrc{nm}, } } -func (b *netMapBuilder) BuildPlacement(a *object.Address, p *netmap.PlacementPolicy) ([]netmap.Nodes, error) { +func NewNetworkMapSourceBuilder(nmSrc netmap.Source) Builder { + return &netMapBuilder{ + nmSrc: nmSrc, + } +} + +func (s *netMapSrc) GetNetMap(diff uint64) (*netmapSDK.Netmap, error) { + return s.nm, nil +} + +func (b *netMapBuilder) BuildPlacement(a *object.Address, p *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { + nm, err := netmap.GetLatestNetworkMap(b.nmSrc) + if err != nil { + return nil, errors.Wrap(err, "could not get network map") + } + aV2 := a.ToV2() - cn, err := b.nm.GetContainerNodes(p, aV2.GetContainerID().GetValue()) + cn, err := nm.GetContainerNodes(p, aV2.GetContainerID().GetValue()) if err != nil { return nil, errors.Wrap(err, "could not get container nodes") } @@ -29,7 +49,7 @@ func (b *netMapBuilder) BuildPlacement(a *object.Address, p *netmap.PlacementPol return cn.Replicas(), nil } - on, err := b.nm.GetPlacementVectors(cn, oid.GetValue()) + on, err := nm.GetPlacementVectors(cn, oid.GetValue()) if err != nil { return nil, errors.Wrap(err, "could not get placement vectors for object") }