|
25 | 25 | package workflow |
26 | 26 |
|
27 | 27 | import ( |
28 | | - "strconv" |
29 | 28 | "strings" |
30 | 29 | "sync" |
31 | 30 |
|
32 | 31 | "github.com/AliceO2Group/Control/core/task" |
33 | 32 | "github.com/sirupsen/logrus" |
34 | | - "github.com/spf13/viper" |
35 | 33 | ) |
36 | 34 |
|
37 | 35 | type SafeStatus struct { |
38 | 36 | mu sync.RWMutex |
39 | 37 | status task.Status |
40 | 38 | } |
41 | 39 |
|
42 | | -func reportTraceRoles(roles []Role, status task.Status) { |
43 | | - if viper.GetBool("veryVerbose") { |
44 | | - stati := make([]string, len(roles)) |
45 | | - critical := make([]string, len(roles)) |
46 | | - names := make([]string, len(roles)) |
47 | | - for i, role := range roles { |
48 | | - stati[i] = role.GetStatus().String() |
49 | | - names[i] = role.GetName() |
50 | | - if taskR, isTaskRole := role.(*taskRole); isTaskRole { |
51 | | - critical[i] = strconv.FormatBool(taskR.IsCritical()) |
52 | | - } else if callR, isCallRole := role.(*callRole); isCallRole { |
53 | | - critical[i] = strconv.FormatBool(callR.IsCritical()) |
54 | | - } else { |
55 | | - critical[i] = strconv.FormatBool(true) |
56 | | - } |
57 | | - } |
58 | | - log.WithFields(logrus.Fields{ |
59 | | - "statuses": strings.Join(stati, ", "), |
60 | | - "critical": strings.Join(critical, ", "), |
61 | | - "names": strings.Join(names, ", "), |
62 | | - "aggregated": status.String(), |
63 | | - }). |
64 | | - Trace("aggregating statuses") |
65 | | - } |
66 | | -} |
67 | | - |
68 | | -// role that are not taskRole or callRole are critical by default |
69 | 40 | func aggregateStatus(roles []Role) (status task.Status) { |
70 | 41 | if len(roles) == 0 { |
71 | 42 | status = task.UNDEFINED |
72 | 43 | return |
73 | 44 | } |
| 45 | + stati := make([]string, len(roles)) |
| 46 | + for i, role := range roles { |
| 47 | + stati[i] = role.GetStatus().String() |
| 48 | + } |
74 | 49 |
|
75 | | - status = task.INVARIANT |
76 | | - for _, role := range roles { |
77 | | - if status == task.UNDEFINED { |
78 | | - break |
79 | | - } |
| 50 | + status = roles[0].GetStatus() |
| 51 | + if len(roles) > 1 { |
| 52 | + for _, c := range roles[1:] { |
| 53 | + if status == task.UNDEFINED { |
| 54 | + log.WithFields(logrus.Fields{ |
| 55 | + "statuses": strings.Join(stati, ", "), |
| 56 | + "aggregated": status.String(), |
| 57 | + }). |
| 58 | + Trace("aggregating statuses") |
80 | 59 |
|
81 | | - if taskR, isTaskRole := role.(*taskRole); isTaskRole { |
82 | | - if !taskR.IsCritical() { |
83 | | - continue |
84 | | - } |
85 | | - } else if callR, isCallRole := role.(*callRole); isCallRole { |
86 | | - if !callR.IsCritical() { |
87 | | - continue |
| 60 | + return |
88 | 61 | } |
| 62 | + status = status.X(c.GetStatus()) |
89 | 63 | } |
90 | | - status = status.X(role.GetStatus()) |
91 | 64 | } |
92 | | - |
93 | | - reportTraceRoles(roles, status) |
| 65 | + log.WithFields(logrus.Fields{ |
| 66 | + "statuses": strings.Join(stati, ", "), |
| 67 | + "aggregated": status.String(), |
| 68 | + }). |
| 69 | + Trace("aggregating statuses") |
94 | 70 |
|
95 | 71 | return |
96 | 72 | } |
97 | 73 |
|
98 | | -// TODO: this function is prime candidate for refactoring. The reason being that it mostly ignores status argument |
99 | | -// for merging, moreover it also does not use status of role from argument. Both of these behaivour are counter-intuitive. |
100 | 74 | func (t *SafeStatus) merge(s task.Status, r Role) { |
101 | 75 | t.mu.Lock() |
102 | 76 | defer t.mu.Unlock() |
|
0 commit comments