def describe_broker(state: State, broker: str, output_format: str): """Return configuration options for broker BROKER. BROKER can be given with broker id (integer), the host name (if hostname is unique), or socket address ('hostname:port')""" if broker.isdigit(): broker = Broker.from_id(state.cluster, broker).describe() elif ":" not in broker: broker = Broker.from_host(state.cluster, broker).describe() else: try: host, port = broker.split(":") broker = Broker.from_host_and_port(state.cluster, host, int(port)).describe() except ValueError: raise ValidationException("BROKER must either be the broker id, the hostname, or in the form 'host:port'") click.echo(format_output(broker, output_format))
def get_brokers(state: State, output_format: str): """List all brokers. Return the broker id's and socket addresses of all the brokers in the kafka cluster defined in the current context. """ brokers = Broker.get_all(state.cluster) broker_ids_and_hosts = [f"{broker.broker_id}: {broker.host}:{broker.port}" for broker in brokers] click.echo(format_output(broker_ids_and_hosts, output_format))
def list_brokers(ctx, args, incomplete): state = ctx.ensure_object(State) all_broker_hosts_names = [f"{broker.host}:{broker.port}" for broker in Broker.get_all(state.cluster)] return [broker for broker in all_broker_hosts_names if broker.startswith(incomplete)]
def broker_host_and_port(state: State) -> str: brokers = Broker.get_all(state.cluster) return "{}:{}".format(brokers[0].host, brokers[0].port)
def broker_host(state: State) -> str: brokers = Broker.get_all(state.cluster) return brokers[0].host
def broker_id(state: State) -> str: brokers = Broker.get_all(state.cluster) return str(brokers[0].broker_id)