X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ricxappframe%2Fxapp_frame.py;h=95aa122997333e94618cd075170d37ce7ef6e253;hb=fbb5928134d64dbab8bc3e64b23c2f21e4c4be6f;hp=e977e27cb5a7ef8e40cb9294d9b4483db616a1b7;hpb=0f8305b167601ce6ca87c55208038455a65eab62;p=ric-plt%2Fxapp-frame-py.git diff --git a/ricxappframe/xapp_frame.py b/ricxappframe/xapp_frame.py index e977e27..95aa122 100644 --- a/ricxappframe/xapp_frame.py +++ b/ricxappframe/xapp_frame.py @@ -21,9 +21,13 @@ Framework here means Xapp classes that can be subclassed from threading import Thread from ricxappframe import xapp_rmr from ricxappframe.xapp_sdl import SDLWrapper -from rmr import rmr +from ricxappframe.rmr import rmr from mdclogpy import Logger +# constants +RIC_HEALTH_CHECK_REQ = 100 +RIC_HEALTH_CHECK_RESP = 101 + # Private base class; not for direct client use @@ -135,6 +139,7 @@ class _BaseXapp: if sbuf.contents.state == 0: return True + self.logger.info("RTS Failed! Summary: {}".format(rmr.message_summary(sbuf))) return False def rmr_free(self, sbuf): @@ -282,6 +287,17 @@ class RMRXapp(_BaseXapp): # used for thread control self._keep_going = True + # register a default healthcheck handler + # this default checks that rmr is working and SDL is working + # the user can override this and register their own handler if they wish since the "last registered callback wins". + def handle_healthcheck(self, summary, sbuf): + ok = self.healthcheck() + payload = b"OK\n" if ok else b"ERROR [RMR or SDL is unhealthy]\n" + self.rmr_rts(sbuf, new_payload=payload, new_mtype=RIC_HEALTH_CHECK_RESP) + self.rmr_free(sbuf) + + self.register_callback(handle_healthcheck, RIC_HEALTH_CHECK_REQ) + def register_callback(self, handler, message_type): """ registers this xapp to call handler(summary, buf) when an rmr message is received of type message_type