Skip to content

Commit 30a2dc2

Browse files
miltalexteo
authored andcommitted
[core] Add GetRuntimeConfig func in templates
1 parent d7cb32a commit 30a2dc2

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

configuration/template/fields.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type ConfigurationService interface {
5555
GetDetectorsForHosts(hosts []string) ([]string, error)
5656
GetCRUCardsForHost(hostname string) (string, error)
5757
GetEndpointsForCRUCard(hostname, cardSerial string) (string, error)
58+
GetRuntimeEntry(component string, key string) (string, error)
5859
}
5960

6061
func (sf Sequence) Execute(confSvc ConfigurationService, parentPath string, varStack VarStack, buildObjectStack BuildObjectStackFunc, stringTemplateCache map[string]template.Template) (err error) {
@@ -206,8 +207,8 @@ func (fields Fields) Execute(confSvc ConfigurationService, parentPath string, va
206207
environment[k] = v
207208
}
208209

209-
CRUCardconfigAccessFuncs := MakeConfigAccessFuncsCRUCard(confSvc, varStack)
210-
for k, v := range CRUCardconfigAccessFuncs {
210+
multiVarconfigAccessFuncs := MakeConfigAccessFuncsMultiVar(confSvc, varStack)
211+
for k, v := range multiVarconfigAccessFuncs {
211212
environment[k] = v
212213
}
213214

configuration/template/stack.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ import (
4242
type GetConfigFunc func(string) string
4343
type ConfigAccessFuncs map[string]GetConfigFunc
4444
type ToPtreeFunc func(string, string) string
45-
type CRUCardConfigAccessFuncs map[string]GetCRUCardConfigFunc
46-
type GetCRUCardConfigFunc func(string, string) string
47-
45+
type MultiVarConfigAccessFuncs map[string]GetMultiVarConfigFunc
46+
type GetMultiVarConfigFunc func(string, string) string
4847

4948
func MakeConfigAccessFuncs(confSvc ConfigurationService, varStack map[string]string) ConfigAccessFuncs {
5049
return ConfigAccessFuncs{
5150
"GetConfigLegacy": func(path string) string {
52-
defer utils.TimeTrack(time.Now(),"GetConfigLegacy", log.WithPrefix("template"))
51+
defer utils.TimeTrack(time.Now(), "GetConfigLegacy", log.WithPrefix("template"))
5352
query, err := componentcfg.NewQuery(path)
5453
if err != nil {
5554
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
@@ -128,20 +127,29 @@ func MakeConfigAccessFuncs(confSvc ConfigurationService, varStack map[string]str
128127
}
129128
}
130129

131-
func MakeConfigAccessFuncsCRUCard(confSvc ConfigurationService, varStack map[string]string) CRUCardConfigAccessFuncs {
132-
return CRUCardConfigAccessFuncs{
130+
func MakeConfigAccessFuncsMultiVar(confSvc ConfigurationService, varStack map[string]string) MultiVarConfigAccessFuncs {
131+
return MultiVarConfigAccessFuncs{
133132
"EndpointsForCRUCard": func(hostname, cardSerial string) string {
134-
defer utils.TimeTrack(time.Now(),"EndpointsForCRUCard", log.WithPrefix("template"))
133+
defer utils.TimeTrack(time.Now(), "EndpointsForCRUCard", log.WithPrefix("template"))
135134
payload, err := confSvc.GetEndpointsForCRUCard(hostname, cardSerial)
136135
if err != nil {
137136
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
138137
}
139138
return payload
140139
},
140+
"GetRuntimeConfig": func(component string, key string) string {
141+
defer utils.TimeTrack(time.Now(), "GetRuntimeConfig", log.WithPrefix("template"))
142+
143+
payload, err := confSvc.GetRuntimeEntry(component, key)
144+
if err != nil {
145+
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
146+
}
147+
148+
return payload
149+
},
141150
}
142151
}
143152

144-
145153
func MakeToPtreeFunc(varStack map[string]string, propMap map[string]string) ToPtreeFunc {
146154
return func(payload string, syntax string) string {
147155
// This function is a no-op with respect to the payload, but it stores the payload

core/integration/ctp/plugin.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/AliceO2Group/Control/common/utils/uid"
3939
"github.com/AliceO2Group/Control/core/integration"
4040
ctpecspb "github.com/AliceO2Group/Control/core/integration/ctp/protos"
41-
"github.com/AliceO2Group/Control/core/the"
4241
"github.com/AliceO2Group/Control/core/workflow/callable"
4342
"github.com/spf13/viper"
4443
"google.golang.org/grpc"
@@ -194,17 +193,10 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
194193
stack["RunStart"] = func() (out string) { // must formally return string even when we return nothing
195194
log.Debug("performing CTP Run Start")
196195

197-
parameters, ok := varStack["ctp_runtime_config"]
196+
runtimeConfig, ok := varStack["ctp_runtime_config"]
198197
if !ok {
199198
log.Debug("no CTP config set, using default configuration")
200-
parameters = ""
201-
}
202-
ctpConfig, ctpErr := the.ConfSvc().GetRuntimeEntry("ctp", parameters)
203-
if ctpErr != nil {
204-
log.WithError(ctpErr).
205-
WithField("endpoint", viper.GetString("ctpServiceEndpoint")).
206-
Error("failed to load config")
207-
return
199+
runtimeConfig = ""
208200
}
209201

210202
rn := varStack["run_number"]
@@ -235,7 +227,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
235227
in := ctpecspb.RunStartRequest{
236228
Runn: uint32(runNumber64),
237229
Detector: detectors,
238-
Config: ctpConfig,
230+
Config: runtimeConfig,
239231
}
240232

241233
if p.ctpClient == nil {

0 commit comments

Comments
 (0)