Skip to content

Commit ff44682

Browse files
committed
[core] Report a channel mismatch error on bad channel configuration
1 parent 2b6ea1a commit ff44682

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

core/task/channel/outbound.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package channel
2626

2727
import (
28+
"fmt"
2829
"strconv"
2930
"strings"
3031

@@ -97,8 +98,9 @@ chans.data1.0.type = pull
9798
chans.data1.numSockets = 1
9899
*/
99100

100-
func (outbound *Outbound) ToFMQMap(bindMap BindMap) (pm controlcommands.PropertyMap) {
101+
func (outbound *Outbound) ToFMQMap(bindMap BindMap) (pm controlcommands.PropertyMap, err error) {
101102
if outbound == nil {
103+
err = fmt.Errorf("outbound channel object is nil")
102104
return
103105
}
104106

@@ -110,24 +112,30 @@ func (outbound *Outbound) ToFMQMap(bindMap BindMap) (pm controlcommands.Property
110112
address = outbound.Target
111113
transport = outbound.Transport
112114
} else {
115+
matched := false
116+
113117
// we don't need class.Bind data for this one, only task.bindPorts after resolving paths!
114118
for chPath, endpoint := range bindMap {
119+
115120
// FIXME: implement more sophisticated channel matching here
116121
if outbound.Target == chPath {
117-
118122
// We have a match, so we generate a resolved target address and break
119123
address = endpoint.GetAddress()
120124
transport = endpoint.GetTransport()
125+
matched = true
121126
break
122127
}
123128
}
129+
if !matched {
130+
err = fmt.Errorf("could not match target for outbound channel %s", outbound.Target)
131+
}
124132
}
125133

126134
if len(address) == 0 {
127135
return
128136
}
129137

130-
return outbound.buildFMQMap(address, transport)
138+
return outbound.buildFMQMap(address, transport), err
131139
}
132140

133141
func (outbound *Outbound) buildFMQMap(address string, transport TransportType) (pm controlcommands.PropertyMap) {

core/task/task.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ import (
4040

4141
"github.com/AliceO2Group/Control/common"
4242
"github.com/AliceO2Group/Control/common/controlmode"
43+
"github.com/AliceO2Group/Control/common/event"
4344
"github.com/AliceO2Group/Control/common/gera"
4445
"github.com/AliceO2Group/Control/common/logger"
4546
"github.com/AliceO2Group/Control/common/utils"
46-
"github.com/AliceO2Group/Control/common/event"
4747
"github.com/AliceO2Group/Control/common/utils/uid"
4848
"github.com/AliceO2Group/Control/configuration/template"
4949
"github.com/AliceO2Group/Control/core/controlcommands"
@@ -247,6 +247,7 @@ func (t *Task) BuildTaskCommand(role parentRole) (err error) {
247247
// parametrizing these values for all control modes.
248248
// THIS BREAKS TASK CLASS REUSE! See OCTRL-227
249249
if class.Control.Mode == controlmode.BASIC ||
250+
class.Control.Mode == controlmode.HOOK ||
250251
class.Control.Mode == controlmode.DIRECT ||
251252
class.Control.Mode == controlmode.FAIRMQ {
252253
var varStack map[string]string
@@ -431,11 +432,12 @@ func fillCommonProperties(t *Task, propMap controlcommands.PropertyMap) {
431432
propMap["environment_id"] = envId.String()
432433
}
433434

434-
func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommands.PropertyMap) {
435+
func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommands.PropertyMap, err error) {
435436
propMap = make(controlcommands.PropertyMap)
436437
if class := t.GetTaskClass(); class != nil {
437438
if class.Control.Mode != controlmode.BASIC { // if it's NOT a basic task or hook, we template the props
438439
if t.GetParent() == nil {
440+
err = fmt.Errorf("cannot build property map for parentless task %s (id %s)", t.name, t.taskId)
439441
return
440442
}
441443

@@ -444,17 +446,18 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
444446

445447
// First we get the full varStack from the parent role, and
446448
// consolidate it.
447-
varStack, err := t.GetParent().ConsolidatedVarStack()
449+
var varStack map[string]string
450+
varStack, err = t.GetParent().ConsolidatedVarStack()
448451
if err != nil {
449-
log.WithError(err).Error("cannot fetch variables stack for property map")
452+
err = fmt.Errorf("cannot fetch variables stack for property map: %w", err)
450453
return
451454
}
452455

453456
// We wrap the parent varStack around the class Defaults, ensuring
454457
// the class Defaults are overridden by anything else.
455458
varStack, err = gera.MakeStringMapWithMap(varStack).WrappedAndFlattened(class.Defaults)
456459
if err != nil {
457-
log.WithError(err).Error("cannot fetch task class defaults for property map")
460+
err = fmt.Errorf("cannot fetch task class defaults for property map: %w", err)
458461
return
459462
}
460463

@@ -476,10 +479,10 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
476479
endpoint, ok := t.localBindMap[inbCh.Name]
477480
if !ok {
478481
log.WithFields(logrus.Fields{
479-
"channelName": inbCh.Name,
480-
"taskName": t.name,
481-
}).
482-
Error("endpoint not allocated for inbound channel")
482+
"channelName": inbCh.Name,
483+
"taskName": t.name,
484+
}).
485+
Warn("endpoint not allocated for inbound channel")
483486
continue
484487
}
485488

@@ -493,7 +496,11 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
493496
}
494497
for _, outboundCh := range channel.MergeOutbound(t.GetParent().CollectOutboundChannels(), class.Connect) {
495498
// We get the FairMQ-formatted propertyMap from the outbound channel spec
496-
chanProps := outboundCh.ToFMQMap(bindMap)
499+
var chanProps controlcommands.PropertyMap
500+
chanProps, err = outboundCh.ToFMQMap(bindMap)
501+
if err != nil {
502+
return nil, err
503+
}
497504

498505
// And if valid, we copy it into the task's propertyMap
499506
if len(chanProps) > 0 {
@@ -539,7 +546,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
539546
}
540547

541548
}
542-
return propMap
549+
return propMap, err
543550
}
544551

545552
func (t *Task) GetMesosCommandTarget() controlcommands.MesosCommandTarget {

core/task/tasks.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ func (m Tasks) BuildPropertyMaps(bindMap channel.BindMap) (propMapMap controlcom
109109
}
110110
receiver := task.GetMesosCommandTarget()
111111

112-
propMapMap[receiver] = task.BuildPropertyMap(bindMap)
112+
var taskPropMap controlcommands.PropertyMap
113+
taskPropMap, err = task.BuildPropertyMap(bindMap)
114+
if err != nil {
115+
return nil, err
116+
}
117+
propMapMap[receiver] = taskPropMap
113118
}
114119
return
115120
}

0 commit comments

Comments
 (0)