From 3604d96f3fe1955f4129c8a884c66c220218a3c3 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 1 Dec 2021 16:42:31 +0300 Subject: [PATCH] [#362] netmap: Add marshaling of the subnetID field of container policy Signed-off-by: Pavel Karpy --- netmap/convert.go | 15 +++++++++++++++ netmap/grpc/types.go | 9 +++++++++ netmap/marshal.go | 8 ++++++++ netmap/test/generate.go | 1 + 4 files changed, 33 insertions(+) diff --git a/netmap/convert.go b/netmap/convert.go index e0595929..8325c949 100644 --- a/netmap/convert.go +++ b/netmap/convert.go @@ -216,6 +216,7 @@ func (p *PlacementPolicy) ToGRPCMessage() grpc.Message { m.SetSelectors(SelectorsToGRPC(p.selectors)) m.SetReplicas(ReplicasToGRPC(p.replicas)) m.SetContainerBackupFactor(p.backupFactor) + m.SetSubnetID(p.subnetID.ToGRPCMessage().(*refsGRPC.SubnetID)) } return m @@ -244,6 +245,20 @@ func (p *PlacementPolicy) FromGRPCMessage(m grpc.Message) error { return err } + subnetID := v.GetSubnetId() + if subnetID == nil { + p.subnetID = nil + } else { + if p.subnetID == nil { + p.subnetID = new(refs.SubnetID) + } + + err = p.subnetID.FromGRPCMessage(subnetID) + if err != nil { + return err + } + } + p.backupFactor = v.GetContainerBackupFactor() return nil diff --git a/netmap/grpc/types.go b/netmap/grpc/types.go index e8dc6876..95b0acc4 100644 --- a/netmap/grpc/types.go +++ b/netmap/grpc/types.go @@ -1,5 +1,7 @@ package netmap +import refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + // SetReplicas of placement policy. func (m *PlacementPolicy) SetReplicas(v []*Replica) { if m != nil { @@ -28,6 +30,13 @@ func (m *PlacementPolicy) SetFilters(v []*Filter) { } } +// SetSubnetID sets ID of subnet. +func (m *PlacementPolicy) SetSubnetID(v *refs.SubnetID) { + if m != nil { + m.SubnetId = v + } +} + // SetName of placement filter. func (m *Filter) SetName(v string) { if m != nil { diff --git a/netmap/marshal.go b/netmap/marshal.go index d2521112..b29e7507 100644 --- a/netmap/marshal.go +++ b/netmap/marshal.go @@ -26,6 +26,7 @@ const ( backupPolicyField = 2 selectorsPolicyField = 3 filtersPolicyField = 4 + subnetIDPolicyField = 5 keyAttributeField = 1 valueAttributeField = 2 @@ -262,6 +263,11 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) ([]byte, error) { offset += n } + _, err = protoutil.NestedStructureMarshal(subnetIDPolicyField, buf[offset:], p.subnetID) + if err != nil { + return nil, err + } + return buf, nil } @@ -280,6 +286,8 @@ func (p *PlacementPolicy) StableSize() (size int) { size += protoutil.NestedStructureSize(filtersPolicyField, p.filters[i]) } + size += protoutil.NestedStructureSize(subnetIDPolicyField, p.subnetID) + return size } diff --git a/netmap/test/generate.go b/netmap/test/generate.go index be07f128..93e2ff38 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -102,6 +102,7 @@ func GeneratePlacementPolicy(empty bool) *netmap.PlacementPolicy { m.SetFilters(GenerateFilters(false)) m.SetSelectors(GenerateSelectors(false)) m.SetReplicas(GenerateReplicas(false)) + m.SetSubnetID(refstest.GenerateSubnetID(false)) } return m