X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=96aa0577d47dc2b905897821e3595c6032fe5030;hb=b733d3feaf729312e2c8dbdd7f8ce30c54b68588;hp=1f02285aa1e812cbde97191b6b84fdd1d4770f59;hpb=256c304042f0cd6c766db505fe5b03bbc3163fef;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index 1f02285..96aa057 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -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 @@ -47,6 +56,7 @@ var ( Config Configurator Subscription *Subscriber Alarm *AlarmClient + Util *Utils readyCb ReadyCB readyCbParams interface{} shutdownCb ShutdownCB @@ -55,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{}) { @@ -90,13 +100,13 @@ func registerXapp() { for { time.Sleep(5 * time.Second) if !IsHealthProbeReady() { - Logger.Info("xApp is not ready yet, waiting ...") + Logger.Info("Application='%s' is not ready yet, waiting ...", viper.GetString("name")) continue } - Logger.Info("xApp is now up and ready, continue with registration ...") + Logger.Debug("Application='%s' is now up and ready, continue with registration ...", viper.GetString("name")) if err := doRegister(); err == nil { - Logger.Info("xApp registration done, proceeding with startup ...") + Logger.Info("Registration done, proceeding with startup ...") break } } @@ -110,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] } @@ -242,14 +254,19 @@ func init() { } else { Logger.SetLevel(viper.GetInt("logger.level")) } - Logger.SetFormat(0) + + if !viper.IsSet("controls.logger.noFormat") || !viper.GetBool("controls.logger.noFormat") { + Logger.SetFormat(0) + } 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")) + 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() } @@ -264,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()