X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2app%2Fentrypoints%2Fredis_eventconsumer.py;h=98e198b9d88ea970e90b25f336418132bd8ad728;hb=748a90298e8abff7f1ff2fdec6a36c2775fe7161;hp=56301747563ae87b21ffa9b65cd436df911f5d34;hpb=6c304dfab28ffd1bbe69b9ada3d11e8fbbde014b;p=pti%2Fo2.git diff --git a/o2app/entrypoints/redis_eventconsumer.py b/o2app/entrypoints/redis_eventconsumer.py index 5630174..98e198b 100644 --- a/o2app/entrypoints/redis_eventconsumer.py +++ b/o2app/entrypoints/redis_eventconsumer.py @@ -13,22 +13,23 @@ # limitations under the License. # import json + import redis import json from o2app import bootstrap from o2common.config import config -# from o2common.domain import commands from o2dms.domain import commands from o2ims.domain import commands as imscmd +from o2ims.domain.subscription_obj import Message2SMO, RegistrationMessage +from o2ims.domain.alarm_obj import AlarmEvent2SMO from o2common.helper import o2logging -from o2ims.domain.subscription_obj import Message2SMO, NotificationEventEnum,\ - RegistrationMessage logger = o2logging.get_logger(__name__) r = redis.Redis(**config.get_redis_host_and_port()) apibase = config.get_o2ims_api_base() +api_monitoring_base = config.get_o2ims_monitoring_api_base() def main(): @@ -37,18 +38,18 @@ def main(): pubsub = r.pubsub(ignore_subscribe_messages=True) pubsub.subscribe("NfDeploymentStateChanged") pubsub.subscribe('ResourceChanged') - pubsub.subscribe('ConfigurationChanged') pubsub.subscribe('OcloudChanged') + pubsub.subscribe('AlarmEventChanged') for m in pubsub.listen(): try: - handle_dms_changed(m, bus) + handle_changed(m, bus) except Exception as ex: logger.warning("{}".format(str(ex))) continue -def handle_dms_changed(m, bus): +def handle_changed(m, bus): logger.info("handling %s", m) channel = m['channel'].decode("UTF-8") if channel == "NfDeploymentStateChanged": @@ -72,19 +73,24 @@ def handle_dms_changed(m, bus): eventtype=data['notificationEventType'], updatetime=data['updatetime'])) bus.handle(cmd) - elif channel == 'ConfigurationChanged': + elif channel == 'OcloudChanged': datastr = m['data'] data = json.loads(datastr) - logger.info('ConfigurationChanged with cmd:{}'.format(data)) - cmd = imscmd.Register2SMO(data=RegistrationMessage(id=data['id'])) + logger.info('OcloudChanged with cmd:{}'.format(data)) + cmd = imscmd.Register2SMO(data=RegistrationMessage( + data['notificationEventType'], + id=data['id'])) bus.handle(cmd) - elif channel == 'OcloudChanged': + elif channel == 'AlarmEventChanged': datastr = m['data'] data = json.loads(datastr) - logger.info('OcloudChanged with cmd:{}'.format(data)) - if data['notificationEventType'] == NotificationEventEnum.CREATE: - cmd = imscmd.Register2SMO(data=RegistrationMessage(is_all=True)) - bus.handle(cmd) + logger.info('AlarmEventChanged with cmd:{}'.format(data)) + ref = api_monitoring_base + '/alarms/' + data['id'] + cmd = imscmd.PubAlarm2SMO(data=AlarmEvent2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime'])) + bus.handle(cmd) else: logger.info("unhandled:{}".format(channel))