forked from TrueCloudLab/frostfs-node
[#1513] Upgrade NeoFS SDK Go with changed netmap
package
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
24b4c1ecf4
commit
21d2f8f861
70 changed files with 878 additions and 992 deletions
|
@ -1,69 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
)
|
||||
|
||||
const (
|
||||
// list of default values for well-known attributes
|
||||
defaultCapacity = 0
|
||||
defaultPrice = 0
|
||||
)
|
||||
|
||||
func parseAttributes(c *config.Config) []netmap.NodeAttribute {
|
||||
if nodeconfig.Relay(c) {
|
||||
return nil
|
||||
func parseAttributes(c *cfg) {
|
||||
if nodeconfig.Relay(c.appCfg) {
|
||||
return
|
||||
}
|
||||
|
||||
stringAttributes := nodeconfig.Attributes(c)
|
||||
|
||||
attrs, err := attributes.ParseV2Attributes(stringAttributes, nil)
|
||||
if err != nil {
|
||||
fatalOnErr(err)
|
||||
}
|
||||
|
||||
return addWellKnownAttributes(attrs)
|
||||
}
|
||||
|
||||
type wellKnownNodeAttrDesc struct {
|
||||
explicit bool
|
||||
defaultVal string
|
||||
}
|
||||
|
||||
func listWellKnownAttrDesc() map[string]wellKnownNodeAttrDesc {
|
||||
return map[string]wellKnownNodeAttrDesc{
|
||||
netmap.AttrPrice: {defaultVal: strconv.FormatUint(defaultPrice, 10)},
|
||||
netmap.AttrCapacity: {defaultVal: strconv.FormatUint(defaultCapacity, 10)},
|
||||
netmap.AttrUNLOCODE: {explicit: true},
|
||||
}
|
||||
}
|
||||
|
||||
func addWellKnownAttributes(attrs []netmap.NodeAttribute) []netmap.NodeAttribute {
|
||||
mWellKnown := listWellKnownAttrDesc()
|
||||
|
||||
// check how user defined well-known attributes
|
||||
for i := range attrs {
|
||||
delete(mWellKnown, attrs[i].Key())
|
||||
}
|
||||
|
||||
for key, desc := range mWellKnown {
|
||||
// check if required attribute is set
|
||||
if desc.explicit {
|
||||
fatalOnErr(fmt.Errorf("missing explicit value of required node attribute %s", key))
|
||||
}
|
||||
|
||||
// set default value of the attribute
|
||||
index := len(attrs)
|
||||
attrs = append(attrs, netmap.NodeAttribute{})
|
||||
attrs[index].SetKey(key)
|
||||
attrs[index].SetValue(desc.defaultVal)
|
||||
}
|
||||
|
||||
return attrs
|
||||
fatalOnErr(attributes.ReadNodeAttributes(&c.cfgNodeInfo.localInfo, nodeconfig.Attributes(c.appCfg)))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue