forked from ch3lo/overlord
/
criteria.go
63 lines (51 loc) · 1.6 KB
/
criteria.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
package updater
import "github.com/ch3lo/overlord/scheduler"
type ChangeCriteria interface {
MeetCriteria(status map[string]*scheduler.ServiceInformation) map[string]*scheduler.ServiceInformation
}
type ImageNameCriteria struct {
Name string
}
func (c *ImageNameCriteria) MeetCriteria(elements map[string]*scheduler.ServiceInformation) map[string]*scheduler.ServiceInformation {
var filtered map[string]*scheduler.ServiceInformation
for k, v := range elements {
if c.Name == v.Image {
filtered[k] = elements[k]
}
}
return filtered
}
type StatusCriteria struct {
Status string
}
func (c *StatusCriteria) MeetCriteria(elements map[string]*scheduler.ServiceInformation) map[string]*scheduler.ServiceInformation {
var filtered map[string]*scheduler.ServiceInformation
for k, v := range elements {
if c.Status == v.Status {
filtered[k] = elements[k]
}
}
return filtered
}
type AndCriteria struct {
criteria ChangeCriteria
otherCriteria ChangeCriteria
}
func (c *AndCriteria) MeetCriteria(elements map[string]*scheduler.ServiceInformation) map[string]*scheduler.ServiceInformation {
filtered := c.criteria.MeetCriteria(elements)
return c.otherCriteria.MeetCriteria(filtered)
}
type OrCriteria struct {
criteria ChangeCriteria
otherCriteria ChangeCriteria
}
func (c *OrCriteria) MeetCriteria(elements map[string]*scheduler.ServiceInformation) map[string]*scheduler.ServiceInformation {
filtered := c.criteria.MeetCriteria(elements)
others := c.otherCriteria.MeetCriteria(elements)
for k, _ := range others {
if filtered[k] == nil {
filtered[k] = others[k]
}
}
return filtered
}