X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=583d2889d6362b4260181e259d2a96ed6d03c4ee;hb=82651fe96c123b61252dfef755ce7b9882e7db97;hp=e8f47ef6202f4eea6205f951780a5ed98d7733bc;hpb=dba83dfb6f135fb2f6987e55beec8552c6a8b74e;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index e8f47ef..583d288 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -23,17 +23,26 @@ import ( "bytes" "encoding/json" "fmt" + "net" "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() @@ -41,6 +50,7 @@ var ( // XApp is an application instance Rmr *RMRClient Sdl *SDLClient + SdlStorage *SDLStorage Rnib *RNIBClient Resource *Router Metric *Metrics @@ -57,7 +67,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{}) { @@ -92,7 +102,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 } @@ -255,24 +265,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()