def setUp(self): """ Setup the prerequisit of tests """ print("Setup") ConfigManager.init("test_Cluster_stop_sigterm") self.confstore = ConfigManager.get_confstore() MessageBus.init()
def _get_producer(self): """ Get message bus producer """ message_type = Conf.get(const.HA_GLOBAL_INDEX, f"MONITOR{_DELIM}message_type") producer_id = Conf.get(const.HA_GLOBAL_INDEX, f"MONITOR{_DELIM}producer_id") MessageBus.init() Log.info( f"Getting producer {producer_id} for message type: {message_type}") return MessageBus.get_producer(producer_id, message_type)
def _get_consumer(self) -> MessageBusConsumer: """ Returns an object of MessageBusConsumer class which will listen on cluster_event message type and callback will be executed """ self._consumer_id = Conf.get(const.HA_GLOBAL_INDEX, f'FAULT_TOLERANCE{_DELIM}consumer_id') self._consumer_group = Conf.get(const.HA_GLOBAL_INDEX, f'FAULT_TOLERANCE{_DELIM}consumer_group') self._message_type = Conf.get(const.HA_GLOBAL_INDEX, f'FAULT_TOLERANCE{_DELIM}message_type') MessageBus.init() return MessageBus.get_consumer(consumer_id=self._consumer_id, \ consumer_group=self._consumer_group, \ message_type=self._message_type, \ callback=self.process_message)
def _get_consumer(self): """ Return instace of message bus consumer. """ consumer_id = Conf.get(HA_GLOBAL_INDEX, f"EVENT_MANAGER{_DELIM}consumer_id") consumer_group = Conf.get(HA_GLOBAL_INDEX, f"EVENT_MANAGER{_DELIM}consumer_group") message_type = Conf.get(HA_GLOBAL_INDEX, f"EVENT_MANAGER{_DELIM}message_type") MessageBus.init() return MessageBus.get_consumer(consumer_id=consumer_id, consumer_group=consumer_group, message_type=message_type, callback=self.process_event)
def __init__(self, default_log_enable, singleton_check: bool = False): """ Private Constructor. Make initialization work for Event Manager """ if singleton_check is False: raise Exception("Please use EventManager.get_instance() to fetch \ singleton instance of class") if EventManager.__instance is None: EventManager.__instance = self else: raise Exception( "EventManager is singleton class, use EventManager.get_instance()." ) if default_log_enable: ConfigManager.init(const.EVENT_MANAGER_LOG) self._confstore = ConfigManager.get_confstore() self._monitor_rule = MonitorRulesManager() self._default_action = HEALTH_MON_ACTIONS.PUBLISH_ACT.value MessageBus.init()
def publish(args: argparse.Namespace) -> None: """ publishes the message on the message bus. Args: args: parsed argument conf_store: ConftStoreSearch object """ try: with open(args.file, 'r') as fi: events_dict = json.load(fi) if _events_key in events_dict.keys(): ConfigManager.init(None) MessageBus.init() message_type = Conf.get( const.HA_GLOBAL_INDEX, f'FAULT_TOLERANCE{const._DELIM}message_type') message_producer = MessageBus.get_producer( "health_event_generator", message_type) cluster_id = Conf.get( const.HA_GLOBAL_INDEX, f'COMMON_CONFIG{const._DELIM}cluster_id') site_id = Conf.get(const.HA_GLOBAL_INDEX, f'COMMON_CONFIG{const._DELIM}site_id') rack_id = Conf.get(const.HA_GLOBAL_INDEX, f'COMMON_CONFIG{const._DELIM}rack_id') storageset_id = '1' # TODO: Read from config when available. for _, value in events_dict[_events_key].items(): resource_type = value[_resource_type_key] resource_type_list = Conf.get( const.HA_GLOBAL_INDEX, f"CLUSTER{const._DELIM}resource_type") if resource_type not in resource_type_list: raise Exception( f'Invalid resource_type: {resource_type}') resource_status = value[_resource_status_key] status_supported = False for status in list(HEALTH_STATUSES): if resource_status == status.value: status_supported = True break if status_supported is False: raise Exception( f'Invalid resource_status: {resource_status}') payload = { f'{HealthAttr.SOURCE}': value[_source_key], f'{HealthAttr.CLUSTER_ID}': cluster_id, f'{HealthAttr.SITE_ID}': site_id, f'{HealthAttr.RACK_ID}': rack_id, f'{HealthAttr.STORAGESET_ID}': storageset_id, f'{HealthAttr.NODE_ID}': value[_node_id_key], f'{HealthAttr.RESOURCE_TYPE}': resource_type, f'{HealthAttr.RESOURCE_ID}': value[_resource_id_key], f'{HealthAttr.RESOURCE_STATUS}': resource_status } health_event = HealthEvent(**payload) health_event.set_specific_info(value[_specific_info_key]) print(f"Publishing health event {health_event.json}") message_producer.publish(health_event.json) if _delay_key in events_dict.keys(): print( f"Sleeping for {events_dict[_delay_key]} seconds") time.sleep(events_dict[_delay_key]) except Exception as err: sys.stderr.write(f"Health event generator failed. Error: {err}\n") return errno.EINVAL