Sha256: e7a52c1acb239095e09cc765788d0ce14a209c01edf16a9be18fd845bad06b09

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    module Ui
      module Models
        # Represents a single broker data within the cluster
        class Broker < Lib::HashProxy
          class << self
            # @return [Array<Broker>] all brokers in the cluster
            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

            # Finds requested broker
            #
            # @param broker_id [String, Integer] id of the broker
            # @return [Broker]
            # @raise [::Karafka::Web::Errors::Ui::NotFoundError]
            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
          end

          # @return [Integer]
          def id
            broker_id
          end

          # @return [String]
          def name
            broker_name
          end

          # @return [Integer]
          def port
            broker_port
          end

          # @return [String] full broker name for presentation
          def full_name
            "#{id} - #{name}:#{port}"
          end

          # @return [Array<Karafka::Admin::Configs::Config>] all broker configs
          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
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
karafka-web-0.10.4 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.3 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.2 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.1 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.0 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.0.rc2 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.0.rc1 lib/karafka/web/ui/models/broker.rb
karafka-web-0.10.0.beta1 lib/karafka/web/ui/models/broker.rb
karafka-web-0.9.1 lib/karafka/web/ui/models/broker.rb
karafka-web-0.9.0 lib/karafka/web/ui/models/broker.rb
karafka-web-0.9.0.rc3 lib/karafka/web/ui/models/broker.rb
karafka-web-0.9.0.rc2 lib/karafka/web/ui/models/broker.rb
karafka-web-0.9.0.rc1 lib/karafka/web/ui/models/broker.rb