Sha256: 0273d41b457f4fa02dabcad21d7c2b08fffaa56055f3829dcea37c47cba488a9

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

require 'forwardable'

module BigBrother
  class ClusterCollection
    extend Forwardable
    def_delegators :@clusters, :[], :[]=, :size, :clear

    def initialize
      @clusters = {}
    end

    def config(new_clusters)
      (@clusters.keys - new_clusters.keys).each do |removed_name|
        @clusters.delete(removed_name).stop_monitoring!
      end
      new_clusters.each do |cluster_name, cluster|
        if @clusters.key?(cluster_name)
          @clusters[cluster_name] = cluster.incorporate_state(@clusters[cluster_name])
        else
          @clusters[cluster_name] = cluster
        end
      end
    end

    def running
      @clusters.values.select(&:monitored?)
    end

    def stopped
      @clusters.values.reject(&:monitored?)
    end

    def ready_for_check
      @clusters.values.select(&:needs_check?)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
big_brother-0.6.8 lib/big_brother/cluster_collection.rb
big_brother-0.6.7 lib/big_brother/cluster_collection.rb