[#362] netmap: Add marshaling of the subnetID field of container policy

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-01 16:42:31 +03:00 committed by LeL
parent d93828f465
commit 3604d96f3f
4 changed files with 33 additions and 0 deletions

View file

@ -216,6 +216,7 @@ func (p *PlacementPolicy) ToGRPCMessage() grpc.Message {
m.SetSelectors(SelectorsToGRPC(p.selectors)) m.SetSelectors(SelectorsToGRPC(p.selectors))
m.SetReplicas(ReplicasToGRPC(p.replicas)) m.SetReplicas(ReplicasToGRPC(p.replicas))
m.SetContainerBackupFactor(p.backupFactor) m.SetContainerBackupFactor(p.backupFactor)
m.SetSubnetID(p.subnetID.ToGRPCMessage().(*refsGRPC.SubnetID))
} }
return m return m
@ -244,6 +245,20 @@ func (p *PlacementPolicy) FromGRPCMessage(m grpc.Message) error {
return err 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() p.backupFactor = v.GetContainerBackupFactor()
return nil return nil

View file

@ -1,5 +1,7 @@
package netmap package netmap
import refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
// SetReplicas of placement policy. // SetReplicas of placement policy.
func (m *PlacementPolicy) SetReplicas(v []*Replica) { func (m *PlacementPolicy) SetReplicas(v []*Replica) {
if m != nil { 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. // SetName of placement filter.
func (m *Filter) SetName(v string) { func (m *Filter) SetName(v string) {
if m != nil { if m != nil {

View file

@ -26,6 +26,7 @@ const (
backupPolicyField = 2 backupPolicyField = 2
selectorsPolicyField = 3 selectorsPolicyField = 3
filtersPolicyField = 4 filtersPolicyField = 4
subnetIDPolicyField = 5
keyAttributeField = 1 keyAttributeField = 1
valueAttributeField = 2 valueAttributeField = 2
@ -262,6 +263,11 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
} }
_, err = protoutil.NestedStructureMarshal(subnetIDPolicyField, buf[offset:], p.subnetID)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -280,6 +286,8 @@ func (p *PlacementPolicy) StableSize() (size int) {
size += protoutil.NestedStructureSize(filtersPolicyField, p.filters[i]) size += protoutil.NestedStructureSize(filtersPolicyField, p.filters[i])
} }
size += protoutil.NestedStructureSize(subnetIDPolicyField, p.subnetID)
return size return size
} }

View file

@ -102,6 +102,7 @@ func GeneratePlacementPolicy(empty bool) *netmap.PlacementPolicy {
m.SetFilters(GenerateFilters(false)) m.SetFilters(GenerateFilters(false))
m.SetSelectors(GenerateSelectors(false)) m.SetSelectors(GenerateSelectors(false))
m.SetReplicas(GenerateReplicas(false)) m.SetReplicas(GenerateReplicas(false))
m.SetSubnetID(refstest.GenerateSubnetID(false))
} }
return m return m