X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp.go;h=72a8d321168c0463ea59c54e0542f35c17006c4c;hb=9c523a68520e552d051ca922815aa936c8611894;hp=12f1628db48373913f7fd27fdaf03bfa3208d7b4;hpb=8fd8b8d5fffb319b31eac745ff1d93c941bd9723;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index 12f1628..72a8d32 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -48,22 +48,24 @@ type ShutdownCB func() 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 - Util *Utils - readyCb ReadyCB - readyCbParams interface{} - shutdownCb ShutdownCB - shutdownFlag int32 - shutdownCnt int32 + Rmr *RMRClient + Sdl *SDLClient + SdlStorage *SDLStorage + Rnib *RNIBClient + Resource *Router + Metric *Metrics + Logger *Log + Config Configurator + Subscription *Subscriber + Alarm *AlarmClient + Util *Utils + readyCb ReadyCB + readyCbParams interface{} + shutdownCb ShutdownCB + shutdownFlag int32 + shutdownCnt int32 + disableAlarmClient bool + isRegistered bool ) var startTime time.Time @@ -80,13 +82,19 @@ func IsReady() bool { return Rmr != nil && Rmr.IsReady() && SdlStorage != nil && SdlStorage.IsReady() } +func IsRegistered() bool { + return isRegistered +} + func SetReadyCB(cb ReadyCB, params interface{}) { readyCb = cb readyCbParams = params } func XappReadyCb(params interface{}) { - Alarm = NewAlarmClient(viper.GetString("moId"), viper.GetString("name")) + if disableAlarmClient == false { + Alarm = NewAlarmClient(viper.GetString("moId"), viper.GetString("name")) + } if readyCb != nil { readyCb(readyCbParams) } @@ -106,6 +114,8 @@ func XappShutdownCb() { if shutdownCb != nil { shutdownCb() } + + isRegistered = false } func registerXapp() { @@ -118,6 +128,7 @@ func registerXapp() { Logger.Debug("Application='%s' is now up and ready, continue with registration ...", viper.GetString("name")) if err := doRegister(); err == nil { + isRegistered = true Logger.Info("Registration done, proceeding with startup ...") break } @@ -152,9 +163,21 @@ func getPltNamespace(envName, defVal string) string { func doPost(pltNs, url string, msg []byte, status int) error { resp, err := http.Post(fmt.Sprintf(url, pltNs, pltNs), "application/json", bytes.NewBuffer(msg)) if err != nil || resp == nil || resp.StatusCode != status { - Logger.Info("http.Post to '%s' failed with error: %v", fmt.Sprintf(url, pltNs, pltNs), err) - return err + logdesc := fmt.Sprintf("http.Post to '%s' failed with", fmt.Sprintf(url, pltNs, pltNs)) + if resp != nil { + logdesc += fmt.Sprintf(" status: %d != %d", resp.StatusCode, status) + } else { + logdesc += fmt.Sprintf(" resp: nil") + } + if err != nil { + logdesc += fmt.Sprintf(" err: %s", err.Error()) + } else { + logdesc += fmt.Sprintf(" err: nil") + } + Logger.Info(logdesc) + return fmt.Errorf(logdesc) } + Logger.Info("Post to '%s' done, status:%v", fmt.Sprintf(url, pltNs, pltNs), resp.Status) return err @@ -305,7 +328,19 @@ func GetIpAddress() (string, error) { return "", fmt.Errorf("Interface (%s) couldn't find ip", ifname) } -func RunWithParams(c MessageConsumer, sdlcheck bool) { +type RunParams struct { + SdlCheck bool + DisableAlarmClient bool +} + +func RunWithRunParams(c MessageConsumer, params RunParams) { + + if params.DisableAlarmClient { + disableAlarmClient = true + } else { + disableAlarmClient = false + } + Rmr = NewRMRClient() Rmr.SetReadyCB(XappReadyCb, nil) @@ -322,7 +357,7 @@ func RunWithParams(c MessageConsumer, sdlcheck bool) { go http.ListenAndServe(host, Resource.router) Logger.Info(fmt.Sprintf("Xapp started, listening on: %s", host)) - if sdlcheck { + if params.SdlCheck { SdlStorage.TestConnection(viper.GetString("controls.db.namespace")) } go registerXapp() @@ -330,6 +365,10 @@ func RunWithParams(c MessageConsumer, sdlcheck bool) { Rmr.Start(c) } +func RunWithParams(c MessageConsumer, sdlcheck bool) { + RunWithRunParams(c, RunParams{SdlCheck: sdlcheck, DisableAlarmClient: false}) +} + func Run(c MessageConsumer) { RunWithParams(c, true) }