def __del__(self): # Delete the test topic cmd = "/opt/kafka/bin/kafka-topics.sh --delete" + \ " --topic mytest --bootstrap-server " + self._server + ":9092" try: cmd_proc = SimpleProcess(cmd) res_op, res_err, res_rc = cmd_proc.run() if res_rc != 0: raise SetupError(errno.EINVAL, "Unable to test the config") except Exception as e: raise SetupError(errno.EINVAL, \ "Unable to test the config, %s", e)
def __init__(self): from cortx.utils.message_bus import MessageBusAdmin # Create a test message_type try: admin = MessageBusAdmin(admin_id='messageadmin') admin.register_message_type(message_types=['mytest'], partitions=1) list_message_type = admin.list_message_types() if 'mytest' not in list_message_type: raise SetupError(errors.ERR_OP_FAILED, "Failed to test the config." \ "message_type 'mytest' creation failed.") except Exception as e: raise SetupError(errors.ERR_OP_FAILED, "Failed to test the config, %s", e)
def __del__(self): # Delete the test message_type from cortx.utils.message_bus import MessageBusAdmin # deregister_message_type try: admin = MessageBusAdmin(admin_id='messageadmin') admin.deregister_message_type(message_types=['mytest']) list_message_type = admin.list_message_types() if 'mytest' in list_message_type: raise SetupError(errors.ERR_OP_FAILED, "Failed to test the" \ " config. Deregister message_type: mytest failed") except Exception as e: raise SetupError(errors.ERR_OP_FAILED, \ "Failed to test the config, %s", e)
def __init__(self): from cortx.utils.conf_store import Conf Conf.load("index", "json:///etc/cortx/message_bus.conf") self._server = Conf.get("index", 'message_broker>cluster[0]>server') # Create a test topic cmd = "/opt/kafka/bin/kafka-topics.sh --create" + \ " --topic mytest --bootstrap-server " + self._server + ":9092" try: cmd_proc = SimpleProcess(cmd) res_op, res_err, res_rc = cmd_proc.run() if res_rc != 0: raise SetupError(errno.EINVAL, "Unable to test the config") except Exception as e: raise SetupError(errno.EINVAL, \ "Unable to test the config, %s", e)
def __init__(self, args: dict): if os.geteuid() != 0: raise SetupError( errno.EPERM, "Permission denied! You need to be a \ root user") self._url = args.config self._args = args.args
def receive_msg(self): """ Receives a message """ from cortx.utils.message_bus import MessageConsumer consumer = MessageConsumer(consumer_id='setup', \ consumer_group='provisioner', message_types=['mytest'], auto_ack=False, \ offset='earliest') while True: try: time.sleep(1) message = consumer.receive() if message != None: return message except Exception as e: raise SetupError(errno.EINVAL, \ "Unable to test the config. %s", e)
def receive_msg(self): """ Receives a message """ from cortx.utils.message_bus import MessageConsumer consumer = MessageConsumer(consumer_id='setup', \ consumer_group='provisioner', message_types=['mytest'], auto_ack=False, \ offset='earliest') while True: try: time.sleep(1) message = consumer.receive() if message is not None: return message except Exception as e: raise SetupError(errors.ERR_OP_FAILED, "Failed to receive messages" \ "for message_type: mytest. Unable to test the config." \ " %s with consumer_id: setup, message_types: mytest " \ "consumer_group: provisioner", e)