-
Notifications
You must be signed in to change notification settings - Fork 11
/
update.go
93 lines (79 loc) · 1.89 KB
/
update.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
package neco
import "time"
// Environments to use release or pre-release neco
const (
NoneEnv = "none"
TestEnv = "test"
DevEnv = "dev"
StagingEnv = "staging"
ProdEnv = "prod"
)
// UpdateRequest represents request from neco-updater
type UpdateRequest struct {
Version string `json:"version"`
Servers []int `json:"servers"`
Stop bool `json:"stop"`
StartedAt time.Time `json:"started_at"`
}
// IsMember returns true if a boot server is the member of this update request.
func (r UpdateRequest) IsMember(lrn int) bool {
for _, n := range r.Servers {
if n == lrn {
return true
}
}
return false
}
// UpdateCondition is the condition of the update process.
type UpdateCondition int
// Possible update conditions.
const (
CondNotRunning = iota
CondRunning
CondAbort
CondComplete
)
// String implements io.Stringer
func (c UpdateCondition) String() string {
switch c {
case CondNotRunning:
return "not running"
case CondRunning:
return "running"
case CondAbort:
return "aborted"
case CondComplete:
return "completed"
default:
return "unknown"
}
}
// UpdateStatus represents status report from neco-worker
type UpdateStatus struct {
Version string `json:"version"`
Step int `json:"step"`
Cond UpdateCondition `json:"cond"`
Message string `json:"message"`
}
// UpdateCompleted returns true if the current update process has
// completed successfully.
func UpdateCompleted(version string, lrns []int, statuses map[int]*UpdateStatus) bool {
for _, lrn := range lrns {
st, ok := statuses[lrn]
if !ok {
return false
}
if st.Version != version {
return false
}
if st.Cond != CondComplete {
return false
}
}
return true
}
// ContentsUpdateStatus represents update status of uploaded assets.
type ContentsUpdateStatus struct {
Version string `json:"version"`
Success bool `json:"success"`
}