X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=124fbcfa34aa1b5b973168d7d898837b02050a1a;hb=refs%2Ftags%2Fv0.0.29;hp=d796afe95e31a1481bfc34d3b5e40dc91ff2392e;hpb=2e78e42c5896b61b77ab3a97e45704f6749161b2;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index d796afe..124fbcf 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -25,28 +25,46 @@ import ( "net/http" ) +type ReadyCB func(interface{}) + var ( // XApp is an application instance - Rmr *RMRClient - Sdl *SDLClient - UeNib *UENIBClient - Rnib *RNIBClient - Resource *Router - Metric *Metrics - Logger Log - Config Configurator + Rmr *RMRClient + Sdl *SDLClient + Rnib *RNIBClient + Resource *Router + Metric *Metrics + Logger *Log + Config Configurator + Subscription *Subscriber + readyCb ReadyCB + readyCbParams interface{} ) +func IsReady() bool { + return Rmr != nil && Rmr.IsReady() && Sdl != nil && Sdl.IsReady() +} + +func SetReadyCB(cb ReadyCB, params interface{}) { + readyCb = cb + readyCbParams = params +} + +func xappReadyCb(params interface{}) { + if readyCb != nil { + readyCb(readyCbParams) + } +} + func init() { // Load xapp configuration Logger = LoadConfig() Logger.SetLevel(viper.GetInt("logger.level")) - Rmr = NewRMRClient() Resource = NewRouter() Config = Configurator{} - UeNib = NewUENIBClient() Metric = NewMetrics(viper.GetString("metrics.url"), viper.GetString("metrics.namespace"), Resource.router) + Subscription = NewSubscriber(viper.GetString("subscription.host"), viper.GetInt("subscription.timeout")) if viper.IsSet("db.namespaces") { namespaces := viper.GetStringSlice("db.namespaces") @@ -61,11 +79,17 @@ func init() { } } -func Run(c MessageConsumer) { +func RunWithParams(c MessageConsumer, sdlcheck bool) { + Rmr = NewRMRClient() + Rmr.SetReadyCB(xappReadyCb, nil) go http.ListenAndServe(viper.GetString("local.host"), Resource.router) - Logger.Info(fmt.Sprintf("Xapp started, listening on: %s", viper.GetString("local.host"))) - - Sdl.TestConnection() + if sdlcheck { + Sdl.TestConnection() + } Rmr.Start(c) } + +func Run(c MessageConsumer) { + RunWithParams(c, true) +}