Backward compatible with old xApp descriptor 51/5051/1 v0.6.3
authorMohamed Abukar <abukar.mohamed@nokia.com>
Thu, 12 Nov 2020 08:02:41 +0000 (10:02 +0200)
committerMohamed Abukar <abukar.mohamed@nokia.com>
Thu, 12 Nov 2020 08:02:44 +0000 (10:02 +0200)
Change-Id: I390425c5e05b17f039e4bce5f99a02f788041ba2
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
config/config-file.json
pkg/xapp/config.go
pkg/xapp/db.go
pkg/xapp/rmr.go
pkg/xapp/xapp.go
pkg/xapp/xapp_test.go

index 5741d69..cacdde9 100755 (executable)
@@ -70,7 +70,8 @@
             "timeout": 5,
             "host": "service-ricplt-submgr-http.ricplt:8088",
             "clientEndpoint": "service-ricxapp-ueec-http.ricxapp:8080"
-        }
+        },
+        "waitForSdl": false
     },
     "metrics": {
         "url": "/ric/v1/metrics",
index bb76a07..8ab7941 100755 (executable)
@@ -63,7 +63,7 @@ func LoadConfig() (l *Log) {
        }
        l.Info("Using config file: %s", viper.ConfigFileUsed())
 
-       updatemtypes := func() {
+       updateMTypes := func() {
                var mtypes []mtype
                viper.UnmarshalKey("rmr.mtypes", &mtypes)
 
@@ -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("controls.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)
index a7302cd..e422cfd 100755 (executable)
@@ -73,6 +73,9 @@ type RNIBClient struct {
 
 // NewSDLClient returns a new SDLClient.
 func NewSDLClient(ns string) *SDLClient {
+       if ns == "" {
+               ns = "sdl"
+       }
        return &SDLClient{
                db:    sdl.NewSdlInstance(ns, sdl.NewDatabase()),
                stat:  Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
index 9407024..ef8aea5 100755 (executable)
@@ -67,6 +67,7 @@ import (
        "bytes"
        "crypto/md5"
        "fmt"
+       "github.com/spf13/viper"
        "strings"
        "time"
        "unsafe"
@@ -169,6 +170,16 @@ func NewRMRClientWithParams(params *RMRClientParams) *RMRClient {
 
 func NewRMRClient() *RMRClient {
        p := GetPortData("rmr-data")
+       if p.Port == 0 || viper.IsSet("rmr.protPort") {
+               // Old xApp descriptor used, fallback to rmr section
+               fmt.Sscanf(viper.GetString("rmr.protPort"), "tcp:%d", &p.Port)
+               p.MaxSize = viper.GetInt("rmr.maxSize")
+               p.ThreadType = viper.GetInt("rmr.threadType")
+               p.LowLatency = viper.GetBool("rmr.lowLatency")
+               p.FastAck = viper.GetBool("rmr.fastAck")
+               p.MaxRetryOnFailure = viper.GetInt("rmr.maxRetryOnFailure")
+       }
+
        return NewRMRClientWithParams(
                &RMRClientParams{
                        RmrData:  p,
index 5ab48ab..a9a130e 100755 (executable)
@@ -123,12 +123,16 @@ func init() {
        // Load xapp configuration
        Logger = LoadConfig()
 
-       Logger.SetLevel(viper.GetInt("controls.logger.level"))
+       if viper.IsSet("controls.logger.level") {
+               Logger.SetLevel(viper.GetInt("controls.logger.level"))
+       } else {
+               Logger.SetLevel(viper.GetInt("logger.level"))
+       }
        Resource = NewRouter()
        Config = Configurator{}
        Metric = NewMetrics(viper.GetString("metrics.url"), viper.GetString("metrics.namespace"), Resource.router)
        Subscription = NewSubscriber(viper.GetString("subscription.host"), viper.GetInt("subscription.timeout"))
-       Sdl = NewSDLClient(viper.GetString("db.namespace"))
+       Sdl = NewSDLClient(viper.GetString("controls.db.namespace"))
        Rnib = NewRNIBClient()
 
        InstallSignalHandler()
index abf9345..baafa16 100755 (executable)
@@ -44,7 +44,7 @@ func (m Consumer) Consume(params *RMRParams) (err error) {
 
 // Test cases
 func TestMain(m *testing.M) {
-       go RunWithParams(Consumer{}, viper.GetBool("db.waitForSdl"))
+       go RunWithParams(Consumer{}, viper.GetBool("controls.waitForSdl"))
        time.Sleep(time.Duration(5) * time.Second)
        code := m.Run()
        os.Exit(code)
@@ -122,7 +122,7 @@ func TestMessagesReceivedSuccessfully(t *testing.T) {
        // Allow time to process the messages
        time.Sleep(time.Duration(5) * time.Second)
 
-       waitForSdl := viper.GetBool("db.waitForSdl")
+       waitForSdl := viper.GetBool("controls.waitForSdl")
        stats := getMetrics(t)
        if !strings.Contains(stats, "ricxapp_RMR_Transmitted 100") {
                t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
@@ -168,7 +168,7 @@ func TestMessagesReceivedSuccessfullyUsingWh(t *testing.T) {
        // Allow time to process the messages
        time.Sleep(time.Duration(5) * time.Second)
 
-       waitForSdl := viper.GetBool("db.waitForSdl")
+       waitForSdl := viper.GetBool("controls.waitForSdl")
        stats := getMetrics(t)
        if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") {
                t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
@@ -210,7 +210,7 @@ func TestMessagesReceivedSuccessfullyUsingWhCall(t *testing.T) {
        // Allow time to process the messages
        time.Sleep(time.Duration(2) * time.Second)
 
-       waitForSdl := viper.GetBool("db.waitForSdl")
+       waitForSdl := viper.GetBool("controls.waitForSdl")
        stats := getMetrics(t)
        if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") {
                t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
@@ -240,7 +240,7 @@ func TestMessagesReceivedSuccessfullyUsingWhCall(t *testing.T) {
 
 func TestSubscribeChannels(t *testing.T) {
        Logger.Info("CASE: TestSubscribeChannels")
-       if !viper.GetBool("db.waitForSdl") {
+       if !viper.GetBool("controls.waitForSdl") {
                return
        }