def send_start_cluster_shutdown_message(self): """ Sends the "start_cluster_shutdown" message for cluster stop monitor """ producer_id = "csm_producer" self.message_type = Conf.get( const.HA_GLOBAL_INDEX, f'CLUSTER_STOP_MON{const._DELIM}message_type') self.producer = MessageBus.get_producer(producer_id=producer_id, message_type=self.message_type) self.producer.publish({"start_cluster_shutdown": 1})
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_producer(self, component: str) -> object: """ Get Producer object. Args: component (str): Component """ producer_id = const.EVENT_MGR_PRODUCER_ID.replace( "<component_id>", component) message_type_key = EVENT_MANAGER_KEYS.MESSAGE_TYPE_KEY.value.replace( "<component_id>", component) message_type_key_val = self._confstore.get(message_type_key) _, message_type = message_type_key_val.popitem() return MessageBus.get_producer(producer_id, message_type)
def _send_req(self, req): """ Send the created request to "monitor" on message bus Args: req : created actuator request """ self.req_message_type = Conf.get( const.HA_GLOBAL_INDEX, f"ACTUATOR_MANAGER{_DELIM}req_message_type") self.producer_id = Conf.get(const.HA_GLOBAL_INDEX, f"ACTUATOR_MANAGER{_DELIM}producer_id") self.producer = MessageBus.get_producer(self.producer_id, self.req_message_type) Log.debug( f"Publishing request {req} on message_type {self.req_message_type}" ) self.producer.publish(req)
def setUp(self): """ Setup. """ self.message_type = "test_ha" MessageBus.deregister(self.message_type) # Consumer self.consumer_id = 1 self.consumer_group = "test_ha_group" # Producer producer_id = "ha_producer" self.producer = MessageBus.get_producer(producer_id=producer_id, message_type=self.message_type) self.status = None self.stop_thread = False self.count = 1 self.consumer = MessageBus.get_consumer( consumer_id=self.consumer_id, consumer_group=self.consumer_group, message_type=self.message_type, callback=self._callback)
def _get_producer(self): message_type = Conf.get(const.HA_GLOBAL_INDEX, f"EVENT_MANAGER{_DELIM}message_type") producer_id = Conf.get(const.HA_GLOBAL_INDEX, f"EVENT_MANAGER{_DELIM}producer_id") return MessageBus.get_producer(producer_id, message_type)
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