From cdb3b7107091e049239d10dde0b344d9a8a5714d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 6 Sep 2021 16:03:43 +0300 Subject: [PATCH] [#798] neofs-node/config: Add persistent_state section Signed-off-by: Alex Vanin --- cmd/neofs-node/config/node/config.go | 32 ++++++++++++++++++++++- cmd/neofs-node/config/node/config_test.go | 5 ++++ config/example/node.env | 1 + config/example/node.json | 5 +++- config/example/node.yaml | 2 ++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index c7f12771c..d575f88f5 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -11,10 +11,20 @@ import ( utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config" ) +// PersistentStateConfig is a wrapper over "persistent_state" config section +// which provides access to persistent state storage configuration of node. +type PersistentStateConfig struct { + cfg *config.Config +} + const ( - subsection = "node" + subsection = "node" + persistentStateSubsection = "persistent_state" attributePrefix = "attribute" + + // PersistentStatePathDefault is a default path for persistent state file. + PersistentStatePathDefault = ".neofs-storage-state" ) // Key returns value of "key" config parameter @@ -115,3 +125,23 @@ func Attributes(c *config.Config) (attrs []string) { func Relay(c *config.Config) bool { return config.BoolSafe(c.Sub(subsection), "relay") } + +// PersistentState returns structure that provides access to "persistent_state" +// subsection of "node" section. +func PersistentState(c *config.Config) PersistentStateConfig { + return PersistentStateConfig{ + c.Sub(subsection).Sub(persistentStateSubsection), + } +} + +// Path returns value of "path" config parameter. +// +// Returns PersistentStatePathDefault if value is not a non-empty string. +func (p PersistentStateConfig) Path() string { + v := config.String(p.cfg, "path") + if v != "" { + return v + } + + return PersistentStatePathDefault +} diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index 54ced7d94..2d09c4e3f 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -30,9 +30,11 @@ func TestNodeSection(t *testing.T) { attribute := Attributes(empty) relay := Relay(empty) + persistatePath := PersistentState(empty).Path() require.Empty(t, attribute) require.Equal(t, false, relay) + require.Equal(t, PersistentStatePathDefault, persistatePath) }) const path = "../../../../config/example/node" @@ -43,6 +45,7 @@ func TestNodeSection(t *testing.T) { attributes := Attributes(c) relay := Relay(c) wKey := Wallet(c) + persistatePath := PersistentState(c).Path() expectedAddr := []struct { str string @@ -94,6 +97,8 @@ func TestNodeSection(t *testing.T) { require.Equal(t, config.StringSafe(c.Sub("node").Sub("wallet"), "address"), address.Uint160ToString(wKey.GetScriptHash())) + + require.Equal(t, "/state", persistatePath) } configtest.ForEachFileType(path, fileConfigTest) diff --git a/config/example/node.env b/config/example/node.env index d230cc526..212a2d07d 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -15,6 +15,7 @@ NEOFS_NODE_ADDRESSES=s01.neofs.devenv:8080 /dns4/s02.neofs.devenv/tcp/8081 grpc: NEOFS_NODE_ATTRIBUTE_0=Price:11 NEOFS_NODE_ATTRIBUTE_1=UN-LOCODE:RU MSK NEOFS_NODE_RELAY=true +NEOFS_NODE_PERSISTENT_STATE_PATH=/state # gRPC section NEOFS_GRPC_NUM=2 diff --git a/config/example/node.json b/config/example/node.json index 8a43d646f..ec0c4099e 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -25,7 +25,10 @@ ], "attribute_0": "Price:11", "attribute_1": "UN-LOCODE:RU MSK", - "relay": true + "relay": true, + "persistent_state": { + "path": "/state" + } }, "grpc": { "num": 2, diff --git a/config/example/node.yaml b/config/example/node.yaml index b5bd0cc24..6cdd59f80 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -23,6 +23,8 @@ node: attribute_0: "Price:11" attribute_1: UN-LOCODE:RU MSK relay: true + persistent_state: + path: /state grpc: num: 2