Skip to content

Commit 48bd01b

Browse files
committed
[core] Resolve outbound channel targets for all role types
1 parent 9d23766 commit 48bd01b

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

core/workflow/aggregatorrole.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (r *aggregatorRole) UnmarshalYAML(unmarshal func(interface{}) error) (err e
5555
*r = role
5656
for _, v := range r.Roles {
5757
v.setParent(r)
58+
v.resolveOutboundChannelTargets()
5859
}
5960
return
6061
}

core/workflow/iteratorrole.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ package workflow
2626

2727
import (
2828
"errors"
29-
"strconv"
29+
"strconv"
30+
3031
"github.com/AliceO2Group/Control/core/task"
3132
"github.com/AliceO2Group/Control/core/task/constraint"
3233
)
@@ -116,6 +117,15 @@ func (f *iteratorInfo) UnmarshalYAML(unmarshal func(interface{}) error) (err err
116117
return
117118
}
118119

120+
func (i *iteratorRole) resolveOutboundChannelTargets() {
121+
if i == nil || i.Roles == nil {
122+
return
123+
}
124+
for _, r := range i.Roles {
125+
r.resolveOutboundChannelTargets()
126+
}
127+
}
128+
119129
func (i *iteratorRole) expandTemplate() (err error) {
120130
values := make(templateMap)
121131

core/workflow/role.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Role interface {
4747
GenerateTaskDescriptors() task.Descriptors
4848
getConstraints() constraint.Constraints
4949
setParent(role Updatable)
50+
resolveOutboundChannelTargets()
5051
}
5152

5253
type Updatable interface {

core/workflow/rolebase.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
package workflow
2626

2727
import (
28-
"github.com/AliceO2Group/Control/core/task/channel"
29-
"github.com/AliceO2Group/Control/common/logger"
30-
"github.com/sirupsen/logrus"
31-
"github.com/jinzhu/copier"
3228
"bytes"
3329
"fmt"
3430
"text/template"
3531

32+
"github.com/AliceO2Group/Control/common/logger"
33+
"github.com/AliceO2Group/Control/core/task/channel"
34+
"github.com/jinzhu/copier"
35+
"github.com/sirupsen/logrus"
36+
3637
"github.com/AliceO2Group/Control/core/task"
37-
"github.com/pborman/uuid"
3838
"github.com/AliceO2Group/Control/core/task/constraint"
39+
"github.com/pborman/uuid"
3940
)
4041

4142
var log = logger.New(logrus.StandardLogger(), "workflow")
@@ -79,8 +80,6 @@ func (r *roleBase) UnmarshalYAML(unmarshal func(interface{}) error) (err error)
7980
if err == nil {
8081
*r = roleBase(role)
8182
}
82-
83-
r.resolveOutboundChannelTargets()
8483
return
8584
}
8685

@@ -102,9 +101,12 @@ func (r *roleBase) resolveOutboundChannelTargets() {
102101
}
103102
return p.GetPath()
104103
},
105-
"up": func(levels uint) string {
104+
"up": func(levels int) string {
105+
if levels <= 0 {
106+
return r.GetPath()
107+
}
106108
var p _parentRole = r
107-
for i := levels - 1; i >= 0; i-- {
109+
for i := 0; i < levels; i++ {
108110
p = p.GetParentRole()
109111
if p == nil {
110112
log.WithFields(logrus.Fields{"error": "role has no ancestor", "role": r.GetPath()}).Error("workflow configuration error")
@@ -115,7 +117,7 @@ func (r *roleBase) resolveOutboundChannelTargets() {
115117
},
116118
}
117119

118-
for _, ch := range r.Connect {
120+
for i, ch := range r.Connect {
119121
tmpl := template.New(r.GetPath())
120122
parsed, err := tmpl.Funcs(funcMap).Parse(ch.Target)
121123
if err != nil {
@@ -129,7 +131,7 @@ func (r *roleBase) resolveOutboundChannelTargets() {
129131
continue
130132
}
131133
// Finally we write the result back to the target string
132-
ch.Target = buf.String()
134+
r.Connect[i].Target = buf.String()
133135
}
134136
}
135137

0 commit comments

Comments
 (0)