X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=151b14bc70b190e54273ae013ed3930ed5351de9;hb=b1ed7be0b303c9c6ec3744b82caf7d1c720ee19a;hp=ad62e36b4d4c259078b9f33c310a55b2675386af;hpb=40bc000e6cafe3a7eea32e4361268574050c12c4;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index ad62e36..151b14b 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -23,6 +23,7 @@ import ( "bytes" "encoding/json" "fmt" + "net" "net/http" "os" "os/signal" @@ -48,13 +49,14 @@ var ( // XApp is an application instance Rmr *RMRClient Sdl *SDLClient + SdlStorage *SDLStorage Rnib *RNIBClient Resource *Router Metric *Metrics Logger *Log Config Configurator Subscription *Subscriber - Alarm *AlarmClient + //Alarm *AlarmClient Util *Utils readyCb ReadyCB readyCbParams interface{} @@ -64,7 +66,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{}) { @@ -73,7 +75,7 @@ func SetReadyCB(cb ReadyCB, params interface{}) { } func XappReadyCb(params interface{}) { - Alarm = NewAlarmClient(viper.GetString("moId"), viper.GetString("name")) + //Alarm = NewAlarmClient(viper.GetString("moId"), viper.GetString("name")) if readyCb != nil { readyCb(readyCbParams) } @@ -262,24 +264,53 @@ 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() } +func getIpAdress() string { + var ip net.IP + itf, err := net.InterfaceByName(os.Getenv("INTERFACE_NAME")) + if err != nil { + Logger.Info("Interface name is not able to resolve " + err.Error()) + return ip.String() + } + item, err := itf.Addrs() + if err != nil { + Logger.Info("IP address is not able to resolve " + err.Error()) + return ip.String() + } + for _, addr := range item { + switch v := addr.(type) { + case *net.IPNet: + if !v.IP.IsLinkLocalUnicast() { + ip = v.IP + } + } + } + return ip.String() +} + func RunWithParams(c MessageConsumer, sdlcheck bool) { Rmr = NewRMRClient() Rmr.SetReadyCB(XappReadyCb, nil) - - host := fmt.Sprintf(":%d", GetPortData("http").Port) + ipString := getIpAdress() + var host string + if ipString == "" { + host = fmt.Sprintf(":%d", GetPortData("http").Port) + } else { + host = fmt.Sprintf("%s:%d", ipString, GetPortData("http").Port) + } go http.ListenAndServe(host, Resource.router) Logger.Info(fmt.Sprintf("Xapp started, listening on: %s", host)) if sdlcheck { - Sdl.TestConnection() + SdlStorage.TestConnection(viper.GetString("controls.db.namespace")) } go registerXapp()