Integrate RNIB with SDL SyncStorage to xapp-frame
[ric-plt/xapp-frame.git] / pkg / xapp / xapp.go
index f778265..96aa057 100755 (executable)
@@ -23,16 +23,24 @@ import (
        "bytes"
        "encoding/json"
        "fmt"
-       "github.com/spf13/viper"
        "net/http"
        "os"
        "os/signal"
        "strings"
        "sync/atomic"
        "syscall"
+       "testing"
        "time"
+
+       "github.com/spf13/viper"
 )
 
+// For testing purpose go version 1.13 ->
+var _ = func() bool {
+       testing.Init()
+       return true
+}()
+
 type ReadyCB func(interface{})
 type ShutdownCB func()
 
@@ -40,6 +48,7 @@ var (
        // XApp is an application instance
        Rmr           *RMRClient
        Sdl           *SDLClient
+       SdlStorage    *SDLStorage
        Rnib          *RNIBClient
        Resource      *Router
        Metric        *Metrics
@@ -56,7 +65,7 @@ var (
 )
 
 func IsReady() bool {
-       return Rmr != nil && Rmr.IsReady() && Sdl != nil && Sdl.IsReady()
+       return Rmr != nil && Rmr.IsReady() && SdlStorage != nil && SdlStorage.IsReady()
 }
 
 func SetReadyCB(cb ReadyCB, params interface{}) {
@@ -111,6 +120,8 @@ func getService(host, service string) string {
 
        svc := fmt.Sprintf(service, strings.ToUpper(appnamespace), strings.ToUpper(host))
        url := strings.Split(os.Getenv(strings.Replace(svc, "-", "_", -1)), "//")
+
+       Logger.Info("getService: %+v %+v", svc, url)
        if len(url) > 1 {
                return url[1]
        }
@@ -252,8 +263,9 @@ func init() {
        Config = Configurator{}
        Metric = NewMetrics(viper.GetString("metrics.url"), viper.GetString("metrics.namespace"), Resource.router)
        Subscription = NewSubscriber(viper.GetString("controls.subscription.host"), viper.GetInt("controls.subscription.timeout"))
+       SdlStorage = NewSdlStorage()
        Sdl = NewSDLClient(viper.GetString("controls.db.namespace"))
-       Rnib = NewRNIBClient()
+       Rnib = GetNewRnibClient(SdlStorage.db)
        Util = NewUtils()
 
        InstallSignalHandler()
@@ -269,7 +281,7 @@ func RunWithParams(c MessageConsumer, sdlcheck bool) {
        Logger.Info(fmt.Sprintf("Xapp started, listening on: %s", host))
 
        if sdlcheck {
-               Sdl.TestConnection()
+               SdlStorage.TestConnection(viper.GetString("controls.db.namespace"))
        }
        go registerXapp()