Skip to content

Commit

Permalink
[core] Add GetRuntimeConfig func in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
miltalex authored and teo committed Oct 8, 2021
1 parent d7cb32a commit 30a2dc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions configuration/template/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ConfigurationService interface {
GetDetectorsForHosts(hosts []string) ([]string, error)
GetCRUCardsForHost(hostname string) (string, error)
GetEndpointsForCRUCard(hostname, cardSerial string) (string, error)
GetRuntimeEntry(component string, key string) (string, error)
}

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

CRUCardconfigAccessFuncs := MakeConfigAccessFuncsCRUCard(confSvc, varStack)
for k, v := range CRUCardconfigAccessFuncs {
multiVarconfigAccessFuncs := MakeConfigAccessFuncsMultiVar(confSvc, varStack)
for k, v := range multiVarconfigAccessFuncs {
environment[k] = v
}

Expand Down
24 changes: 16 additions & 8 deletions configuration/template/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ import (
type GetConfigFunc func(string) string
type ConfigAccessFuncs map[string]GetConfigFunc
type ToPtreeFunc func(string, string) string
type CRUCardConfigAccessFuncs map[string]GetCRUCardConfigFunc
type GetCRUCardConfigFunc func(string, string) string

type MultiVarConfigAccessFuncs map[string]GetMultiVarConfigFunc
type GetMultiVarConfigFunc func(string, string) string

func MakeConfigAccessFuncs(confSvc ConfigurationService, varStack map[string]string) ConfigAccessFuncs {
return ConfigAccessFuncs{
"GetConfigLegacy": func(path string) string {
defer utils.TimeTrack(time.Now(),"GetConfigLegacy", log.WithPrefix("template"))
defer utils.TimeTrack(time.Now(), "GetConfigLegacy", log.WithPrefix("template"))
query, err := componentcfg.NewQuery(path)
if err != nil {
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
Expand Down Expand Up @@ -128,20 +127,29 @@ func MakeConfigAccessFuncs(confSvc ConfigurationService, varStack map[string]str
}
}

func MakeConfigAccessFuncsCRUCard(confSvc ConfigurationService, varStack map[string]string) CRUCardConfigAccessFuncs {
return CRUCardConfigAccessFuncs{
func MakeConfigAccessFuncsMultiVar(confSvc ConfigurationService, varStack map[string]string) MultiVarConfigAccessFuncs {
return MultiVarConfigAccessFuncs{
"EndpointsForCRUCard": func(hostname, cardSerial string) string {
defer utils.TimeTrack(time.Now(),"EndpointsForCRUCard", log.WithPrefix("template"))
defer utils.TimeTrack(time.Now(), "EndpointsForCRUCard", log.WithPrefix("template"))
payload, err := confSvc.GetEndpointsForCRUCard(hostname, cardSerial)
if err != nil {
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
}
return payload
},
"GetRuntimeConfig": func(component string, key string) string {
defer utils.TimeTrack(time.Now(), "GetRuntimeConfig", log.WithPrefix("template"))

payload, err := confSvc.GetRuntimeEntry(component, key)
if err != nil {
return fmt.Sprintf("{\"error\":\"%s\"}", err.Error())
}

return payload
},
}
}


func MakeToPtreeFunc(varStack map[string]string, propMap map[string]string) ToPtreeFunc {
return func(payload string, syntax string) string {
// This function is a no-op with respect to the payload, but it stores the payload
Expand Down
14 changes: 3 additions & 11 deletions core/integration/ctp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/AliceO2Group/Control/common/utils/uid"
"github.com/AliceO2Group/Control/core/integration"
ctpecspb "github.com/AliceO2Group/Control/core/integration/ctp/protos"
"github.com/AliceO2Group/Control/core/the"
"github.com/AliceO2Group/Control/core/workflow/callable"
"github.com/spf13/viper"
"google.golang.org/grpc"
Expand Down Expand Up @@ -194,17 +193,10 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
stack["RunStart"] = func() (out string) { // must formally return string even when we return nothing
log.Debug("performing CTP Run Start")

parameters, ok := varStack["ctp_runtime_config"]
runtimeConfig, ok := varStack["ctp_runtime_config"]
if !ok {
log.Debug("no CTP config set, using default configuration")
parameters = ""
}
ctpConfig, ctpErr := the.ConfSvc().GetRuntimeEntry("ctp", parameters)
if ctpErr != nil {
log.WithError(ctpErr).
WithField("endpoint", viper.GetString("ctpServiceEndpoint")).
Error("failed to load config")
return
runtimeConfig = ""
}

rn := varStack["run_number"]
Expand Down Expand Up @@ -235,7 +227,7 @@ func (p *Plugin) ObjectStack(data interface{}) (stack map[string]interface{}) {
in := ctpecspb.RunStartRequest{
Runn: uint32(runNumber64),
Detector: detectors,
Config: ctpConfig,
Config: runtimeConfig,
}

if p.ctpClient == nil {
Expand Down

0 comments on commit 30a2dc2

Please sign in to comment.