Skip to content

Commit

Permalink
Merge pull request #17 from k1LoW/build-component-from-nw-route
Browse files Browse the repository at this point in the history
Create a node component from the network routes when the node component does not exist
  • Loading branch information
k1LoW authored Sep 25, 2020
2 parents ad04cea + 4c64606 commit 7d54485
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ func (cfg *Config) LoadRealNodesFile(path string) error {
return cfg.LoadRealNodes(buf)
}

func (cfg *Config) FindNode(name string) (*Node, error) {
for _, n := range cfg.Nodes {
if strings.EqualFold(n.FullName(), name) {
return n, nil
}
}
return nil, fmt.Errorf("node not found: %s", name)
}

func (cfg *Config) FindComponent(name string) (*Component, error) {
var components []*Component
switch sepCount(name) {
Expand Down Expand Up @@ -299,6 +308,7 @@ func (cfg *Config) buildComponents() error {

// global components
for _, c := range gc.Keys() {
// create global component from network route
cfg.globalComponents = append(cfg.globalComponents, &Component{
Name: c.(string),
})
Expand All @@ -309,18 +319,29 @@ func (cfg *Config) buildComponents() error {
cfg.nodeComponents = append(cfg.nodeComponents, n.Components...)
}

belongTo := false
for _, c := range nc.Keys() {
for _, n := range cfg.Nodes {
for _, com := range n.Components {
if strings.EqualFold(com.FullName(), c.(string)) {
belongTo = true
}
belongTo := false
splitted := sepSplit(c.(string))
nodeName := splitted[0]
comName := splitted[1]
n, err := cfg.FindNode(nodeName)
if err != nil {
return fmt.Errorf("node '%s' not found: %s", nodeName, c)
}
for _, com := range n.Components {
if strings.EqualFold(com.FullName(), c.(string)) {
belongTo = true
break
}
}
if !belongTo {
splitted := sepSplit(c.(string))
return fmt.Errorf("node '%s' not found: %s", splitted[0], c)
// create node component from network route
component := &Component{
Name: comName,
Node: n,
}
n.Components = append(n.Components, component)
cfg.nodeComponents = append(cfg.nodeComponents, component)
}
}

Expand All @@ -332,6 +353,7 @@ func (cfg *Config) buildComponents() error {
belongTo := false
for _, cl := range cfg.Clusters() {
if strings.EqualFold(cl.FullName(), clName) {
// create cluster component from network route
com := &Component{
Cluster: cl,
Name: comName,
Expand Down

0 comments on commit 7d54485

Please sign in to comment.