Skip to content

Commit 4fb6ba0

Browse files
committed
[core] Avoid direct Apricot defaults/vars calls from ODC client
1 parent 6087eaa commit 4fb6ba0

2 files changed

Lines changed: 35 additions & 22 deletions

File tree

core/environment/environment.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"sync"
3535
"time"
3636

37-
"github.com/AliceO2Group/Control/apricot"
3837
"github.com/AliceO2Group/Control/common/event"
3938
"github.com/AliceO2Group/Control/common/gera"
4039
"github.com/AliceO2Group/Control/common/logger"
@@ -68,14 +67,16 @@ type Environment struct {
6867
hookHandlerF func(hooks task.Tasks) error
6968
incomingEvents chan event.DeviceEvent
7069

71-
GlobalDefaults gera.StringMap // From Consul
72-
GlobalVars gera.StringMap // From Consul
73-
UserVars gera.StringMap // From user input
74-
stateChangedCh chan *event.TasksStateChangedEvent
75-
unsubscribe chan struct{}
76-
eventStream Subscription
77-
Public bool // From workflow or user
78-
Description string // From workflow
70+
GlobalDefaults gera.StringMap // From Consul
71+
GlobalVars gera.StringMap // From Consul
72+
UserVars gera.StringMap // From user input
73+
BaseConfigStack map[string]string // Exclusively from Consul, already flattened for performance
74+
75+
stateChangedCh chan *event.TasksStateChangedEvent
76+
unsubscribe chan struct{}
77+
eventStream Subscription
78+
Public bool // From workflow or user
79+
Description string // From workflow
7980

8081
callsPendingAwait map[string] /*await expression, trigger only*/ callable.CallsMap
8182

@@ -123,6 +124,12 @@ func newEnvironment(userVars map[string]string) (env *Environment, err error) {
123124
)
124125
env.GlobalVars.Set("__fmq_cleanup_count", "0") // initialize to 0 the number of START transitions
125126

127+
env.BaseConfigStack, err = gera.MakeStringMapWithMap(env.GlobalVars.Raw()).
128+
WrappedAndFlattened(gera.MakeStringMapWithMap(env.GlobalDefaults.Raw())) // prepare the base config stack
129+
if err != nil {
130+
return nil, err
131+
}
132+
126133
// We start with STANDBY, which will not be preceded with enter_STANDBY, thus we set the value here.
127134
enterStateTimeMs := strconv.FormatInt(time.Now().UnixMilli(), 10)
128135
env.UserVars.Set("enter_state_time_ms", enterStateTimeMs)
@@ -171,14 +178,12 @@ func newEnvironment(userVars map[string]string) (env *Environment, err error) {
171178
}
172179
env.GlobalVars.Set("__fmq_cleanup_count", strconv.Itoa(cleanupCount)) // number of times the START transition has run for this env
173180

174-
configStack, err := gera.MakeStringMapWithMap(apricot.Instance().GetVars()).
175-
WrappedAndFlattened(gera.MakeStringMapWithMap(the.ConfSvc().GetDefaults()))
176181
if err == nil {
177-
lhcPeriod, ok := configStack["lhc_period"]
182+
lhcPeriod, ok := env.BaseConfigStack["lhc_period"]
178183
if ok {
179184
env.workflow.GetVars().Set("lhc_period", lhcPeriod)
180185
}
181-
nHbfPerTf, ok := configStack["n_hbf_per_tf"]
186+
nHbfPerTf, ok := env.BaseConfigStack["n_hbf_per_tf"]
182187
if ok {
183188
env.workflow.GetVars().Set("n_hbf_per_tf", nHbfPerTf)
184189
}

core/integration/odc/plugin.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import (
3939
"time"
4040

4141
"github.com/AliceO2Group/Control/apricot"
42-
"github.com/AliceO2Group/Control/common/gera"
4342
"github.com/AliceO2Group/Control/common/logger/infologger"
4443
"github.com/AliceO2Group/Control/common/utils/uid"
44+
"github.com/AliceO2Group/Control/core/environment"
4545
"github.com/AliceO2Group/Control/core/integration"
4646
odc "github.com/AliceO2Group/Control/core/integration/odc/protos"
4747
"github.com/AliceO2Group/Control/core/workflow/callable"
@@ -258,17 +258,14 @@ func (p *Plugin) Init(_ string) error {
258258
}
259259

260260
func (p *Plugin) ObjectStack(varStack map[string]string) (stack map[string]interface{}) {
261-
envId, ok := varStack["environment_id"]
262-
if !ok {
261+
envId, envIdOk := varStack["environment_id"]
262+
if !envIdOk {
263263
log.Error("ObjectStack cannot acquire environment ID")
264264
return
265265
}
266-
267-
var csErr error
268-
configStack := apricot.Instance().GetDefaults()
269-
configStack, csErr = gera.MakeStringMapWithMap(apricot.Instance().GetVars()).WrappedAndFlattened(gera.MakeStringMapWithMap(configStack))
270-
if csErr != nil {
271-
log.Error("cannot access AliECS workflow configuration defaults")
266+
envUid, err := uid.FromString(envId)
267+
if err != nil {
268+
log.Error("ObjectStack cannot parse environment ID")
272269
return
273270
}
274271

@@ -316,6 +313,17 @@ func (p *Plugin) ObjectStack(varStack map[string]string) (stack map[string]inter
316313
)
317314
accumulator = make([]string, 0)
318315

316+
envMan := environment.ManagerInstance()
317+
myEnv, err := envMan.Environment(envUid)
318+
if err != nil {
319+
log.WithError(err).
320+
WithField("partition", envId).
321+
WithField("call", "GenerateEPNWorkflowScript").
322+
Error("cannot acquire environment reference")
323+
return
324+
}
325+
configStack := myEnv.BaseConfigStack
326+
319327
pdpConfigOption, ok = varStack["pdp_config_option"]
320328
if !ok {
321329
log.WithField("partition", envId).

0 commit comments

Comments
 (0)