Revert "Add the PATCH method for the monitoring API"
[pti/o2.git] / o2app / entrypoints / redis_eventconsumer.py
index cc34099..c95133a 100644 (file)
@@ -18,6 +18,7 @@ import redis
 import json
 from o2app import bootstrap
 from o2common.config import config
+from o2common.adapter.notifications import SmoNotifications
 from o2dms.domain import commands
 from o2ims.domain import commands as imscmd
 from o2ims.domain.subscription_obj import Message2SMO, RegistrationMessage
@@ -36,11 +37,17 @@ 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')
 
     for m in pubsub.listen():
@@ -64,6 +71,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 +116,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']