Class: Mamiya::Master::ApplicationStatus
- Inherits:
-
Object
- Object
- Mamiya::Master::ApplicationStatus
- Defined in:
- lib/mamiya/master/application_status.rb
Overview
This class determines application cluster’s status (what’s majority package active, etc).
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Instance Method Summary collapse
- #common_previous_release ⇒ Object
- #common_releases ⇒ Object
- #currents ⇒ Object
-
#initialize(agent_monitor, application, labels: nil) ⇒ ApplicationStatus
constructor
A new instance of ApplicationStatus.
- #major_current ⇒ Object
- #non_participants ⇒ Object
- #participants ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(agent_monitor, application, labels: nil) ⇒ ApplicationStatus
Returns a new instance of ApplicationStatus.
8 9 10 11 12 |
# 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 |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
14 15 16 |
# File 'lib/mamiya/master/application_status.rb', line 14 def agents @agents end |
#application ⇒ Object (readonly)
Returns the value of attribute application.
14 15 16 |
# File 'lib/mamiya/master/application_status.rb', line 14 def application @application end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
14 15 16 |
# File 'lib/mamiya/master/application_status.rb', line 14 def labels @labels end |
Instance Method Details
#common_previous_release ⇒ Object
69 70 71 72 73 74 |
# 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 ⇒ Object
60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
50 51 52 53 54 |
# 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 ⇒ Object
56 57 58 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/mamiya/master/application_status.rb', line 46 def non_participants agents.keys - participants.keys end |
#participants ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |