-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathstatus.go
70 lines (56 loc) · 1.42 KB
/
status.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
package status
type statusID string
const (
DisabledStatus = "disabled"
UploadStatus = "upload"
DownloadStatus = "download"
ErrorStatus = "error"
RemoteConfigAvailableStatus = "remoteConfigAvailable"
RemoteConfigValidStatus = "remoteConfigIValid"
)
type controllerStatus struct {
statusMap map[statusID]statusMessage
}
type statusMessage struct {
reason string
message string
}
func newControllerStatus() *controllerStatus {
return &controllerStatus{
statusMap: make(map[statusID]statusMessage),
}
}
func (c *controllerStatus) setStatus(id statusID, reason, message string) {
entries := make(map[statusID]statusMessage)
for k, v := range c.statusMap {
entries[k] = v
}
existing, ok := c.statusMap[id]
if !ok || existing.reason != reason || existing.message != message {
entries[id] = statusMessage{
reason: reason,
message: message,
}
}
c.statusMap = entries
}
func (c *controllerStatus) getStatus(id statusID) *statusMessage {
s, ok := c.statusMap[id]
if !ok {
return nil
}
return &s
}
func (c *controllerStatus) hasStatus(id statusID) bool {
_, ok := c.statusMap[id]
return ok
}
func (c *controllerStatus) reset() {
c.statusMap = make(map[statusID]statusMessage)
}
func (c *controllerStatus) isHealthy() bool {
return !c.hasStatus(ErrorStatus)
}
func (c *controllerStatus) isDisabled() bool {
return c.hasStatus(DisabledStatus)
}