-
Notifications
You must be signed in to change notification settings - Fork 0
/
wakeup.go
112 lines (81 loc) · 2.96 KB
/
wakeup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"github.com/ch3lo/wakeup/graph"
"github.com/ch3lo/wakeup/service"
"github.com/ch3lo/wakeup/util"
"github.com/kr/pretty"
"github.com/op/go-logging"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)
var log = logging.MustGetLogger("main")
var config = util.GetConfiguration()
type ServicesConfiguration struct {
DockerServices []service.DockerService `json:"docker_services" yaml:"docker_services"`
ExternalServices []service.ExternalService `json:"external_services" yaml:"external_services"`
}
func main() {
services := servicesConfigurationReader(config.File)
var g *graph.Graph = createGraph(&services)
//var g2 *graph.Graph = createGraph(&config)
//fmt.Printf("GRAPH %#v\n", pretty.Formatter(g))
//fmt.Printf("GRAPH2 %#v\n", pretty.Formatter(g2))
//testPointer(g)
//fmt.Printf("GRAPH DIC ID %#v %#v\n", g.Nodes["dic"], pretty.Formatter(g.Nodes["dic"].Change))
//fmt.Printf("GRAPH2 DIC ID %#v %#v\n", g2.Nodes["dic"], pretty.Formatter(g2.Nodes["dic"].Change))
//fmt.Printf("GRAPH %#v\n", pretty.Formatter(g))
//fmt.Printf("GRAPH2 %#v\n", pretty.Formatter(g2))
/*var nodes *[]*graph.Node = g.ReverseChildrens("acc")
log.Debug("Reverse nodes:")
for key, value := range *nodes {
log.Debug("Node %# i: %s", key, value.Id())
}
log.Debug("GRAPH %#v", pretty.Formatter(nodes))
*/
runNode(g.Nodes["acc"])
}
func servicesConfigurationReader(configFile string) ServicesConfiguration {
filename, _ := filepath.Abs(configFile)
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
var servicesConfig ServicesConfiguration
err = yaml.Unmarshal(yamlFile, &servicesConfig)
if err != nil {
panic(err)
}
log.Debug("Configuration %#v\n\n\n", servicesConfig)
return servicesConfig
}
func createGraph(services *ServicesConfiguration) *graph.Graph {
g := graph.NewGraph()
for id, _ := range services.DockerServices {
g.AddNode(graph.NewNode(&services.DockerServices[id]))
}
for id, _ := range services.ExternalServices {
g.AddNode(graph.NewNode(&services.ExternalServices[id]))
}
var from *graph.Node
var to *graph.Node
for _, srv_a := range services.DockerServices {
from = g.GetNode(srv_a.Id())
for _, srv_b := range srv_a.Uses {
to = g.GetNode(srv_b.Id())
g.AddEdge(from, to)
}
for _, srv_b := range srv_a.Externals {
to = g.GetNode(srv_b.Id())
g.AddEdge(from, to)
}
}
return g
}
func testPointer(g *graph.Graph) {
log.Debug("DIC ID %#v %# v", g.Nodes["acc"].Neighbors["pcc"].Neighbors["dic"], pretty.Formatter(g.Nodes["acc"].Neighbors["pcc"].Neighbors["dic"].Change))
g.Nodes["acc"].Neighbors["pcc"].Neighbors["dic"].Change = g.Nodes["acc"].Neighbors["pcc"].Neighbors["dic"].Change + "?"
log.Debug("DIC ID %#v %#v\n", g.Nodes["acc"].Neighbors["dic"], pretty.Formatter(g.Nodes["acc"].Neighbors["dic"].Change))
g.Nodes["acc"].Neighbors["dic"].Change = g.Nodes["acc"].Neighbors["dic"].Change + "?"
log.Debug("DIC ID %#v %#v\n", g.Nodes["dic"], pretty.Formatter(g.Nodes["dic"].Change))
}