forked from TrueCloudLab/frostfs-node
[#36] Parse attributes from node config
Well-known attributes set up with explicit configuration values, other attributes set up from chain of attributes. Chain of attributes is a string, that contains keys-value pairs, divided by semicolon. Pairs itself divided by slash. E.g. "StorageType:HDD/RPM:7200" Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
28534a509d
commit
1759ff57f1
2 changed files with 40 additions and 6 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -18,8 +19,11 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// config keys for cfgNodeInfo
|
// config keys for cfgNodeInfo
|
||||||
cfgNodeKey = "node.key"
|
cfgNodeKey = "node.key"
|
||||||
cfgBootstrapAddress = "node.address"
|
cfgBootstrapAddress = "node.address"
|
||||||
|
cfgNodeAttributePrefix = "node.attribute"
|
||||||
|
cfgNodeCapacity = "node.capacity"
|
||||||
|
cfgNodePrice = "node.price"
|
||||||
|
|
||||||
// config keys for cfgGRPC
|
// config keys for cfgGRPC
|
||||||
cfgListenAddress = "grpc.endpoint"
|
cfgListenAddress = "grpc.endpoint"
|
||||||
|
@ -95,7 +99,10 @@ type cfgNetmap struct {
|
||||||
type BootstrapType uint32
|
type BootstrapType uint32
|
||||||
|
|
||||||
type cfgNodeInfo struct {
|
type cfgNodeInfo struct {
|
||||||
bootType BootstrapType
|
bootType BootstrapType
|
||||||
|
attributes []string
|
||||||
|
capacity uint64
|
||||||
|
price uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -140,7 +147,10 @@ func initCfg(path string) *cfg {
|
||||||
fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)),
|
fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)),
|
||||||
},
|
},
|
||||||
cfgNodeInfo: cfgNodeInfo{
|
cfgNodeInfo: cfgNodeInfo{
|
||||||
bootType: StorageNode,
|
bootType: StorageNode,
|
||||||
|
attributes: readAttributes(viperCfg),
|
||||||
|
capacity: viperCfg.GetUint64(cfgNodeCapacity),
|
||||||
|
price: viperCfg.GetUint64(cfgNodePrice),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +179,8 @@ func initViper(path string) *viper.Viper {
|
||||||
func defaultConfiguration(v *viper.Viper) {
|
func defaultConfiguration(v *viper.Viper) {
|
||||||
// fixme: all hardcoded private keys must be removed
|
// fixme: all hardcoded private keys must be removed
|
||||||
v.SetDefault(cfgNodeKey, "Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
|
v.SetDefault(cfgNodeKey, "Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
|
||||||
|
v.SetDefault(cfgNodeCapacity, "10")
|
||||||
|
v.SetDefault(cfgNodePrice, "10")
|
||||||
v.SetDefault(cfgBootstrapAddress, "") // address to bootstrap with
|
v.SetDefault(cfgBootstrapAddress, "") // address to bootstrap with
|
||||||
|
|
||||||
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
|
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
|
||||||
|
@ -183,3 +195,18 @@ func defaultConfiguration(v *viper.Viper) {
|
||||||
v.SetDefault(cfgNetmapContract, "75194459637323ea8837d2afe8225ec74a5658c3")
|
v.SetDefault(cfgNetmapContract, "75194459637323ea8837d2afe8225ec74a5658c3")
|
||||||
v.SetDefault(cfgNetmapFee, "1")
|
v.SetDefault(cfgNetmapFee, "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readAttributes(v *viper.Viper) (attrs []string) {
|
||||||
|
const maxAttributes = 100
|
||||||
|
|
||||||
|
for i := 0; i < maxAttributes; i++ {
|
||||||
|
attr := v.GetString(cfgNodeAttributePrefix + "_" + strconv.Itoa(i))
|
||||||
|
if attr == "" {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
attrs = append(attrs, attr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return attrs
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,10 +32,15 @@ func bootstrapNode(c *cfg) {
|
||||||
cliWrapper, err := wrapper.New(cli)
|
cliWrapper, err := wrapper.New(cli)
|
||||||
fatalOnErr(errors.Wrap(err, "bootstrap error"))
|
fatalOnErr(errors.Wrap(err, "bootstrap error"))
|
||||||
|
|
||||||
peerInfo := new(netmap.NodeInfo)
|
attrs, err := attributes.ParseV2Attributes(c.cfgNodeInfo.attributes, nil)
|
||||||
|
if err != nil {
|
||||||
|
fatalOnErr(errors.Wrap(err, "bootstrap attribute error"))
|
||||||
|
}
|
||||||
|
|
||||||
|
peerInfo := new(v2netmap.NodeInfo)
|
||||||
peerInfo.SetAddress(c.viper.GetString(cfgBootstrapAddress))
|
peerInfo.SetAddress(c.viper.GetString(cfgBootstrapAddress))
|
||||||
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
||||||
// todo: add attributes as opts
|
peerInfo.SetAttributes(attrs)
|
||||||
|
|
||||||
err = cliWrapper.AddPeer(peerInfo)
|
err = cliWrapper.AddPeer(peerInfo)
|
||||||
fatalOnErr(errors.Wrap(err, "bootstrap error"))
|
fatalOnErr(errors.Wrap(err, "bootstrap error"))
|
||||||
|
|
Loading…
Reference in a new issue