Sha256: 735dca1b12a425b3a2047f1b42fadfc958e4b84fa48b1eb256cc7941e91761d4

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module ProxES
  class NodesStatusCheck < StatusCheck
    def node_type
      raise 'Unimplemented'
    end

    def value
      children.count
    end

    def check_node(node)
      node['roles']&.include?(node_type) ||
        node['attributes'] && node.dig('attributes', node_type) != 'false' ||
        node.dig('settings', 'node') && node.dig('settings', 'node', node_type) != 'false'
    end

    def children
      @children ||= source_result['nodes']['nodes'].map do |_id, node|
        [node['name'], 1] if check_node(node)
      end.compact.to_h
    end

    def check
      return true if required_value.blank?

      required_value.to_i == value
    end

    def formatted(val = nil)
      (val || value).to_i == 1 ? '1 Node' : "#{val || value} Nodes"
    end
  end

  class MasterNodesStatusCheck < NodesStatusCheck
    def node_type
      'master'
    end
  end

  class DataNodesStatusCheck < NodesStatusCheck
    def node_type
      'data'
    end
  end

  class IngestNodesStatusCheck < NodesStatusCheck
    def node_type
      'ingest'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proxes-0.10.1 lib/proxes/models/status_checks/nodes_status_check.rb