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=cc34099bfebb2c3ffd476577d2b1db533ccab158;hpb=b2bda65ba534ae72433f914f70384666e369ea0a;p=pti%2Fo2.git diff --git a/o2app/entrypoints/redis_eventconsumer.py b/o2app/entrypoints/redis_eventconsumer.py index cc34099..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. @@ -16,14 +16,16 @@ import redis import json + from o2app import bootstrap +from o2common.adapter.notifications import SmoNotifications from o2common.config import config +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 logger = o2logging.get_logger(__name__) r = redis.Redis(**config.get_redis_host_and_port()) @@ -36,12 +38,19 @@ 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('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: @@ -64,6 +73,42 @@ def handle_changed(m, bus): ToState=data['ToState'] ) bus.handle(cmd) + 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 + inventory_api_version + '/deploymentManagers/' + \ + data['id'] + cmd = imscmd.PubMessage2SMO(data=Message2SMO( + id=data['id'], ref=ref, + eventtype=data['notificationEventType'], + updatetime=data['updatetime']), + type='Dms') + bus.handle(cmd) elif channel == 'ResourceChanged': datastr = m['data'] data = json.loads(datastr) @@ -73,15 +118,16 @@ def handle_changed(m, bus): cmd = imscmd.PubMessage2SMO(data=Message2SMO( id=data['id'], ref=ref, eventtype=data['notificationEventType'], - updatetime=data['updatetime'])) + 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)) cmd = imscmd.Register2SMO(data=RegistrationMessage( - data['notificationEventType'], - id=data['id'])) + id=data['id'], eventtype=data['notificationEventType'], + updatetime=data['updatetime'])) bus.handle(cmd) elif channel == 'AlarmEventChanged': datastr = m['data'] @@ -94,6 +140,14 @@ def handle_changed(m, bus): 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))