Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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)]
Exemplo n.º 4
0
def broker_host_and_port(state: State) -> str:
    brokers = Broker.get_all(state.cluster)
    return "{}:{}".format(brokers[0].host, brokers[0].port)
Exemplo n.º 5
0
def broker_host(state: State) -> str:
    brokers = Broker.get_all(state.cluster)
    return brokers[0].host
Exemplo n.º 6
0
def broker_id(state: State) -> str:
    brokers = Broker.get_all(state.cluster)
    return str(brokers[0].broker_id)