Rename nodes_dynamic_path to state_path
This commit is contained in:
parent
4cc93891ee
commit
5ca74e51bc
|
@ -13,8 +13,9 @@ webroot = "webroot"
|
||||||
[nodes]
|
[nodes]
|
||||||
enable = true
|
enable = true
|
||||||
nodes_version = 2
|
nodes_version = 2
|
||||||
nodes_path = "/var/www/html/meshviewer/data/nodes_all.json"
|
nodes_path = "/var/www/html/meshviewer/data/nodes.json"
|
||||||
graph_path = "/var/www/html/meshviewer/data/graph.json"
|
graph_path = "/var/www/html/meshviewer/data/graph.json"
|
||||||
|
state_path = "/var/lib/collector/state.json"
|
||||||
|
|
||||||
# Export nodes and graph periodically
|
# Export nodes and graph periodically
|
||||||
save_interval = "5s"
|
save_interval = "5s"
|
||||||
|
|
|
@ -22,8 +22,8 @@ type Config struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
NodesVersion int
|
NodesVersion int
|
||||||
NodesPath string
|
NodesPath string
|
||||||
NodesDynamicPath string
|
|
||||||
GraphPath string
|
GraphPath string
|
||||||
|
StatePath string
|
||||||
SaveInterval Duration // Save nodes periodically
|
SaveInterval Duration // Save nodes periodically
|
||||||
PruneAfter Duration // Remove nodes after n days of inactivity
|
PruneAfter Duration // Remove nodes after n days of inactivity
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,6 @@ func TestReadConfig(t *testing.T) {
|
||||||
assert.Equal(time.Minute, config.Respondd.CollectInterval.Duration)
|
assert.Equal(time.Minute, config.Respondd.CollectInterval.Duration)
|
||||||
|
|
||||||
assert.Equal(2, config.Nodes.NodesVersion)
|
assert.Equal(2, config.Nodes.NodesVersion)
|
||||||
assert.Equal("/var/www/html/meshviewer/data/nodes_all.json", config.Nodes.NodesPath)
|
assert.Equal("/var/www/html/meshviewer/data/nodes.json", config.Nodes.NodesPath)
|
||||||
assert.Equal(time.Hour*24*7, config.Nodes.PruneAfter.Duration)
|
assert.Equal(time.Hour*24*7, config.Nodes.PruneAfter.Duration)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func NewNodes(config *Config) *Nodes {
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Nodes.NodesDynamicPath != "" {
|
if config.Nodes.StatePath != "" {
|
||||||
nodes.load()
|
nodes.load()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -178,7 +178,7 @@ func (nodes *Nodes) expire() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nodes *Nodes) load() {
|
func (nodes *Nodes) load() {
|
||||||
path := nodes.config.Nodes.NodesDynamicPath
|
path := nodes.config.Nodes.StatePath
|
||||||
|
|
||||||
if f, err := os.Open(path); err == nil { // transform data to legacy meshviewer
|
if f, err := os.Open(path); err == nil { // transform data to legacy meshviewer
|
||||||
if err = json.NewDecoder(f).Decode(nodes); err == nil {
|
if err = json.NewDecoder(f).Decode(nodes); err == nil {
|
||||||
|
@ -197,7 +197,7 @@ func (nodes *Nodes) save() {
|
||||||
defer nodes.RUnlock()
|
defer nodes.RUnlock()
|
||||||
|
|
||||||
// serialize nodes
|
// serialize nodes
|
||||||
save(nodes, nodes.config.Nodes.NodesDynamicPath)
|
save(nodes, nodes.config.Nodes.StatePath)
|
||||||
|
|
||||||
if path := nodes.config.Nodes.NodesPath; path != "" {
|
if path := nodes.config.Nodes.NodesPath; path != "" {
|
||||||
version := nodes.config.Nodes.NodesVersion
|
version := nodes.config.Nodes.NodesVersion
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestLoadAndSave(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
config.Nodes.NodesDynamicPath = "testdata/nodes.json"
|
config.Nodes.StatePath = "testdata/nodes.json"
|
||||||
|
|
||||||
nodes := NewNodes(config)
|
nodes := NewNodes(config)
|
||||||
nodes.load()
|
nodes.load()
|
||||||
|
|
Loading…
Reference in New Issue