class Mamiya::Master::ApplicationStatus
This class determines application cluster's status (what's majority package active, etc).
Attributes
agents[R]
application[R]
labels[R]
Public Class Methods
new(agent_monitor, application, labels: nil)
click to toggle source
# File lib/mamiya/master/application_status.rb, line 8 def initialize(agent_monitor, application, labels: nil) @application = application @labels = labels @agents = agent_monitor.statuses(labels: labels).reject { |_, s| s['master'] } end
Public Instance Methods
common_previous_release()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 69 def common_previous_release idx = common_releases.index(major_current) return if !idx || idx < 1 common_releases[idx-1] end
common_releases()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 60 def common_releases #@common_releases ||= participants.map { |_| _[].select { |package, as| as.size > 2 }.map(&:first).compact.sort @common_releases ||= participants. map { |name, agent| agent['releases'] && agent['releases'][application] }. compact. inject(:&). sort end
currents()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 50 def currents @currents ||= Hash[participants.group_by do |name, status| status['currents'] && status['currents'][application] end.map { |package, as| [package, as.map(&:first).sort] }] end
major_current()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 56 def major_current @major_current ||= currents.max_by { |package, as| as.size }[0] end
non_participants()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 46 def non_participants agents.keys - participants.keys end
participants()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 32 def participants @participants ||= Hash[agents.select do |name, status| (status['currents'] && status['currents'][application]) || \ (status['releases'] && status['releases'][application]) || \ (status['prereleases'] && status['prereleases'][application]) || \ (status['packages'] && status['packages'][application]) || \ (status['queues'] && status['queues'].any? { |_, q| (q['working'] && q['working']['app'] == application) || \ (q['queue'] && q['queue'].any? { |t| t['app'] == application }) }) end] end
to_hash()
click to toggle source
# File lib/mamiya/master/application_status.rb, line 16 def to_hash { application: application, labels: labels, participants_count: participants.size, agents_count: agents.size, non_participants: non_participants, major_current: major_current, currents: currents, common_releases: common_releases, common_previous_release: common_previous_release, } end