Пример #1
0
def _parse_partition(topic, partition_id, replica_str):
    if topic['num_partitions'] != -1:
        raise ArgumentError("Cannot specify num_partitions and replication_factor when using an explicit partition and replica list")
    try:
        topic['replica_assignment'].append({'partition_id': partition_id, 'replicas': [int(bid) for bid in replica_str.split("|")]})
    except ValueError:
        raise ArgumentError("replica_id must be an integer")
Пример #2
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 3:
            raise ArgumentError(
                "At least one topic definition must be provided")
        if not cmd_args[0] in ('true', 'false'):
            raise ArgumentError("The first argument may only be true or false")
        if not cmd_args[1].isdigit():
            raise ArgumentError("The second argument must be an integer")

        values = {
            'validate_only': cmd_args[0] == 'true',
            'topics': [],
            'timeout': int(cmd_args[1])
        }
        for topic_def in cmd_args[2:]:
            tparts = topic_def.split(",")
            topic = {
                'topic': tparts[0],
                'num_partitions': -1,
                'replication_factor': -1,
                'replica_assignment': [],
                'configs': []
            }

            _parse_remaining_args(topic, tparts[1:])
            values['topics'].append(topic)

        return values
Пример #3
0
def _parse_partition(item):
    parts = item.split(",")
    if len(parts) != 2:
        raise ArgumentError("partitions must be specified as topic,partitions")

    try:
        return {'topic': parts[0], 'partition': int(parts[1])}
    except ValueError:
        raise ArgumentError("The partition must be an integer")
Пример #4
0
def _parse_topic_set(topic_set):
    tparts = topic_set.split(',')
    if len(tparts) < 2:
        raise ArgumentError("Each topic must have at least one partition")

    try:
        return {'topic': tparts[0], 'partitions': [{'partition': int(p)} for p in tparts[1:]]}
    except ValueError:
        raise ArgumentError("partitions must be integers")
Пример #5
0
def _get_partition_map(partition):
    if len(partition) != 2:
        raise ArgumentError("Partition tuple must have exactly 2 fields")

    try:
        pmap = {'partition': int(partition[0]), 'timestamp': int(partition[1])}
    except ValueError:
        raise ArgumentError("Partition tuple must be exactly 2 integers")

    return pmap
 def process_arguments(cls, cmd_args):
     if len(cmd_args) != 2:
         raise ArgumentError(
             "FindCoordinator takes exactly two string arguments")
     if cmd_args[0] not in ('group', 'transaction'):
         raise ArgumentError(
             "The first argument can only be 'group' or 'transaction'")
     return {
         'coordinator_type': 0 if cmd_args[0] == 'group' else 1,
         'coordinator_key': cmd_args[1]
     }
Пример #7
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) != 3:
            raise ArgumentError("HeartbeatV0 takes exactly three arguments")

        try:
            return {
                'group_id': cmd_args[0],
                'group_generation_id': int(cmd_args[1]),
                'member_id': cmd_args[2]
            }
        except ValueError:
            raise ArgumentError("the group_generation_id must be an integer")
Пример #8
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 3:
            raise ArgumentError("ListOffsetV0 requires at least 3 arguments")

        try:
            values = {'replica_id': int(cmd_args.pop(0)), 'topics': []}
        except ValueError:
            raise ArgumentError("The replica_id must be an integer")

        while len(cmd_args) > 0:
            topic, cmd_args = _parse_next_topic(cmd_args)
            values['topics'].append(topic)

        return values
Пример #9
0
def _get_partition_map(partition):
    if (len(partition) < 2) or (len(partition) > 3):
        raise ArgumentError("Partition tuple must have 3 or 4 fields")

    try:
        pmap = {'partition': int(partition[0]),
                'offset': int(partition[1]),
                'metadata': None}
    except ValueError:
        raise ArgumentError("Partition tuple must be exactly 2 integers and an optional string")

    if len(partition) == 3:
        pmap['metadata'] = partition[2]
    return pmap
Пример #10
0
def _parse_group_protocol(protocol):
    pparts = protocol.split(',')
    if len(pparts) != 2:
        raise ArgumentError(
            "Expected group_protocol_name,group_protocol_metadata")
    if pparts[1] == '':
        return {'protocol_name': pparts[0], 'protocol_metadata': None}
    else:
        try:
            return {
                'protocol_name': pparts[0],
                'protocol_metadata': binascii.unhexlify(pparts[1])
            }
        except:
            raise ArgumentError(
                "group_protocol_metadata must be empty or a hex string")
Пример #11
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) != 4:
            raise ArgumentError("SyncGroupV0 requires exactly 4 arguments")

        try:
            member_assignments = binascii.unhexlify(cmd_args[3])
        except (binascii.Error, TypeError):
            raise ArgumentError("member_assignments must be a hex string")

        try:
            return {'group_id': cmd_args[0],
                    'generation_id': int(cmd_args[1]),
                    'member_id': cmd_args[2],
                    'member_assignments': member_assignments}
        except ValueError:
            raise ArgumentError("The generation_id must be an integer")
Пример #12
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 6:
            raise ArgumentError("OffsetCommitV2 requires at least 6 arguments")
        try:
            values = {'group_id': cmd_args.pop(0),
                      'group_generation_id': int(cmd_args.pop(0)),
                      'member_id': cmd_args.pop(0),
                      'retention_time': int(cmd_args.pop(0)),
                      'topics': []}
        except ValueError:
            raise ArgumentError("group_generation_id and retention_time must be integers")

        while len(cmd_args) > 0:
            topic, cmd_args = _parse_next_topic(cmd_args)
            values['topics'].append(topic)

        return values
    def process_arguments(cls, cmd_args):
        if (len(cmd_args) != 1) or (not isinstance(cmd_args[0],
                                                   six.integer_types)):
            raise ArgumentError(
                "ControlledShutdown requires exactly one argument that is a number"
            )

        return {'broker_id': cmd_args[0]}
Пример #14
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 2:
            raise ArgumentError("OffsetFetchV0 requires at least 2 arguments")
        values = {'group_id': cmd_args[0], 'topics': []}

        for topic_set in cmd_args[1:]:
            values['topics'].append(_parse_topic_set(topic_set))

        return values
Пример #15
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 5:
            raise ArgumentError("JoinGroupV0 requires at least 5 arguments")

        try:
            values = {
                'group_id': cmd_args[0],
                'session_timeout': int(cmd_args[1]),
                'member_id': cmd_args[2],
                'protocol_type': cmd_args[3],
                'group_protocols': []
            }
        except ValueError:
            raise ArgumentError("The session_timeout must be an integer")

        for protocol in cmd_args[4:]:
            values['group_protocols'].append(_parse_group_protocol(protocol))

        return values
Пример #16
0
def _parse_remaining_args(topic, targs):
    if targs[0].isdigit() and targs[1].isdigit():
        topic['num_partitions'] = int(targs[0])
        topic['replication_factor'] = int(targs[1])
        _parse_kv_args(topic, targs[2:])
    else:
        _parse_kv_args(topic, targs)

    if (topic['num_partitions'] == -1) and (len(topic['replica_assignment']) == 0):
        raise ArgumentError("You must specify either num_partitions and replication_factor OR an explicit replica_assignment")
Пример #17
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 3:
            raise ArgumentError("OffsetCommitV0 requires at least 3 arguments")
        values = {'group_id': cmd_args.pop(0), 'topics': []}

        while len(cmd_args) > 0:
            topic, cmd_args = _parse_next_topic(cmd_args)
            values['topics'].append(topic)

        return values
Пример #18
0
def _parse_next_topic(cmd_args):
    topic = {'topic': cmd_args.pop(0), 'partitions': []}
    while True:
        try:
            cmd_args[0].index(',')
        except (IndexError, ValueError):
            if len(topic['partitions']) == 0:
                raise ArgumentError("Topic is missing partitions")
            return topic, cmd_args
        partition = cmd_args.pop(0).split(',')
        topic['partitions'].append(_get_partition_map(partition))
Пример #19
0
def _process_arguments(cmd_name, cmd_args):
    if len(cmd_args) < 4:
        raise ArgumentError(
            "{0} requires at least 4 arguments".format(cmd_name))

    try:
        values = {
            'controller_id': int(cmd_args[0]),
            'controller_epoch': int(cmd_args[1]),
            'partition_states': [],
            'live_leaders': []
        }
    except ValueError:
        raise ArgumentError(
            "The controller_id and controller_epoch must be integers")

    for csv in cmd_args[2:]:
        _parse_argument(values, csv)

    return values
Пример #20
0
def _parse_kv_args(topic, topic_args):
    for targ in topic_args:
        arg_parts = targ.split("=")
        if len(arg_parts) != 2:
            raise ArgumentError("was expecting a 'key=value'")

        try:
            partition_id = int(arg_parts[0])
            _parse_partition(topic, partition_id, arg_parts[1])
        except ValueError:
            topic['configs'].append({'config_key': arg_parts[0], 'config_value': arg_parts[1]})
Пример #21
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 4:
            raise ArgumentError("StopReplicaV0 requires at least 4 arguments")

        try:
            values = {
                'controller_id':
                int(cmd_args[0]),
                'controller_epoch':
                int(cmd_args[1]),
                'delete_partitions':
                cmd_args[2].lower() in ['true', '1', 't', 'y', 'yes'],
                'partitions': []
            }
        except ValueError:
            raise ArgumentError(
                "The controller_id and controller_epoch must be integers")

        for item in cmd_args[3:]:
            values['partitions'].append(_parse_partition(item))

        return values
Пример #22
0
def _parse_argument(values, arg):
    cparts = arg.split(",")
    if len(cparts) == 8:
        try:
            values['partition_states'].append({
                'topic':
                cparts[0],
                'partition':
                int(cparts[1]),
                'controller_epoch':
                int(cparts[2]),
                'leader':
                int(cparts[3]),
                'leader_epoch':
                int(cparts[4]),
                'isr':
                _get_integer_list(cparts[5]),
                'zk_version':
                int(cparts[6]),
                'replicas':
                _get_integer_list(cparts[7])
            })
        except ValueError:
            raise ArgumentError(
                "partition_states fields, except for topic, must be integers")
    elif len(cparts) == 3:
        try:
            values['live_leaders'].append({
                'id': int(cparts[0]),
                'host': cparts[1],
                'port': int(cparts[2])
            })
        except ValueError:
            raise ArgumentError(
                "live_leaders broker_id and port fields must be integers")
    else:
        raise ArgumentError(
            "partition_states or live_leaders format incorrect. check help.")
Пример #23
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) == 1:
            return {'group_id': cmd_args[0], 'topics': None}
        elif len(cmd_args) == 0:
            raise ArgumentError(
                "OffsetFetchV{0} requires at least 1 argument".format(
                    cls.api_version))
        else:
            values = {'group_id': cmd_args[0], 'topics': []}

            for topic_set in cmd_args[1:]:
                values['topics'].append(_parse_topic_set(topic_set))

            return values
Пример #24
0
    def process_arguments(cls, cmd_args):
        if len(cmd_args) < 4:
            raise ArgumentError("ListOffsetV2 requires at least 4 arguments")
        if cmd_args[1] not in ('true', 'false'):
            raise ArgumentError("committed must be 'true' or 'false'")

        try:
            replica_id = int(cmd_args.pop(0))
        except ValueError:
            raise ArgumentError("The replica_id must be an integer")
        committed = cmd_args.pop(0)

        values = {
            'replica_id': replica_id,
            'isolation_level': 1 if committed == 'true' else 0,
            'topics': []
        }

        while len(cmd_args) > 0:
            topic, cmd_args = _parse_next_topic(cmd_args)
            values['topics'].append(topic)

        return values
Пример #25
0
    def process_arguments(cls, cmd_args):
        if (len(cmd_args) < 2) or (not cmd_args[0].isdigit()):
            raise ArgumentError("The first argument must be an integer, and at least one topic definition must be provided")

        values = {'topics': [], 'timeout': int(cmd_args[0])}
        for topic_def in cmd_args[1:]:
            tparts = topic_def.split(",")
            topic = {'topic': tparts[0],
                     'num_partitions': -1,
                     'replication_factor': -1,
                     'replica_assignment': [],
                     'configs': []}

            _parse_remaining_args(topic, tparts[1:])
            values['topics'].append(topic)

        return values
Пример #26
0
    def process_arguments(cls, cmd_args):
        if (len(cmd_args) < 2) or (not cmd_args[0].isdigit()):
            raise ArgumentError("The first argument must be an integer, and at least one topic must be provided")

        return {'topics': cmd_args[1:], 'timeout': int(cmd_args[0])}
Пример #27
0
 def process_arguments(cls, cmd_args):
     if len(cmd_args) != 1:
         raise ArgumentError(
             "GroupCoordinator takes exactly one string argument")
     return {'group_id': cmd_args[0]}
Пример #28
0
 def process_arguments(cls, cmd_args):
     if len(cmd_args) != 0:
         raise ArgumentError("ListGroupsV0 takes no arguments")
     return {}
Пример #29
0
 def process_arguments(cls, cmd_args):
     if len(cmd_args) != 1:
         raise ArgumentError(
             "SaslHandshakeV0 requires exactly one argument")
     return {'mechanism': cmd_args[0]}
Пример #30
0
 def process_arguments(cls, cmd_args):
     if len(cmd_args) != 0:
         raise ArgumentError("ApiVersion takes no arguments")
     return {}