Skip to content

Commit e0f0f81

Browse files
committed
[core] Role path globbing support
1 parent 0ed4a0a commit e0f0f81

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

core/workflow/aggregatorrole.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"errors"
2929

3030
"github.com/AliceO2Group/Control/core/task"
31+
"github.com/gobwas/glob"
3132
"github.com/sirupsen/logrus"
3233
)
3334

@@ -61,6 +62,20 @@ func (r *aggregatorRole) UnmarshalYAML(unmarshal func(interface{}) error) (err e
6162
return
6263
}
6364

65+
func (r *aggregatorRole) GlobFilter(g glob.Glob) (rs []Role) {
66+
rs = make([]Role, 0)
67+
if g.Match(r.GetPath()) {
68+
rs = append(rs, r)
69+
}
70+
for _, chr := range r.Roles {
71+
chrs := chr.GlobFilter(g)
72+
if len(chrs) != 0 {
73+
rs = append(rs, chrs...)
74+
}
75+
}
76+
return
77+
}
78+
6479
func (r *aggregatorRole) ProcessTemplates() (err error) {
6580
if r == nil {
6681
return errors.New("role tree error when processing templates")
@@ -110,6 +125,7 @@ func (r *aggregatorRole) updateState(s task.State) {
110125
if r == nil {
111126
return
112127
}
128+
log.WithField("role", r.Name).WithField("state", s.String()).Debug("updating state")
113129
r.state.merge(s, r)
114130
if r.parent != nil {
115131
r.parent.updateState(r.state.get())

core/workflow/iteratorrole.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/AliceO2Group/Control/core/task"
3232
"github.com/AliceO2Group/Control/core/task/constraint"
33+
"github.com/gobwas/glob"
3334
)
3435

3536
type iteratorRole struct {
@@ -117,6 +118,17 @@ func (f *iteratorInfo) UnmarshalYAML(unmarshal func(interface{}) error) (err err
117118
return
118119
}
119120

121+
func (i *iteratorRole) GlobFilter(g glob.Glob) (rs []Role) {
122+
rs = make([]Role, 0)
123+
for _, chr := range i.Roles {
124+
chrs := chr.GlobFilter(g)
125+
if len(chrs) != 0 {
126+
rs = append(rs, chrs...)
127+
}
128+
}
129+
return
130+
}
131+
120132
func (i *iteratorRole) ProcessTemplates() (err error) {
121133
if i == nil {
122134
return errors.New("role tree error when processing templates")

core/workflow/role.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/AliceO2Group/Control/core/task"
3333
"github.com/AliceO2Group/Control/core/task/channel"
3434
"github.com/AliceO2Group/Control/core/task/constraint"
35+
"github.com/gobwas/glob"
3536
"github.com/pborman/uuid"
3637
)
3738

@@ -49,6 +50,7 @@ type Role interface {
4950
getConstraints() constraint.Constraints
5051
setParent(role Updatable)
5152
ProcessTemplates() error
53+
GlobFilter(g glob.Glob) []Role
5254
}
5355

5456
type Updatable interface {

core/workflow/rolebase.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ import (
4141

4242
var log = logger.New(logrus.StandardLogger(), "workflow")
4343

44-
const PATH_SEPARATOR = "."
44+
const(
45+
PATH_SEPARATOR = "."
46+
PATH_SEPARATOR_RUNE = '.'
47+
)
48+
4549

4650
type roleBase struct {
4751
Name string `yaml:"name"`
@@ -231,7 +235,7 @@ func (r *roleBase) GetStatus() task.Status {
231235

232236
func (r *roleBase) GetState() task.State {
233237
if r == nil {
234-
return ""
238+
return task.UNKNOWN
235239
}
236240
return r.state.get()
237241
}

core/workflow/taskrole.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"errors"
2929

3030
"github.com/AliceO2Group/Control/core/task"
31+
"github.com/gobwas/glob"
3132
)
3233

3334
type taskRole struct {
@@ -61,6 +62,13 @@ func (t *taskRole) UnmarshalYAML(unmarshal func(interface{}) error) (err error)
6162
return
6263
}
6364

65+
func (t *taskRole) GlobFilter(g glob.Glob) (rs []Role) {
66+
if g.Match(t.GetPath()) {
67+
rs = []Role{t}
68+
}
69+
return
70+
}
71+
6472
func (t *taskRole) ProcessTemplates() (err error) {
6573
if t == nil {
6674
return errors.New("role tree error when processing templates")
@@ -91,6 +99,7 @@ func (t *taskRole) updateState(s task.State) {
9199
if t.parent == nil {
92100
log.WithField("state", s.String()).Error("cannot update state with nil parent")
93101
}
102+
log.WithField("role", t.Name).WithField("state", s.String()).Debug("updating state")
94103
t.state.merge(s, t)
95104
t.parent.updateState(s)
96105
}

0 commit comments

Comments
 (0)