Class: Karafka::Admin::Configs::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/admin/configs/resource.rb

Overview

Represents a single resource in the context of configuration management

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, name:) ⇒ Resource

Parameters:

  • type (Symbol, Integer)

    type of resource as a symbol for mapping or integer

  • name (String)

    name of the resource. It’s the broker id or topic name



31
32
33
34
35
36
37
38
# File 'lib/karafka/admin/configs/resource.rb', line 31

def initialize(type:, name:)
  @type = map_type(type)
  @name = name.to_s
  @configs = []
  @operations = Hash.new { |h, k| h[k] = [] }

  freeze
end

Instance Attribute Details

#configsObject (readonly)

Returns the value of attribute configs.



26
27
28
# File 'lib/karafka/admin/configs/resource.rb', line 26

def configs
  @configs
end

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/karafka/admin/configs/resource.rb', line 26

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



26
27
28
# File 'lib/karafka/admin/configs/resource.rb', line 26

def type
  @type
end

Instance Method Details

#to_native_hashHash

Note:

Configs include the operation type and are expected to be used only for the incremental alter API.

Returns resource converted to a hash that rdkafka can work with.

Returns:

  • (Hash)

    resource converted to a hash that rdkafka can work with



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/karafka/admin/configs/resource.rb', line 55

def to_native_hash
  configs_with_operations = []

  @operations.each do |op_type, configs|
    configs.each do |config|
      configs_with_operations << config.to_native_hash.merge(op_type: op_type)
    end
  end

  {
    resource_type: RESOURCE_TYPES_MAP.fetch(type),
    resource_name: name,
    configs: configs_with_operations
  }.freeze
end