Add the command that registers to the SMO; Make the create registration and create...
[pti/o2.git] / o2app / entrypoints / redis_eventconsumer.py
index ea49edd..d4c7c65 100644 (file)
@@ -22,7 +22,7 @@ from o2dms.domain import commands
 from o2ims.domain import commands as imscmd
 
 from o2common.helper import o2logging
-from o2ims.domain.subscription_obj import Message2SMO
+from o2ims.domain.subscription_obj import Message2SMO, NotificationEventEnum, RegistrationMessage
 logger = o2logging.get_logger(__name__)
 
 r = redis.Redis(**config.get_redis_host_and_port())
@@ -36,6 +36,8 @@ def main():
     pubsub = r.pubsub(ignore_subscribe_messages=True)
     pubsub.subscribe("NfDeploymentStateChanged")
     pubsub.subscribe('ResourceChanged')
+    pubsub.subscribe('RegistrationChanged')
+    pubsub.subscribe('OcloudChanged')
 
     for m in pubsub.listen():
         try:
@@ -58,7 +60,7 @@ def handle_dms_changed(m, bus):
             ToState=data['ToState']
         )
         bus.handle(cmd)
-    if channel == 'ResourceChanged':
+    elif channel == 'ResourceChanged':
         datastr = m['data']
         data = json.loads(datastr)
         logger.info('ResourceChanged with cmd:{}'.format(data))
@@ -69,6 +71,19 @@ def handle_dms_changed(m, bus):
             eventtype=data['notificationEventType'],
             updatetime=data['updatetime']))
         bus.handle(cmd)
+    elif channel == 'RegistrationChanged':
+        datastr = m['data']
+        data = json.loads(datastr)
+        logger.info('RegistrationChanged with cmd:{}'.format(data))
+        cmd = imscmd.Register2SMO(data=RegistrationMessage(id=data['id']))
+        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)
     else:
         logger.info("unhandled:{}".format(channel))