Class: Rdkafka::Admin

Inherits:
Object
  • Object
show all
Includes:
Helpers::OAuth
Defined in:
lib/rdkafka/admin.rb,
lib/rdkafka/admin/create_acl_handle.rb,
lib/rdkafka/admin/create_acl_report.rb,
lib/rdkafka/admin/delete_acl_handle.rb,
lib/rdkafka/admin/delete_acl_report.rb,
lib/rdkafka/admin/acl_binding_result.rb,
lib/rdkafka/admin/create_topic_handle.rb,
lib/rdkafka/admin/create_topic_report.rb,
lib/rdkafka/admin/delete_topic_handle.rb,
lib/rdkafka/admin/delete_topic_report.rb,
lib/rdkafka/admin/describe_acl_handle.rb,
lib/rdkafka/admin/describe_acl_report.rb,
lib/rdkafka/admin/delete_groups_handle.rb,
lib/rdkafka/admin/delete_groups_report.rb,
lib/rdkafka/admin/config_binding_result.rb,
lib/rdkafka/admin/describe_configs_handle.rb,
lib/rdkafka/admin/describe_configs_report.rb,
lib/rdkafka/admin/create_partitions_handle.rb,
lib/rdkafka/admin/create_partitions_report.rb,
lib/rdkafka/admin/config_resource_binding_result.rb,
lib/rdkafka/admin/incremental_alter_configs_handle.rb,
lib/rdkafka/admin/incremental_alter_configs_report.rb

Defined Under Namespace

Classes: AclBindingResult, ConfigBindingResult, ConfigResourceBindingResult, CreateAclHandle, CreateAclReport, CreatePartitionsHandle, CreatePartitionsReport, CreateTopicHandle, CreateTopicReport, DeleteAclHandle, DeleteAclReport, DeleteGroupsHandle, DeleteGroupsReport, DeleteTopicHandle, DeleteTopicReport, DescribeAclHandle, DescribeAclReport, DescribeConfigsHandle, DescribeConfigsReport, IncrementalAlterConfigsHandle, IncrementalAlterConfigsReport

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::OAuth

#oauthbearer_set_token, #oauthbearer_set_token_failure

Class Method Details

.describe_errorsHash<Integer, Hash>

Allows us to retrieve librdkafka errors with descriptions Useful for debugging and building UIs, etc.

Returns:

  • (Hash<Integer, Hash>)

    hash with errors mapped by code



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rdkafka/admin.rb', line 12

def describe_errors
  # Memory pointers for the array of structures and count
  p_error_descs = FFI::MemoryPointer.new(:pointer)
  p_count = FFI::MemoryPointer.new(:size_t)

  # Call the attached function
  Bindings.rd_kafka_get_err_descs(p_error_descs, p_count)

  # Retrieve the number of items in the array
  count = p_count.read_uint

  # Get the pointer to the array of error descriptions
  array_of_errors = FFI::Pointer.new(Bindings::NativeErrorDesc, p_error_descs.read_pointer)

  errors = {}

  count.times do |i|
    # Get the pointer to each struct
    error_ptr = array_of_errors[i]

    # Create a new instance of NativeErrorDesc for each item
    error_desc = Bindings::NativeErrorDesc.new(error_ptr)

    # Read values from the struct
    code = error_desc[:code]

    name = ''
    desc = ''

    name = error_desc[:name].read_string unless error_desc[:name].null?
    desc = error_desc[:desc].read_string unless error_desc[:desc].null?

    errors[code] = { code: code, name: name, description: desc }
  end

  errors
end

Instance Method Details

#closeObject

Close this admin instance



90
91
92
93
94
# File 'lib/rdkafka/admin.rb', line 90

def close
  return if closed?
  ObjectSpace.undefine_finalizer(self)
  @native_kafka.close
end

#closed?Boolean

Whether this admin has closed

Returns:

  • (Boolean)


97
98
99
# File 'lib/rdkafka/admin.rb', line 97

def closed?
  @native_kafka.closed?
end

#create_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:) ⇒ CreateAclHandle

Create acl

Parameters:

Returns:

  • (CreateAclHandle)

    Create acl handle that can be used to wait for the result of creating the acl

Raises:



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/rdkafka/admin.rb', line 392

def create_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
  closed_admin_check(__method__)

  # Create a rd_kafka_AclBinding_t representing the new acl
  error_buffer = FFI::MemoryPointer.from_string(" " * 256)
  new_acl_ptr = Rdkafka::Bindings.rd_kafka_AclBinding_new(
    resource_type,
    FFI::MemoryPointer.from_string(resource_name),
    resource_pattern_type,
    FFI::MemoryPointer.from_string(principal),
    FFI::MemoryPointer.from_string(host),
    operation,
    permission_type,
    error_buffer,
    256
  )
  if new_acl_ptr.null?
    raise Rdkafka::Config::ConfigError.new(error_buffer.read_string)
  end

  # Note that rd_kafka_CreateAcls can create more than one acl at a time
  pointer_array = [new_acl_ptr]
  acls_array_ptr = FFI::MemoryPointer.new(:pointer)
  acls_array_ptr.write_array_of_pointer(pointer_array)

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end

  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(new_acl_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle that we will return to the caller
  create_acl_handle = CreateAclHandle.new
  create_acl_handle[:pending] = true
  create_acl_handle[:response] = -1
  CreateAclHandle.register(create_acl_handle)

  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATEACLS)
  end

  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, create_acl_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_CreateAcls(
        inner,
        acls_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    CreateAclHandle.remove(create_acl_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(new_acl_ptr)
  end

  create_acl_handle
end

#create_partitions(topic_name, partition_count) ⇒ CreateTopicHandle

Creates extra partitions for a given topic

Parameters:

  • topic_name (String)
  • partition_count (Integer)

    how many partitions we want to end up with for given topic

Returns:

  • (CreateTopicHandle)

    Create topic handle that can be used to wait for the result of creating the topic

Raises:

  • (ConfigError)

    When the partition count or replication factor are out of valid range

  • (RdkafkaError)

    When the topic name is invalid or the topic already exists

  • (RdkafkaError)

    When the topic configuration is invalid



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/rdkafka/admin.rb', line 301

def create_partitions(topic_name, partition_count)
  closed_admin_check(__method__)

  @native_kafka.with_inner do |inner|
    error_buffer = FFI::MemoryPointer.from_string(" " * 256)
    new_partitions_ptr = Rdkafka::Bindings.rd_kafka_NewPartitions_new(
      FFI::MemoryPointer.from_string(topic_name),
      partition_count,
      error_buffer,
      256
    )
    if new_partitions_ptr.null?
      raise Rdkafka::Config::ConfigError.new(error_buffer.read_string)
    end

    pointer_array = [new_partitions_ptr]
    topics_array_ptr = FFI::MemoryPointer.new(:pointer)
    topics_array_ptr.write_array_of_pointer(pointer_array)

    # Get a pointer to the queue that our request will be enqueued on
    queue_ptr = Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
    if queue_ptr.null?
      Rdkafka::Bindings.rd_kafka_NewPartitions_destroy(new_partitions_ptr)
      raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
    end

    # Create and register the handle we will return to the caller
    create_partitions_handle = CreatePartitionsHandle.new
    create_partitions_handle[:pending] = true
    create_partitions_handle[:response] = -1
    CreatePartitionsHandle.register(create_partitions_handle)
    admin_options_ptr = Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATEPARTITIONS)
    Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, create_partitions_handle.to_ptr)

    begin
      Rdkafka::Bindings.rd_kafka_CreatePartitions(
        inner,
        topics_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    rescue Exception
      CreatePartitionsHandle.remove(create_partitions_handle.to_ptr.address)
      raise
    ensure
      Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
      Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
      Rdkafka::Bindings.rd_kafka_NewPartitions_destroy(new_partitions_ptr)
    end

    create_partitions_handle
  end
end

#create_topic(topic_name, partition_count, replication_factor, topic_config = {}) ⇒ CreateTopicHandle

Create a topic with the given partition count and replication factor

Returns:

  • (CreateTopicHandle)

    Create topic handle that can be used to wait for the result of creating the topic

Raises:

  • (ConfigError)

    When the partition count or replication factor are out of valid range

  • (RdkafkaError)

    When the topic name is invalid or the topic already exists

  • (RdkafkaError)

    When the topic configuration is invalid



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rdkafka/admin.rb', line 109

def create_topic(topic_name, partition_count, replication_factor, topic_config={})
  closed_admin_check(__method__)

  # Create a rd_kafka_NewTopic_t representing the new topic
  error_buffer = FFI::MemoryPointer.from_string(" " * 256)
  new_topic_ptr = Rdkafka::Bindings.rd_kafka_NewTopic_new(
    FFI::MemoryPointer.from_string(topic_name),
    partition_count,
    replication_factor,
    error_buffer,
    256
  )
  if new_topic_ptr.null?
    raise Rdkafka::Config::ConfigError.new(error_buffer.read_string)
  end

  unless topic_config.nil?
    topic_config.each do |key, value|
      Rdkafka::Bindings.rd_kafka_NewTopic_set_config(
        new_topic_ptr,
        key.to_s,
        value.to_s
      )
    end
  end

  # Note that rd_kafka_CreateTopics can create more than one topic at a time
  pointer_array = [new_topic_ptr]
  topics_array_ptr = FFI::MemoryPointer.new(:pointer)
  topics_array_ptr.write_array_of_pointer(pointer_array)

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end
  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_NewTopic_destroy(new_topic_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle we will return to the caller
  create_topic_handle = CreateTopicHandle.new
  create_topic_handle[:pending] = true
  create_topic_handle[:response] = -1
  CreateTopicHandle.register(create_topic_handle)
  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATETOPICS)
  end
  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, create_topic_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_CreateTopics(
        inner,
        topics_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    CreateTopicHandle.remove(create_topic_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_NewTopic_destroy(new_topic_ptr)
  end

  create_topic_handle
end

#delete_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:) ⇒ DeleteAclHandle

Delete acl

Parameters:

Returns:

  • (DeleteAclHandle)

    Delete acl handle that can be used to wait for the result of deleting the acl

Raises:



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/rdkafka/admin.rb', line 497

def delete_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
  closed_admin_check(__method__)

  # Create a rd_kafka_AclBinding_t representing the acl to be deleted
  error_buffer = FFI::MemoryPointer.from_string(" " * 256)

  delete_acl_ptr = Rdkafka::Bindings.rd_kafka_AclBindingFilter_new(
    resource_type,
    resource_name ? FFI::MemoryPointer.from_string(resource_name) : nil,
    resource_pattern_type,
    principal ? FFI::MemoryPointer.from_string(principal) : nil,
    host ? FFI::MemoryPointer.from_string(host) : nil,
    operation,
    permission_type,
    error_buffer,
    256
  )

  if delete_acl_ptr.null?
    raise Rdkafka::Config::ConfigError.new(error_buffer.read_string)
  end

  # Note that rd_kafka_DeleteAcls can delete more than one acl at a time
  pointer_array = [delete_acl_ptr]
  acls_array_ptr = FFI::MemoryPointer.new(:pointer)
  acls_array_ptr.write_array_of_pointer(pointer_array)

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end

  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(new_acl_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle that we will return to the caller
  delete_acl_handle = DeleteAclHandle.new
  delete_acl_handle[:pending] = true
  delete_acl_handle[:response] = -1
  DeleteAclHandle.register(delete_acl_handle)

  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETEACLS)
  end

  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, delete_acl_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_DeleteAcls(
        inner,
        acls_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    DeleteAclHandle.remove(delete_acl_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(delete_acl_ptr)
  end

  delete_acl_handle
end

#delete_group(group_id) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/rdkafka/admin.rb', line 181

def delete_group(group_id)
  closed_admin_check(__method__)

  # Create a rd_kafka_DeleteGroup_t representing the new topic
  delete_groups_ptr = Rdkafka::Bindings.rd_kafka_DeleteGroup_new(
    FFI::MemoryPointer.from_string(group_id)
  )

  pointer_array = [delete_groups_ptr]
  groups_array_ptr = FFI::MemoryPointer.new(:pointer)
  groups_array_ptr.write_array_of_pointer(pointer_array)

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end
  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_DeleteTopic_destroy(delete_topic_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle we will return to the caller
  delete_groups_handle = DeleteGroupsHandle.new
  delete_groups_handle[:pending] = true
  delete_groups_handle[:response] = -1
  DeleteGroupsHandle.register(delete_groups_handle)
  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETETOPICS)
  end
  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, delete_groups_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_DeleteGroups(
        inner,
        groups_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    DeleteGroupsHandle.remove(delete_groups_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_DeleteGroup_destroy(delete_groups_ptr)
  end

  delete_groups_handle
end

#delete_topic(topic_name) ⇒ DeleteTopicHandle

Deletes the named topic

Returns:

  • (DeleteTopicHandle)

    Delete topic handle that can be used to wait for the result of deleting the topic

Raises:

  • (RdkafkaError)

    When the topic name is invalid or the topic does not exist



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/rdkafka/admin.rb', line 239

def delete_topic(topic_name)
  closed_admin_check(__method__)

  # Create a rd_kafka_DeleteTopic_t representing the topic to be deleted
  delete_topic_ptr = Rdkafka::Bindings.rd_kafka_DeleteTopic_new(FFI::MemoryPointer.from_string(topic_name))

  # Note that rd_kafka_DeleteTopics can create more than one topic at a time
  pointer_array = [delete_topic_ptr]
  topics_array_ptr = FFI::MemoryPointer.new(:pointer)
  topics_array_ptr.write_array_of_pointer(pointer_array)

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end
  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_DeleteTopic_destroy(delete_topic_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle we will return to the caller
  delete_topic_handle = DeleteTopicHandle.new
  delete_topic_handle[:pending] = true
  delete_topic_handle[:response] = -1
  DeleteTopicHandle.register(delete_topic_handle)
  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETETOPICS)
  end
  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, delete_topic_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_DeleteTopics(
        inner,
        topics_array_ptr,
        1,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    DeleteTopicHandle.remove(delete_topic_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_DeleteTopic_destroy(delete_topic_ptr)
  end

  delete_topic_handle
end

#describe_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:) ⇒ DescribeAclHandle

Describe acls

Parameters:

Returns:

  • (DescribeAclHandle)

    Describe acl handle that can be used to wait for the result of fetching acls

Raises:



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# File 'lib/rdkafka/admin.rb', line 604

def describe_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
  closed_admin_check(__method__)

  # Create a rd_kafka_AclBinding_t with the filters to fetch existing acls
  error_buffer = FFI::MemoryPointer.from_string(" " * 256)
  describe_acl_ptr = Rdkafka::Bindings.rd_kafka_AclBindingFilter_new(
    resource_type,
    resource_name ? FFI::MemoryPointer.from_string(resource_name) : nil,
    resource_pattern_type,
    principal ? FFI::MemoryPointer.from_string(principal) : nil,
    host ? FFI::MemoryPointer.from_string(host) : nil,
    operation,
    permission_type,
    error_buffer,
    256
  )
  if describe_acl_ptr.null?
    raise Rdkafka::Config::ConfigError.new(error_buffer.read_string)
  end

  # Get a pointer to the queue that our request will be enqueued on
  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end

  if queue_ptr.null?
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(new_acl_ptr)
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  # Create and register the handle that we will return to the caller
  describe_acl_handle = DescribeAclHandle.new
  describe_acl_handle[:pending] = true
  describe_acl_handle[:response] = -1
  DescribeAclHandle.register(describe_acl_handle)

  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DESCRIBEACLS)
  end

  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, describe_acl_handle.to_ptr)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_DescribeAcls(
        inner,
        describe_acl_ptr,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    DescribeAclHandle.remove(describe_acl_handle.to_ptr.address)
    raise
  ensure
    Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
    Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
    Rdkafka::Bindings.rd_kafka_AclBinding_destroy(describe_acl_ptr)
  end

  describe_acl_handle
end

#describe_configs(resources) ⇒ DescribeConfigsHandle

Note:

Several resources can be requested at one go, but only one broker at a time

Describe configs

Parameters:

  • resources (Array<Hash>)

    Array where elements are hashes with two keys: - :resource_type - numerical resource type based on Kafka API - :resource_name - string with resource name

Returns:

  • (DescribeConfigsHandle)

    Describe config handle that can be used to wait for the result of fetching resources with their appropriate configs

Raises:



679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
# File 'lib/rdkafka/admin.rb', line 679

def describe_configs(resources)
  closed_admin_check(__method__)

  handle = DescribeConfigsHandle.new
  handle[:pending] = true
  handle[:response] = -1

  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end

  if queue_ptr.null?
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(
      inner,
      Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DESCRIBECONFIGS
    )
  end

  DescribeConfigsHandle.register(handle)
  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, handle.to_ptr)

  pointer_array = resources.map do |resource_details|
    Rdkafka::Bindings.rd_kafka_ConfigResource_new(
      resource_details.fetch(:resource_type),
      FFI::MemoryPointer.from_string(
        resource_details.fetch(:resource_name)
      )
    )
  end

  configs_array_ptr = FFI::MemoryPointer.new(:pointer, pointer_array.size)
  configs_array_ptr.write_array_of_pointer(pointer_array)

  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_DescribeConfigs(
        inner,
        configs_array_ptr,
        pointer_array.size,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    DescribeConfigsHandle.remove(handle.to_ptr.address)

    raise
  ensure
    Rdkafka::Bindings.rd_kafka_ConfigResource_destroy_array(
      configs_array_ptr,
      pointer_array.size
    ) if configs_array_ptr
  end

  handle
end

#finalizerObject



72
73
74
# File 'lib/rdkafka/admin.rb', line 72

def finalizer
  ->(_) { close }
end

#incremental_alter_configs(resources_with_configs) ⇒ IncrementalAlterConfigsHandle

Note:

Several resources can be requested at one go, but only one broker at a time

Note:

The results won’t contain altered values but only the altered resources

Alters in an incremental way all the configs provided for given resources

name, value and the proper op_type to perform on this value.

Parameters:

  • resources_with_configs (Array<Hash>)

    resources with the configs key that contains

Returns:

  • (IncrementalAlterConfigsHandle)

    Incremental alter configs handle that can be used to wait for the result of altering resources with their appropriate configs

Raises:



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/rdkafka/admin.rb', line 752

def incremental_alter_configs(resources_with_configs)
  closed_admin_check(__method__)

  handle = IncrementalAlterConfigsHandle.new
  handle[:pending] = true
  handle[:response] = -1

  queue_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
  end

  if queue_ptr.null?
    raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
  end

  admin_options_ptr = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_AdminOptions_new(
      inner,
      Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_INCREMENTALALTERCONFIGS
    )
  end

  IncrementalAlterConfigsHandle.register(handle)
  Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, handle.to_ptr)

  # Tu poprawnie tworzyc
  pointer_array = resources_with_configs.map do |resource_details|
    # First build the appropriate resource representation
    resource_ptr = Rdkafka::Bindings.rd_kafka_ConfigResource_new(
      resource_details.fetch(:resource_type),
      FFI::MemoryPointer.from_string(
        resource_details.fetch(:resource_name)
      )
    )

    resource_details.fetch(:configs).each do |config|
      Bindings.rd_kafka_ConfigResource_add_incremental_config(
        resource_ptr,
        config.fetch(:name),
        config.fetch(:op_type),
        config.fetch(:value)
      )
    end

    resource_ptr
  end

  configs_array_ptr = FFI::MemoryPointer.new(:pointer, pointer_array.size)
  configs_array_ptr.write_array_of_pointer(pointer_array)


  begin
    @native_kafka.with_inner do |inner|
      Rdkafka::Bindings.rd_kafka_IncrementalAlterConfigs(
        inner,
        configs_array_ptr,
        pointer_array.size,
        admin_options_ptr,
        queue_ptr
      )
    end
  rescue Exception
    IncrementalAlterConfigsHandle.remove(handle.to_ptr.address)

    raise
  ensure
    Rdkafka::Bindings.rd_kafka_ConfigResource_destroy_array(
      configs_array_ptr,
      pointer_array.size
    ) if configs_array_ptr
  end

  handle
end

#metadata(topic_name = nil, timeout_ms = 2_000) ⇒ Metadata

Performs the metadata request using admin

Parameters:

  • topic_name (String, nil) (defaults to: nil)

    metadat about particular topic or all if nil

  • timeout_ms (Integer) (defaults to: 2_000)

    metadata request timeout

Returns:



81
82
83
84
85
86
87
# File 'lib/rdkafka/admin.rb', line 81

def (topic_name = nil, timeout_ms = 2_000)
  closed_admin_check(__method__)

  @native_kafka.with_inner do |inner|
    Metadata.new(inner, topic_name, timeout_ms)
  end
end

#nameString

Returns admin name.

Returns:

  • (String)

    admin name



66
67
68
69
70
# File 'lib/rdkafka/admin.rb', line 66

def name
  @name ||= @native_kafka.with_inner do |inner|
    ::Rdkafka::Bindings.rd_kafka_name(inner)
  end
end

#startObject

Note:

Not needed to run unless explicit start was disabled

Starts the native Kafka polling thread and kicks off the init polling



61
62
63
# File 'lib/rdkafka/admin.rb', line 61

def start
  @native_kafka.start
end