def delete_topic(self, admin_id, topic_name): """delete topic for background delete services.""" try: s3MessageBus = S3CortxMsgBus() s3MessageBus.connect() if S3CortxMsgBus.is_topic_exist(admin_id, topic_name): S3CortxMsgBus.delete_topic(admin_id, [topic_name]) except Exception as e: raise e
def create_topic(self, admin_id: str, topic_name: str, partitions: int): """create topic for background delete services.""" try: s3MessageBus = S3CortxMsgBus() s3MessageBus.connect() if not S3CortxMsgBus.is_topic_exist(admin_id, topic_name): S3CortxMsgBus.create_topic(admin_id, [topic_name], partitions) except Exception as e: raise e
def delete_topic(self, admin_id, topic_name): """delete topic for background delete services.""" try: if S3CortxMsgBus.is_topic_exist(admin_id, topic_name): S3CortxMsgBus.delete_topic(admin_id, [topic_name]) else: self.logger.info("Topic does not exist") except Exception as e: raise e
def create_topic(self, admin_id: str, topic_name: str, partitions: int): """create topic for background delete services.""" try: if not S3CortxMsgBus.is_topic_exist(admin_id, topic_name): S3CortxMsgBus.create_topic(admin_id, [topic_name], partitions) self.logger.info("Topic Created") else: self.logger.info("Topic Already exists") except Exception as e: raise e
def __init__(self, config, logger): """Initialize MessageBus.""" self._config = config self._logger = logger self.__msgbuslib = S3CortxMsgBus() self.__isproducersetupcomplete = False self.__isconsumersetupcomplete = False self._daemon_mode = config.get_daemon_mode() self._sleep_time = config.get_msgbus_consumer_sleep_time()
def __loadmsgbuslibrary(self): """Load message bus library.""" #Basically loads msgbus lib and reads its config file self._logger.debug("Instantiating S3MessageBus") self.__msgbuslib = S3CortxMsgBus() self._logger.debug("Connecting to S3MessageBus") ret,msg = self.__msgbuslib.connect() if not ret: self._logger.error("msgbus connect failed {}".format(msg)) self.__msgbuslib = None return ret
def purge_messages(self, producer_id: str, msg_type: str, delivery_mechanism: str, sleep_time: int): """purge messages on message bus.""" try: s3MessageBus = S3CortxMsgBus() s3MessageBus.connect() s3MessageBus.setup_producer(producer_id, msg_type, delivery_mechanism) try: s3MessageBus.purge() #Insert a delay of 1 min after purge, so that the messages are deleted time.sleep(sleep_time) except: sys.stdout.write('Exception during purge. May be there are no messages to purge\n') except Exception as e: raise e