-
Notifications
You must be signed in to change notification settings - Fork 19
/
graph_nodes.go
146 lines (121 loc) · 2.7 KB
/
graph_nodes.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package visualization
import (
"fmt"
"github.com/Aptomi/aptomi/pkg/engine/resolve"
"github.com/Aptomi/aptomi/pkg/lang"
"github.com/Aptomi/aptomi/pkg/runtime"
"github.com/Aptomi/aptomi/pkg/util"
"html"
)
/*
Dependency
*/
type dependencyNode struct {
dependency *lang.Dependency
b *GraphBuilder
}
func (n dependencyNode) getGroup() string {
serviceKey := n.b.resolution.GetDependencyInstanceMap()[runtime.KeyForStorable(n.dependency)]
if len(serviceKey) > 0 {
return "dependency"
}
return "dependencyNotResolved"
}
func (n dependencyNode) getID() string {
return runtime.KeyForStorable(n.dependency)
}
func (n dependencyNode) getLabel() string {
return n.dependency.User
}
/*
Contract
*/
type contractNode struct {
contract *lang.Contract
}
func (n contractNode) getGroup() string {
return "contract"
}
func (n contractNode) getID() string {
return runtime.KeyForStorable(n.contract)
}
func (n contractNode) getLabel() string {
return fmt.Sprintf(
`contract: <b>%s</b>`,
html.EscapeString(n.contract.Name),
)
}
/*
Service
*/
type serviceNode struct {
service *lang.Service
}
func (n serviceNode) getGroup() string {
return "service"
}
func (n serviceNode) getID() string {
return runtime.KeyForStorable(n.service)
}
func (n serviceNode) getLabel() string {
return n.service.Name
}
/*
Component
*/
type componentNode struct {
service *lang.Service
component *lang.ServiceComponent
}
func (n componentNode) getGroup() string {
return "component"
}
func (n componentNode) getID() string {
return runtime.KeyForStorable(n.service) + "-" + n.component.Name
}
func (n componentNode) getLabel() string {
return n.component.Name
}
/*
Service Instance
*/
type serviceInstanceNode struct {
instance *resolve.ComponentInstance
service *lang.Service
}
func (n serviceInstanceNode) getGroup() string {
return "serviceInstance"
}
func (n serviceInstanceNode) getID() string {
return n.instance.GetKey()
}
func (n serviceInstanceNode) getLabel() string {
timeRunning := ""
if !n.instance.CreatedAt.IsZero() {
timeRunning = fmt.Sprintf("\nrunning: <i>%s</i>", html.EscapeString(util.NewTimeDiff(n.instance.GetRunningTime()).Humanize()))
}
return fmt.Sprintf(
`<b>%s</b>
context: <i>%s</i>
cluster: <i>%s</i>%s`,
html.EscapeString(n.service.Name),
html.EscapeString(n.instance.Metadata.Key.ContextNameWithKeys),
html.EscapeString(n.instance.CalculatedLabels.Labels[lang.LabelCluster]),
timeRunning,
)
}
/*
Error
*/
type errorNode struct {
err error
}
func (n errorNode) getGroup() string {
return "error"
}
func (n errorNode) getID() string {
return fmt.Sprintf("error-%p", n.err) // nolint: vet
}
func (n errorNode) getLabel() string {
return fmt.Sprintf("Error: %s", n.err)
}