X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fconfig.go;h=11daf4f6c9a6ee61785d08d04cad010f1d084ab8;hb=refs%2Fchanges%2F54%2F5154%2F2;hp=1b4b806daf2964c7d0da147a55a2c53c260c4884;hpb=f466893fdbf2f782bb2b2a8207d20c38c8dabdba;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/config.go b/pkg/xapp/config.go index 1b4b806..11daf4f 100755 --- a/pkg/xapp/config.go +++ b/pkg/xapp/config.go @@ -63,9 +63,9 @@ func LoadConfig() (l *Log) { } l.Info("Using config file: %s", viper.ConfigFileUsed()) - updatemtypes := func() { + updateMTypes := func() { var mtypes []mtype - viper.UnmarshalKey("rmr.mtypes", &mtypes) + viper.UnmarshalKey("messaging.mtypes", &mtypes) if len(mtypes) > 0 { l.Info("Config mtypes before RICMessageTypes:%d RicMessageTypeToName:%d", len(RICMessageTypes), len(RicMessageTypeToName)) @@ -92,14 +92,19 @@ func LoadConfig() (l *Log) { } } - updatemtypes() + updateMTypes() viper.WatchConfig() viper.OnConfigChange(func(e fsnotify.Event) { l.Info("config file %s changed ", e.Name) - updatemtypes() - Logger.SetLevel(viper.GetInt("logger.level")) + updateMTypes() + if viper.IsSet("controls.logger.level") { + Logger.SetLevel(viper.GetInt("controls.logger.level")) + } else { + Logger.SetLevel(viper.GetInt("logger.level")) + } + if len(ConfigChangeListeners) > 0 { for _, f := range ConfigChangeListeners { go f(e.Name) @@ -126,6 +131,53 @@ func PublishConfigChange(appName, eventJson string) error { return nil } +func GetPortData(pname string) (d PortData) { + var getPolicies = func(policies []interface{}) (plist []int) { + for _, p := range policies { + plist = append(plist, int(p.(float64))) + } + return plist + } + + if viper.IsSet("messaging") == false { + if pname == "http" { + d.Port = 8080 + } + if pname == "rmr-data" { + d.Port = 4560 + } + return + } + + for _, v := range viper.GetStringMap("messaging")["ports"].([]interface{}) { + if n, ok := v.(map[string]interface{})["name"].(string); ok && n == pname { + d.Name = n + if p, _ := v.(map[string]interface{})["port"].(float64); ok { + d.Port = int(p) + } + if m, _ := v.(map[string]interface{})["maxSize"].(float64); ok { + d.MaxSize = int(m) + } + if m, _ := v.(map[string]interface{})["threadType"].(float64); ok { + d.ThreadType = int(m) + } + if m, _ := v.(map[string]interface{})["lowLatency"].(bool); ok { + d.LowLatency = bool(m) + } + if m, _ := v.(map[string]interface{})["fastAck"].(bool); ok { + d.FastAck = bool(m) + } + if m, _ := v.(map[string]interface{})["maxRetryOnFailure"].(float64); ok { + d.MaxRetryOnFailure = int(m) + } + if policies, ok := v.(map[string]interface{})["policies"]; ok { + d.Policies = getPolicies(policies.([]interface{})) + } + } + } + return +} + func (*Configurator) SetSDLNotificationCB(appName string, sdlNotificationCb SDLNotificationCB) error { return Sdl.Subscribe(sdlNotificationCb, fmt.Sprintf("CM_UPDATE:%s", appName)) } @@ -157,3 +209,7 @@ func (*Configurator) GetStringSlice(key string) []string { func (*Configurator) GetStringMap(key string) map[string]interface{} { return viper.GetStringMap(key) } + +func (*Configurator) IsSet(key string) bool { + return viper.IsSet(key) +}