GetPortData() returns policies
[ric-plt/xapp-frame.git] / pkg / xapp / config.go
index 1b4b806..bb76a07 100755 (executable)
@@ -99,7 +99,7 @@ func LoadConfig() (l *Log) {
                l.Info("config file %s changed ", e.Name)
 
                updatemtypes()
-               Logger.SetLevel(viper.GetInt("logger.level"))
+               Logger.SetLevel(viper.GetInt("controls.logger.level"))
                if len(ConfigChangeListeners) > 0 {
                        for _, f := range ConfigChangeListeners {
                                go f(e.Name)
@@ -126,6 +126,43 @@ 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
+       }
+
+       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))
 }