Merge "Set node to run on label docker"
[osm/MON.git] / osm_mon / core / message_bus / common_consumer.py
index b2677d8..3e1f745 100755 (executable)
@@ -22,6 +22,7 @@
 import json
 import logging
 import sys
+import time
 from json import JSONDecodeError
 
 import six
@@ -91,8 +92,22 @@ class CommonConsumer:
 
         topics = ['metric_request', 'alarm_request', 'vim_account']
         common_consumer.subscribe(topics)
-        common_consumer.poll()
-        common_consumer.seek_to_end()
+        retries = 1
+        max_retries = 5
+        while True:
+            try:
+                common_consumer.poll()
+                common_consumer.seek_to_end()
+                break
+            except Exception:
+                log.error("Error getting Kafka partitions. Maybe Kafka is not ready yet.")
+                log.error("Retry number %d of %d", retries, max_retries)
+                if retries >= max_retries:
+                    log.error("Achieved max number of retries. Logging exception and exiting...")
+                    log.exception("Exception: ")
+                    return
+                retries = retries + 1
+                time.sleep(2)
 
         log.info("Listening for messages...")
         for message in common_consumer: