-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtaskrole.go
More file actions
191 lines (161 loc) · 4.49 KB
/
taskrole.go
File metadata and controls
191 lines (161 loc) · 4.49 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* === This file is part of ALICE O² ===
*
* Copyright 2018 CERN and copyright holders of ALICE O².
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/
package workflow
import (
"errors"
"github.com/AliceO2Group/Control/core/task"
"github.com/gobwas/glob"
)
type taskRole struct {
roleBase
Task *task.Task `yaml:"-,omitempty"`
LoadTaskClass string `yaml:"-,omitempty"`
}
func (t *taskRole) UnmarshalYAML(unmarshal func(interface{}) error) (err error) {
aux := struct{
Task struct{
Load string
}
}{}
type _taskRole taskRole
role := _taskRole{}
err = unmarshal(&role)
if err != nil {
return
}
err = unmarshal(&aux)
if err != nil {
return
}
role.LoadTaskClass = aux.Task.Load
*t = taskRole(role)
return
}
func (t *taskRole) GlobFilter(g glob.Glob) (rs []Role) {
if g.Match(t.GetPath()) {
rs = []Role{t}
}
return
}
func (t *taskRole) ProcessTemplates() (err error) {
if t == nil {
return errors.New("role tree error when processing templates")
}
t.resolveOutboundChannelTargets()
return
}
func (t* taskRole) UpdateStatus(s task.Status) {
t.updateStatus(s)
}
func (t* taskRole) UpdateState(s task.State) {
t.updateState(s)
}
func (t *taskRole) updateStatus(s task.Status) {
if t.parent == nil {
log.WithField("status", s.String()).Error("cannot update status with nil parent")
}
t.status.merge(s, t)
t.parent.updateStatus(s)
}
func (t *taskRole) updateState(s task.State) {
if t.parent == nil {
log.WithField("state", s.String()).Error("cannot update state with nil parent")
}
log.WithField("role", t.Name).WithField("state", s.String()).Debug("updating state")
t.state.merge(s, t)
t.parent.updateState(s)
}
func (t *taskRole) SetTask(taskPtr *task.Task) {
t.Task = taskPtr
}
func (t *taskRole) copy() copyable {
rCopy := taskRole{
roleBase: *t.roleBase.copy().(*roleBase),
Task: nil,
LoadTaskClass: t.LoadTaskClass,
}
rCopy.status = SafeStatus{status:task.INACTIVE}
rCopy.state = SafeState{state:task.STANDBY}
return &rCopy
}
func (t *taskRole) GenerateTaskDescriptors() (ds task.Descriptors) {
if t == nil {
return nil
}
ds = make(task.Descriptors, 0)
taskPtr := t.GetTask()
if taskPtr != nil { // If we already have a running task
return
}
ds = task.Descriptors{{
TaskRole: t,
TaskClassName: t.LoadTaskClass,
RoleConstraints: t.getConstraints(),
}}
return
}
func (t *taskRole) GetTasks() []*task.Task {
return []*task.Task{t.GetTask()}
}
func (t *taskRole) GetTask() *task.Task {
if t == nil {
return nil
}
return t.Task
}
func (t* taskRole) GetTaskClass() string {
if t == nil {
return ""
}
return t.LoadTaskClass
}
func (*taskRole) GetRoles() []Role {
return nil
}
//FIXME: figure out if nested doTransition calls are even desirable
// Intead of this stuff, we could have a similar method which does not perform a transition,
// but just builds the mesoscommand_transition and sends it.
// When calling workflow.doTransition it would still appear that we block until we return,
// but we'd have a first passage down the tree to acquire the list of Tasks and then taskman
// to build the MC and enqueue it
// It's critical to have a method which returns all tasks for a role
/*func (t *taskRole) doTransition(transition Transition) (task.Status, task.State) {
if t == nil || t.Task == nil {
return task.UNDEFINED, task.MIXED
}
if t.GetStatus() != task.ACTIVE {
return t.GetStatus(), task.MIXED
}
newState, err := t.Task.DoTransition(transition)
if err != nil {
log.WithError(err).Error("task transition error")
}
return t.GetStatus(), newState
}*/
func (t *taskRole) setParent(role Updatable) {
t.parent = role
}
func (t *taskRole) GetVars() task.VarMap {
panic("niy")
}