m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.0 KiB

6 months ago
  1. from __future__ import absolute_import
  2. from kafka.protocol.api import Request, Response
  3. from kafka.protocol.types import Array, Boolean, Int16, Int32, Schema, String
  4. class MetadataResponse_v0(Response):
  5. API_KEY = 3
  6. API_VERSION = 0
  7. SCHEMA = Schema(
  8. ('brokers', Array(
  9. ('node_id', Int32),
  10. ('host', String('utf-8')),
  11. ('port', Int32))),
  12. ('topics', Array(
  13. ('error_code', Int16),
  14. ('topic', String('utf-8')),
  15. ('partitions', Array(
  16. ('error_code', Int16),
  17. ('partition', Int32),
  18. ('leader', Int32),
  19. ('replicas', Array(Int32)),
  20. ('isr', Array(Int32))))))
  21. )
  22. class MetadataResponse_v1(Response):
  23. API_KEY = 3
  24. API_VERSION = 1
  25. SCHEMA = Schema(
  26. ('brokers', Array(
  27. ('node_id', Int32),
  28. ('host', String('utf-8')),
  29. ('port', Int32),
  30. ('rack', String('utf-8')))),
  31. ('controller_id', Int32),
  32. ('topics', Array(
  33. ('error_code', Int16),
  34. ('topic', String('utf-8')),
  35. ('is_internal', Boolean),
  36. ('partitions', Array(
  37. ('error_code', Int16),
  38. ('partition', Int32),
  39. ('leader', Int32),
  40. ('replicas', Array(Int32)),
  41. ('isr', Array(Int32))))))
  42. )
  43. class MetadataResponse_v2(Response):
  44. API_KEY = 3
  45. API_VERSION = 2
  46. SCHEMA = Schema(
  47. ('brokers', Array(
  48. ('node_id', Int32),
  49. ('host', String('utf-8')),
  50. ('port', Int32),
  51. ('rack', String('utf-8')))),
  52. ('cluster_id', String('utf-8')), # <-- Added cluster_id field in v2
  53. ('controller_id', Int32),
  54. ('topics', Array(
  55. ('error_code', Int16),
  56. ('topic', String('utf-8')),
  57. ('is_internal', Boolean),
  58. ('partitions', Array(
  59. ('error_code', Int16),
  60. ('partition', Int32),
  61. ('leader', Int32),
  62. ('replicas', Array(Int32)),
  63. ('isr', Array(Int32))))))
  64. )
  65. class MetadataResponse_v3(Response):
  66. API_KEY = 3
  67. API_VERSION = 3
  68. SCHEMA = Schema(
  69. ('throttle_time_ms', Int32),
  70. ('brokers', Array(
  71. ('node_id', Int32),
  72. ('host', String('utf-8')),
  73. ('port', Int32),
  74. ('rack', String('utf-8')))),
  75. ('cluster_id', String('utf-8')),
  76. ('controller_id', Int32),
  77. ('topics', Array(
  78. ('error_code', Int16),
  79. ('topic', String('utf-8')),
  80. ('is_internal', Boolean),
  81. ('partitions', Array(
  82. ('error_code', Int16),
  83. ('partition', Int32),
  84. ('leader', Int32),
  85. ('replicas', Array(Int32)),
  86. ('isr', Array(Int32))))))
  87. )
  88. class MetadataResponse_v4(Response):
  89. API_KEY = 3
  90. API_VERSION = 4
  91. SCHEMA = MetadataResponse_v3.SCHEMA
  92. class MetadataResponse_v5(Response):
  93. API_KEY = 3
  94. API_VERSION = 5
  95. SCHEMA = Schema(
  96. ('throttle_time_ms', Int32),
  97. ('brokers', Array(
  98. ('node_id', Int32),
  99. ('host', String('utf-8')),
  100. ('port', Int32),
  101. ('rack', String('utf-8')))),
  102. ('cluster_id', String('utf-8')),
  103. ('controller_id', Int32),
  104. ('topics', Array(
  105. ('error_code', Int16),
  106. ('topic', String('utf-8')),
  107. ('is_internal', Boolean),
  108. ('partitions', Array(
  109. ('error_code', Int16),
  110. ('partition', Int32),
  111. ('leader', Int32),
  112. ('replicas', Array(Int32)),
  113. ('isr', Array(Int32)),
  114. ('offline_replicas', Array(Int32))))))
  115. )
  116. class MetadataRequest_v0(Request):
  117. API_KEY = 3
  118. API_VERSION = 0
  119. RESPONSE_TYPE = MetadataResponse_v0
  120. SCHEMA = Schema(
  121. ('topics', Array(String('utf-8')))
  122. )
  123. ALL_TOPICS = None # Empty Array (len 0) for topics returns all topics
  124. class MetadataRequest_v1(Request):
  125. API_KEY = 3
  126. API_VERSION = 1
  127. RESPONSE_TYPE = MetadataResponse_v1
  128. SCHEMA = MetadataRequest_v0.SCHEMA
  129. ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
  130. NO_TOPICS = None # Empty array (len 0) for topics returns no topics
  131. class MetadataRequest_v2(Request):
  132. API_KEY = 3
  133. API_VERSION = 2
  134. RESPONSE_TYPE = MetadataResponse_v2
  135. SCHEMA = MetadataRequest_v1.SCHEMA
  136. ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
  137. NO_TOPICS = None # Empty array (len 0) for topics returns no topics
  138. class MetadataRequest_v3(Request):
  139. API_KEY = 3
  140. API_VERSION = 3
  141. RESPONSE_TYPE = MetadataResponse_v3
  142. SCHEMA = MetadataRequest_v1.SCHEMA
  143. ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
  144. NO_TOPICS = None # Empty array (len 0) for topics returns no topics
  145. class MetadataRequest_v4(Request):
  146. API_KEY = 3
  147. API_VERSION = 4
  148. RESPONSE_TYPE = MetadataResponse_v4
  149. SCHEMA = Schema(
  150. ('topics', Array(String('utf-8'))),
  151. ('allow_auto_topic_creation', Boolean)
  152. )
  153. ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
  154. NO_TOPICS = None # Empty array (len 0) for topics returns no topics
  155. class MetadataRequest_v5(Request):
  156. """
  157. The v5 metadata request is the same as v4.
  158. An additional field for offline_replicas has been added to the v5 metadata response
  159. """
  160. API_KEY = 3
  161. API_VERSION = 5
  162. RESPONSE_TYPE = MetadataResponse_v5
  163. SCHEMA = MetadataRequest_v4.SCHEMA
  164. ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
  165. NO_TOPICS = None # Empty array (len 0) for topics returns no topics
  166. MetadataRequest = [
  167. MetadataRequest_v0, MetadataRequest_v1, MetadataRequest_v2,
  168. MetadataRequest_v3, MetadataRequest_v4, MetadataRequest_v5
  169. ]
  170. MetadataResponse = [
  171. MetadataResponse_v0, MetadataResponse_v1, MetadataResponse_v2,
  172. MetadataResponse_v3, MetadataResponse_v4, MetadataResponse_v5
  173. ]