[#108] placement: Implement Builder from netmap source
Implement placement.Builder interface on netmap.Source wrapper. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
5017ff0e4a
commit
f6e56aa956
1 changed files with 27 additions and 7 deletions
|
@ -1,25 +1,45 @@
|
||||||
package placement
|
package placement
|
||||||
|
|
||||||
import (
|
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-api-go/pkg/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type netMapBuilder struct {
|
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{
|
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()
|
aV2 := a.ToV2()
|
||||||
|
|
||||||
cn, err := b.nm.GetContainerNodes(p, aV2.GetContainerID().GetValue())
|
cn, err := nm.GetContainerNodes(p, aV2.GetContainerID().GetValue())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not get container nodes")
|
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
|
return cn.Replicas(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
on, err := b.nm.GetPlacementVectors(cn, oid.GetValue())
|
on, err := nm.GetPlacementVectors(cn, oid.GetValue())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not get placement vectors for object")
|
return nil, errors.Wrap(err, "could not get placement vectors for object")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue