Backward compatible with old xApp descriptor

Change-Id: I390425c5e05b17f039e4bce5f99a02f788041ba2
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
diff --git a/config/config-file.json b/config/config-file.json
index 5741d69..cacdde9 100755
--- a/config/config-file.json
+++ b/config/config-file.json
@@ -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",
diff --git a/pkg/xapp/config.go b/pkg/xapp/config.go
index bb76a07..8ab7941 100755
--- a/pkg/xapp/config.go
+++ b/pkg/xapp/config.go
@@ -63,7 +63,7 @@
 	}
 	l.Info("Using config file: %s", viper.ConfigFileUsed())
 
-	updatemtypes := func() {
+	updateMTypes := func() {
 		var mtypes []mtype
 		viper.UnmarshalKey("rmr.mtypes", &mtypes)
 
@@ -92,14 +92,19 @@
 		}
 	}
 
-	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)
diff --git a/pkg/xapp/db.go b/pkg/xapp/db.go
index a7302cd..e422cfd 100755
--- a/pkg/xapp/db.go
+++ b/pkg/xapp/db.go
@@ -73,6 +73,9 @@
 
 // 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"),
diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go
index 9407024..ef8aea5 100755
--- a/pkg/xapp/rmr.go
+++ b/pkg/xapp/rmr.go
@@ -67,6 +67,7 @@
 	"bytes"
 	"crypto/md5"
 	"fmt"
+	"github.com/spf13/viper"
 	"strings"
 	"time"
 	"unsafe"
@@ -169,6 +170,16 @@
 
 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,
diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go
index 5ab48ab..a9a130e 100755
--- a/pkg/xapp/xapp.go
+++ b/pkg/xapp/xapp.go
@@ -123,12 +123,16 @@
 	// 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()
diff --git a/pkg/xapp/xapp_test.go b/pkg/xapp/xapp_test.go
index abf9345..baafa16 100755
--- a/pkg/xapp/xapp_test.go
+++ b/pkg/xapp/xapp_test.go
@@ -44,7 +44,7 @@
 
 // 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 @@
 	// 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 @@
 	// 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 @@
 	// 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 TestSubscribeChannels(t *testing.T) {
 	Logger.Info("CASE: TestSubscribeChannels")
-	if !viper.GetBool("db.waitForSdl") {
+	if !viper.GetBool("controls.waitForSdl") {
 		return
 	}