X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=12f1628db48373913f7fd27fdaf03bfa3208d7b4;hb=refs%2Fchanges%2F67%2F8567%2F1;hp=0e85845be990680f503ea58a6423cf16d74af59f;hpb=fea604a8972776006ac5231425ea5799a93cf06c;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index 0e85845..12f1628 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -37,6 +37,7 @@ import ( ) // For testing purpose go version 1.13 -> + var _ = func() bool { testing.Init() return true @@ -49,6 +50,7 @@ var ( // XApp is an application instance Rmr *RMRClient Sdl *SDLClient + SdlStorage *SDLStorage Rnib *RNIBClient Resource *Router Metric *Metrics @@ -64,8 +66,18 @@ var ( shutdownCnt int32 ) +var startTime time.Time + +func XappUpTime() time.Duration { + return time.Since(startTime) +} + +func init() { + startTime = time.Now() +} + 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{}) { @@ -100,7 +112,7 @@ func registerXapp() { for { time.Sleep(5 * time.Second) if !IsHealthProbeReady() { - Logger.Info("Application='%s' is not ready yet, waiting ...", viper.GetString("name")) + Logger.Debug("Application='%s' is not ready yet, waiting ...", viper.GetString("name")) continue } @@ -154,6 +166,7 @@ func doRegister() error { xappversion := viper.GetString("version") pltNs := getPltNamespace("PLT_NAMESPACE", DEFAULT_PLT_NS) + //httpEp, rmrEp := getService(xappname, SERVICE_HTTP), getService(xappname, SERVICE_RMR) httpEp, rmrEp := getService(host, SERVICE_HTTP), getService(host, SERVICE_RMR) if httpEp == "" || rmrEp == "" { Logger.Warn("Couldn't resolve service endpoints: httpEp=%s rmrEp=%s", httpEp, rmrEp) @@ -263,52 +276,54 @@ 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")) +func GetIpAddress() (string, error) { + ifname := os.Getenv("INTERFACE_NAME") + itf, err := net.InterfaceByName(ifname) if err != nil { - Logger.Info("Interface name is not able to resolve " + err.Error()) - return ip.String() + return "", fmt.Errorf("Interface (%s) %w", ifname, err) } item, err := itf.Addrs() if err != nil { - Logger.Info("IP address is not able to resolve " + err.Error()) - return ip.String() + return "", fmt.Errorf("Interface (%s) %w", ifname, err) } for _, addr := range item { switch v := addr.(type) { case *net.IPNet: if !v.IP.IsLinkLocalUnicast() { - ip = v.IP + return v.IP.String(), nil } } } - return ip.String() + return "", fmt.Errorf("Interface (%s) couldn't find ip", ifname) } func RunWithParams(c MessageConsumer, sdlcheck bool) { Rmr = NewRMRClient() Rmr.SetReadyCB(XappReadyCb, nil) - ipString := getIpAdress() + ipString, err := GetIpAddress() + if err != nil { + Logger.Info("IP address is not able to resolve " + err.Error()) + } var host string if ipString == "" { host = fmt.Sprintf(":%d", GetPortData("http").Port) } else { - host = fmt.Sprintf("%s:%d", ipString, GetPortData("http").Port) + 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()