Class: Karafka::Web::Ui::Models::Broker

Inherits:
Lib::HashProxy show all
Defined in:
lib/karafka/web/ui/models/broker.rb

Overview

Represents a single broker data within the cluster

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lib::HashProxy

#initialize, #method_missing, #respond_to_missing?, #to_h

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Lib::HashProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Karafka::Web::Ui::Lib::HashProxy

Class Method Details

.allArray<Broker>

Returns all brokers in the cluster.

Returns:

  • (Array<Broker>)

    all brokers in the cluster



11
12
13
14
15
16
# File 'lib/karafka/web/ui/models/broker.rb', line 11

def all
  # We do not cache here because we want the most recent state of brokers possible
  ClusterInfo.fetch(cached: false).brokers.map do |broker|
    new(broker)
  end
end

.find(broker_id) ⇒ Broker

Finds requested broker

Parameters:

  • broker_id (String, Integer)

    id of the broker

Returns:

Raises:



23
24
25
26
27
28
29
# File 'lib/karafka/web/ui/models/broker.rb', line 23

def find(broker_id)
  found = all.find { |broker| broker.id.to_s == broker_id }

  return found if found

  raise(::Karafka::Web::Errors::Ui::NotFoundError, broker_id)
end

Instance Method Details

#configsArray<Karafka::Admin::Configs::Config>

Returns all broker configs.

Returns:

  • (Array<Karafka::Admin::Configs::Config>)

    all broker configs



53
54
55
56
57
58
59
60
61
# File 'lib/karafka/web/ui/models/broker.rb', line 53

def configs
  # We copy the array because the result one is frozen and we sort
  @configs ||= ::Karafka::Admin::Configs.describe(
    ::Karafka::Admin::Configs::Resource.new(
      type: :broker,
      name: id
    )
  ).first.configs.dup
end

#full_nameString

Returns full broker name for presentation.

Returns:

  • (String)

    full broker name for presentation



48
49
50
# File 'lib/karafka/web/ui/models/broker.rb', line 48

def full_name
  "#{id} - #{name}:#{port}"
end

#idInteger

Returns:

  • (Integer)


33
34
35
# File 'lib/karafka/web/ui/models/broker.rb', line 33

def id
  broker_id
end

#nameString

Returns:

  • (String)


38
39
40
# File 'lib/karafka/web/ui/models/broker.rb', line 38

def name
  broker_name
end

#portInteger

Returns:

  • (Integer)


43
44
45
# File 'lib/karafka/web/ui/models/broker.rb', line 43

def port
  broker_port
end