/
rule.go
79 lines (69 loc) · 1.37 KB
/
rule.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
package task
import (
"github.com/konveyor/tackle2-hub/model"
"strings"
)
//
// Rule defines postpone rules.
type Rule interface {
Match(candidate, other *model.Task) bool
}
//
// RuleUnique running tasks must be unique by:
// - application
// - variant
// - addon.
type RuleUnique struct {
}
//
// Match determines the match.
func (r *RuleUnique) Match(candidate, other *model.Task) (matched bool) {
if candidate.ApplicationID == nil || other.ApplicationID == nil {
return
}
if *candidate.ApplicationID != *other.ApplicationID {
return
}
if candidate.Addon != other.Addon {
return
}
matched = true
Log.Info(
"Rule:Unique matched.",
"candidate",
candidate.ID,
"by",
other.ID)
return
}
//
// RuleIsolated policy.
type RuleIsolated struct {
}
//
// Match determines the match.
func (r *RuleIsolated) Match(candidate, other *model.Task) (matched bool) {
matched = r.hasPolicy(candidate, Isolated) || r.hasPolicy(other, Isolated)
if matched {
Log.Info(
"Rule:Isolated matched.",
"candidate",
candidate.ID,
"by",
other.ID)
}
return
}
//
// Returns true if the task policy includes: isolated
func (r *RuleIsolated) hasPolicy(task *model.Task, name string) (matched bool) {
for _, p := range strings.Split(task.Policy, ";") {
p = strings.TrimSpace(p)
p = strings.ToLower(p)
if p == name {
matched = true
break
}
}
return
}