X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2app%2Fentrypoints%2Fredis_eventconsumer.py;h=db39daa9fefcc26658a674ed450f33e11bb18016;hb=54ca64640ce149364fcfa91666c01edfe5c02e72;hp=56301747563ae87b21ffa9b65cd436df911f5d34;hpb=6c304dfab28ffd1bbe69b9ada3d11e8fbbde014b;p=pti%2Fo2.git diff --git a/o2app/entrypoints/redis_eventconsumer.py b/o2app/entrypoints/redis_eventconsumer.py index 5630174..db39daa 100644 --- a/o2app/entrypoints/redis_eventconsumer.py +++ b/o2app/entrypoints/redis_eventconsumer.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Wind River Systems, Inc. +# Copyright (C) 2021-2024 Wind River Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,42 +13,54 @@ # limitations under the License. # import json + import redis import json + from o2app import bootstrap +from o2common.adapter.notifications import SmoNotifications from o2common.config import config -# from o2common.domain import commands +from o2common.helper import o2logging 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() +monitor_api_version = config.get_o2ims_monitoring_api_v1() +inventory_api_version = config.get_o2ims_inventory_api_v1() def main(): logger.info("Redis pubsub starting") - bus = bootstrap.bootstrap() + + notifications = SmoNotifications() + bus = bootstrap.bootstrap(notifications=notifications) + pubsub = r.pubsub(ignore_subscribe_messages=True) pubsub.subscribe("NfDeploymentStateChanged") - pubsub.subscribe('ResourceChanged') - pubsub.subscribe('ConfigurationChanged') pubsub.subscribe('OcloudChanged') + pubsub.subscribe('ResourceTypeChanged') + pubsub.subscribe('ResourcePoolChanged') + pubsub.subscribe('DmsChanged') + pubsub.subscribe('ResourceChanged') + pubsub.subscribe('AlarmEventChanged') + pubsub.subscribe('AlarmEventPurged') 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": @@ -61,30 +73,81 @@ def handle_dms_changed(m, bus): ToState=data['ToState'] ) bus.handle(cmd) - elif channel == 'ResourceChanged': + elif channel == 'ResourceTypeChanged': + datastr = m['data'] + data = json.loads(datastr) + logger.info('ResourceTypeChanged with cmd:{}'.format(data)) + ref = apibase + inventory_api_version + '/resourceTypes/' + \ + data['id'] + cmd = imscmd.PubMessage2SMO(data=Message2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime']), + type='ResourceType') + bus.handle(cmd) + elif channel == 'ResourcePoolChanged': + datastr = m['data'] + data = json.loads(datastr) + logger.info('ResourcePoolChanged with cmd:{}'.format(data)) + ref = apibase + inventory_api_version + '/resourcePools/' + \ + data['id'] + cmd = imscmd.PubMessage2SMO(data=Message2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime']), + type='ResourcePool') + bus.handle(cmd) + elif channel == 'DmsChanged': datastr = m['data'] data = json.loads(datastr) logger.info('ResourceChanged with cmd:{}'.format(data)) - ref = apibase + '/resourcePools/' + data['resourcePoolId'] +\ - '/resources/' + data['id'] + ref = apibase + inventory_api_version + '/deploymentManagers/' + \ + data['id'] cmd = imscmd.PubMessage2SMO(data=Message2SMO( id=data['id'], ref=ref, eventtype=data['notificationEventType'], - updatetime=data['updatetime'])) + updatetime=data['updatetime']), + type='Dms') bus.handle(cmd) - elif channel == 'ConfigurationChanged': + elif channel == 'ResourceChanged': datastr = m['data'] data = json.loads(datastr) - logger.info('ConfigurationChanged with cmd:{}'.format(data)) - cmd = imscmd.Register2SMO(data=RegistrationMessage(id=data['id'])) + logger.info('ResourceChanged with cmd:{}'.format(data)) + ref = apibase + inventory_api_version + '/resourcePools/' + \ + data['resourcePoolId'] + '/resources/' + data['id'] + cmd = imscmd.PubMessage2SMO(data=Message2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime']), + type='Resource') bus.handle(cmd) elif channel == 'OcloudChanged': 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) + cmd = imscmd.Register2SMO(data=RegistrationMessage( + id=data['id'], eventtype=data['notificationEventType'], + updatetime=data['updatetime'])) + bus.handle(cmd) + elif channel == 'AlarmEventChanged': + datastr = m['data'] + data = json.loads(datastr) + logger.info('AlarmEventChanged with cmd:{}'.format(data)) + ref = api_monitoring_base + \ + monitor_api_version + '/alarms/' + data['id'] + cmd = imscmd.PubAlarm2SMO(data=AlarmEvent2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime'])) + bus.handle(cmd) + elif channel == 'AlarmEventPurged': + datastr = m['data'] + data = json.loads(datastr) + logger.info('AlarmEventPurged with cmd:{}'.format(data)) + cmd = imscmd.PurgeAlarmEvent(data=AlarmEvent2SMO( + id=data['id'], eventtype=data['notificationEventType'], + updatetime=data['updatetime'])) + bus.handle(cmd) else: logger.info("unhandled:{}".format(channel))