Esempio n. 1
0
class ProduceResponse_v1(Response):
    API_KEY = 0
    API_VERSION = 1
    SCHEMA = Schema(('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('error_code', Int16),
                                  ('offset', Int64))))),
                    ('throttle_time_ms', Int32))
Esempio n. 2
0
class OffsetResponse_v2(Response):
    API_KEY = 2
    API_VERSION = 2
    SCHEMA = Schema(('throttle_time_ms', Int32),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('error_code', Int16),
                                  ('timestamp', Int64), ('offset', Int64))))))
Esempio n. 3
0
class Struct(AbstractType):
    SCHEMA = Schema()

    def __init__(self, *args, **kwargs):
        if len(args) == len(self.SCHEMA.fields):
            for i, name in enumerate(self.SCHEMA.names):
                self.__dict__[name] = args[i]
        elif len(args) > 0:
            raise ValueError('Args must be empty or mirror schema')
        else:
            for name in self.SCHEMA.names:
                self.__dict__[name] = kwargs.pop(name, None)
            if kwargs:
                raise ValueError('Keyword(s) not in schema %s: %s'
                                 % (list(self.SCHEMA.names),
                                    ', '.join(kwargs.keys())))

        # overloading encode() to support both class and instance
        # Without WeakMethod() this creates circular ref, which
        # causes instances to "leak" to garbage
        self.encode = WeakMethod(self._encode_self)

    @classmethod
    def encode(cls, item):  # pylint: disable=E0202
        bits = []
        for i, field in enumerate(cls.SCHEMA.fields):
            bits.append(field.encode(item[i]))
        return b''.join(bits)

    def _encode_self(self):
        return self.SCHEMA.encode(
            [self.__dict__[name] for name in self.SCHEMA.names]
        )

    @classmethod
    def decode(cls, data):
        if isinstance(data, bytes):
            data = BytesIO(data)
        return cls(*[field.decode(data) for field in cls.SCHEMA.fields])

    def __repr__(self):
        key_vals = []
        for name, field in zip(self.SCHEMA.names, self.SCHEMA.fields):
            key_vals.append('%s=%s' % (name, field.repr(self.__dict__[name])))
        return self.__class__.__name__ + '(' + ', '.join(key_vals) + ')'

    def __hash__(self):
        return hash(self.encode())

    def __eq__(self, other):
        if self.SCHEMA != other.SCHEMA:
            return False
        for attr in self.SCHEMA.names:
            if self.__dict__[attr] != other.__dict__[attr]:
                return False
        return True
Esempio n. 4
0
class ProduceRequest_v3(ProduceRequest):
    API_VERSION = 3
    RESPONSE_TYPE = ProduceResponse_v3
    SCHEMA = Schema(
        ('transactional_id', String('utf-8')), ('required_acks', Int16),
        ('timeout', Int32),
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions', Array(('partition', Int32),
                                    ('messages', Bytes))))))
Esempio n. 5
0
class OffsetCommitRequest_v0(Request):
    API_KEY = 8
    API_VERSION = 0  # Zookeeper-backed storage
    RESPONSE_TYPE = OffsetCommitResponse_v0
    SCHEMA = Schema(('consumer_group', String('utf-8')),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('metadata', String('utf-8')))))))
Esempio n. 6
0
class MetadataRequest_v4(Request):
    API_KEY = 3
    API_VERSION = 4
    RESPONSE_TYPE = MetadataResponse_v4
    SCHEMA = Schema(
        ('topics', Array(String('utf-8'))),
        ('allow_auto_topic_creation', Boolean)
    )
    ALL_TOPICS = -1  # Null Array (len -1) for topics returns all topics
    NO_TOPICS = None  # Empty array (len 0) for topics returns no topics
Esempio n. 7
0
class FetchResponse_v1(Response):
    API_KEY = 1
    API_VERSION = 1
    SCHEMA = Schema(('throttle_time_ms', Int32),
                    ('topics',
                     Array(('topics', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('error_code', Int16),
                                  ('highwater_offset', Int64),
                                  ('message_set', Bytes))))))
Esempio n. 8
0
class OffsetRequest_v1(Request):
    API_KEY = 2
    API_VERSION = 1
    RESPONSE_TYPE = OffsetResponse_v1
    SCHEMA = Schema(
        ('replica_id', Int32),
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions', Array(('partition', Int32),
                                    ('timestamp', Int64))))))
    DEFAULTS = {'replica_id': -1}
Esempio n. 9
0
class JoinGroupRequest_v0(Request):
    API_KEY = 11
    API_VERSION = 0
    RESPONSE_TYPE = JoinGroupResponse_v0
    SCHEMA = Schema(('group', String('utf-8')), ('session_timeout', Int32),
                    ('member_id', String('utf-8')),
                    ('protocol_type', String('utf-8')),
                    ('group_protocols',
                     Array(('protocol_name', String('utf-8')),
                           ('protocol_metadata', Bytes))))
    UNKNOWN_MEMBER_ID = ''
Esempio n. 10
0
class FetchRequest_v0(Request):
    API_KEY = 1
    API_VERSION = 0
    RESPONSE_TYPE = FetchResponse_v0
    SCHEMA = Schema(('replica_id', Int32), ('max_wait_time', Int32),
                    ('min_bytes', Int32),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('max_bytes', Int32))))))
Esempio n. 11
0
class OffsetFetchResponse_v3(Response):
    API_KEY = 9
    API_VERSION = 3
    SCHEMA = Schema(('throttle_time_ms', Int32),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('metadata', String('utf-8')),
                                  ('error_code', Int16))))),
                    ('error_code', Int16))
Esempio n. 12
0
class OffsetFetchResponse_v2(Response):
    # Added in KIP-88
    API_KEY = 9
    API_VERSION = 2
    SCHEMA = Schema(
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions',
                Array(('partition', Int32), ('offset', Int64),
                      ('metadata', String('utf-8')), ('error_code', Int16))))),
        ('error_code', Int16))
Esempio n. 13
0
class OffsetRequest_v2(Request):
    API_KEY = 2
    API_VERSION = 2
    RESPONSE_TYPE = OffsetResponse_v2
    SCHEMA = Schema(
        ('replica_id', Int32),
        ('isolation_level', Int8),  # <- added isolation_level
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions', Array(('partition', Int32),
                                    ('timestamp', Int64))))))
    DEFAULTS = {'replica_id': -1}
Esempio n. 14
0
class ConsumerProtocolMemberAssignment(Struct):
    SCHEMA = Schema(('version', Int16), ('assignment',
                                         Array(('topic', String('utf-8')),
                                               ('partitions', Array(Int32)))),
                    ('user_data', Bytes))

    def partitions(self):
        return [
            TopicPartition(topic, partition) for topic, partitions in
            self.assignment  # pylint: disable-msg=no-member
            for partition in partitions
        ]
Esempio n. 15
0
class FetchRequest_v4(Request):
    # Adds isolation_level field
    API_KEY = 1
    API_VERSION = 4
    RESPONSE_TYPE = FetchResponse_v4
    SCHEMA = Schema(('replica_id', Int32), ('max_wait_time', Int32),
                    ('min_bytes', Int32), ('max_bytes', Int32),
                    ('isolation_level', Int8),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('max_bytes', Int32))))))
Esempio n. 16
0
class FetchRequest_v5(Request):
    # This may only be used in broker-broker api calls
    API_KEY = 1
    API_VERSION = 5
    RESPONSE_TYPE = FetchResponse_v5
    SCHEMA = Schema(
        ('replica_id', Int32), ('max_wait_time', Int32), ('min_bytes', Int32),
        ('max_bytes', Int32), ('isolation_level', Int8),
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions',
                Array(('partition', Int32), ('fetch_offset', Int64),
                      ('log_start_offset', Int64), ('max_bytes', Int32))))))
Esempio n. 17
0
class OffsetCommitRequest_v1(Request):
    API_KEY = 8
    API_VERSION = 1  # Kafka-backed storage
    RESPONSE_TYPE = OffsetCommitResponse_v1
    SCHEMA = Schema(('consumer_group', String('utf-8')),
                    ('consumer_group_generation_id', Int32),
                    ('consumer_id', String('utf-8')),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('timestamp', Int64),
                                  ('metadata', String('utf-8')))))))
Esempio n. 18
0
class FetchRequest_v3(Request):
    API_KEY = 1
    API_VERSION = 3
    RESPONSE_TYPE = FetchResponse_v3
    SCHEMA = Schema(
        ('replica_id', Int32),
        ('max_wait_time', Int32),
        ('min_bytes', Int32),
        ('max_bytes', Int32),  # This new field is only difference from FR_v2
        ('topics',
         Array(('topic', String('utf-8')),
               ('partitions',
                Array(('partition', Int32), ('offset', Int64),
                      ('max_bytes', Int32))))))
Esempio n. 19
0
class DescribeGroupsResponse_v0(Response):
    API_KEY = 15
    API_VERSION = 0
    SCHEMA = Schema(
        ('groups',
         Array(('error_code', Int16), ('group', String('utf-8')),
               ('state', String('utf-8')), ('protocol_type', String('utf-8')),
               ('protocol', String('utf-8')),
               ('members',
                Array(('member_id', String('utf-8')),
                      ('client_id', String('utf-8')),
                      ('client_host', String('utf-8')),
                      ('member_metadata', Bytes),
                      ('member_assignment', Bytes))))))
Esempio n. 20
0
class FetchResponse_v4(Response):
    API_KEY = 1
    API_VERSION = 4
    SCHEMA = Schema(
        ('throttle_time_ms', Int32),
        ('topics',
         Array(
             ('topics', String('utf-8')),
             ('partitions',
              Array(('partition', Int32), ('error_code', Int16),
                    ('highwater_offset', Int64), ('last_stable_offset', Int64),
                    ('aborted_transactions',
                     Array(('producer_id', Int64), ('first_offset', Int64))),
                    ('message_set', Bytes))))))
Esempio n. 21
0
class CreateTopicsRequest_v1(Request):
    API_KEY = 19
    API_VERSION = 1
    RESPONSE_TYPE = CreateTopicsResponse_v1
    SCHEMA = Schema(
        ('create_topic_requests',
         Array(('topic', String('utf-8')), ('num_partitions', Int32),
               ('replication_factor', Int16),
               ('replica_assignment',
                Array(('partition_id', Int32), ('replicas', Array(Int32)))),
               ('configs',
                Array(('config_key', String('utf-8')),
                      ('config_value', String('utf-8')))))),
        ('timeout', Int32), ('validate_only', Boolean))
Esempio n. 22
0
class OffsetCommitRequest_v2(Request):
    API_KEY = 8
    API_VERSION = 2  # added retention_time, dropped timestamp
    RESPONSE_TYPE = OffsetCommitResponse_v2
    SCHEMA = Schema(('consumer_group', String('utf-8')),
                    ('consumer_group_generation_id', Int32),
                    ('consumer_id', String('utf-8')),
                    ('retention_time', Int64),
                    ('topics',
                     Array(('topic', String('utf-8')),
                           ('partitions',
                            Array(('partition', Int32), ('offset', Int64),
                                  ('metadata', String('utf-8')))))))
    DEFAULT_GENERATION_ID = -1
    DEFAULT_RETENTION_TIME = -1
Esempio n. 23
0
class MetadataResponse_v0(Response):
    API_KEY = 3
    API_VERSION = 0
    SCHEMA = Schema(
        ('brokers', Array(
            ('node_id', Int32),
            ('host', String('utf-8')),
            ('port', Int32))),
        ('topics', Array(
            ('error_code', Int16),
            ('topic', String('utf-8')),
            ('partitions', Array(
                ('error_code', Int16),
                ('partition', Int32),
                ('leader', Int32),
                ('replicas', Array(Int32)),
                ('isr', Array(Int32))))))
    )
Esempio n. 24
0
class MetadataResponse_v1(Response):
    API_KEY = 3
    API_VERSION = 1
    SCHEMA = Schema(
        ('brokers', Array(
            ('node_id', Int32),
            ('host', String('utf-8')),
            ('port', Int32),
            ('rack', String('utf-8')))),
        ('controller_id', Int32),
        ('topics', Array(
            ('error_code', Int16),
            ('topic', String('utf-8')),
            ('is_internal', Boolean),
            ('partitions', Array(
                ('error_code', Int16),
                ('partition', Int32),
                ('leader', Int32),
                ('replicas', Array(Int32)),
                ('isr', Array(Int32))))))
    )
Esempio n. 25
0
class SaslAuthenticateResponse_v0(Request):
    API_KEY = 36
    API_VERSION = 0
    SCHEMA = Schema(('error_code', Int16), ('error_message', String('utf-8')),
                    ('sasl_auth_bytes', Bytes))
Esempio n. 26
0
class SaslHandShakeResponse_v0(Response):
    API_KEY = 17
    API_VERSION = 0
    SCHEMA = Schema(('error_code', Int16),
                    ('enabled_mechanisms', Array(String('utf-8'))))
Esempio n. 27
0
class SaslHandShakeRequest_v0(Request):
    API_KEY = 17
    API_VERSION = 0
    RESPONSE_TYPE = SaslHandShakeResponse_v0
    SCHEMA = Schema(('mechanism', String('utf-8')))
Esempio n. 28
0
class ApiVersionRequest_v0(Request):
    API_KEY = 18
    API_VERSION = 0
    RESPONSE_TYPE = ApiVersionResponse_v0
    SCHEMA = Schema()
Esempio n. 29
0
class SaslAuthenticateRequest_v0(Request):
    API_KEY = 36
    API_VERSION = 0
    RESPONSE_TYPE = SaslAuthenticateResponse_v0
    SCHEMA = Schema(('sasl_auth_bytes', Bytes))
Esempio n. 30
0
class CreateTopicsResponse_v1(Response):
    API_KEY = 19
    API_VERSION = 1
    SCHEMA = Schema(('topic_error_codes',
                     Array(('topic', String('utf-8')), ('error_code', Int16),
                           ('error_message', String('utf-8')))))