-
Notifications
You must be signed in to change notification settings - Fork 199
/
world.go
71 lines (59 loc) Β· 1.45 KB
/
world.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
package model
import (
"github.com/coroot/coroot/timeseries"
)
type IntegrationStatus struct {
NodeAgent struct {
Installed bool
}
KubeStateMetrics struct {
Required bool
Installed bool
}
}
type World struct {
Ctx timeseries.Context
CheckConfigs CheckConfigs
Nodes []*Node
Applications map[ApplicationId]*Application
appsByNsAndName map[nsAndName]*Application
IntegrationStatus IntegrationStatus
}
type nsAndName struct {
ns string
name string
}
func NewWorld(from, to timeseries.Time, step timeseries.Duration) *World {
return &World{
Ctx: timeseries.Context{From: from, To: to, Step: step},
Applications: map[ApplicationId]*Application{},
}
}
func (w *World) GetApplication(id ApplicationId) *Application {
return w.Applications[id]
}
func (w *World) GetApplicationByNsAndName(ns, name string) *Application {
if w.appsByNsAndName == nil {
w.appsByNsAndName = map[nsAndName]*Application{}
for id, app := range w.Applications {
w.appsByNsAndName[nsAndName{ns: id.Namespace, name: id.Name}] = app
}
}
return w.appsByNsAndName[nsAndName{ns: ns, name: name}]
}
func (w *World) GetOrCreateApplication(id ApplicationId) *Application {
app := w.GetApplication(id)
if app == nil {
app = NewApplication(id)
w.Applications[id] = app
}
return app
}
func (w *World) GetNode(name string) *Node {
for _, n := range w.Nodes {
if n.Name.Value() == name || n.K8sName.Value() == name {
return n
}
}
return nil
}