X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=0e85845be990680f503ea58a6423cf16d74af59f;hb=refs%2Fchanges%2F29%2F6729%2F2;hp=de355fb05165dd9f18b5df328ce6ea9491089e7b;hpb=0ce03386e6dbdb82b88406b22bb91c8cbe18e349;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index de355fb..0e85845 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -23,16 +23,25 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/spf13/viper" + "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() @@ -91,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 } } @@ -111,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] } @@ -243,12 +254,15 @@ 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")) Sdl = NewSDLClient(viper.GetString("controls.db.namespace")) Rnib = NewRNIBClient() Util = NewUtils() @@ -256,12 +270,40 @@ func init() { 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))