Class: Mamiya::Master::PackageStatus
- Inherits:
-
Object
- Object
- Mamiya::Master::PackageStatus
- Defined in:
- lib/mamiya/master/package_status.rb
Overview
This class determines distribution and releasing status of given package using given AgentMonitor.
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.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
Instance Method Summary collapse
- #current_agents ⇒ Object
- #fetch_queued_agents ⇒ Object
- #fetched_agents ⇒ Object
- #fetching_agents ⇒ Object
-
#initialize(agent_monitor, application, package, labels: nil) ⇒ PackageStatus
constructor
A new instance of PackageStatus.
- #non_participants ⇒ Object
- #participants ⇒ Object
- #prepare_queued_agents ⇒ Object
- #prepared_agents ⇒ Object
- #preparing_agents ⇒ Object
- #reload ⇒ Object
- #status ⇒ Object
- #switch_queued_agents ⇒ Object
- #switching_agents ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(agent_monitor, application, package, labels: nil) ⇒ PackageStatus
8 9 10 11 12 13 |
# File 'lib/mamiya/master/package_status.rb', line 8 def initialize(agent_monitor, application, package, labels: nil) @application = application @package = package @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.
15 16 17 |
# File 'lib/mamiya/master/package_status.rb', line 15 def agents @agents end |
#application ⇒ Object (readonly)
Returns the value of attribute application.
15 16 17 |
# File 'lib/mamiya/master/package_status.rb', line 15 def application @application end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
15 16 17 |
# File 'lib/mamiya/master/package_status.rb', line 15 def labels @labels end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
15 16 17 |
# File 'lib/mamiya/master/package_status.rb', line 15 def package @package end |
Instance Method Details
#current_agents ⇒ Object
150 151 152 153 154 155 |
# File 'lib/mamiya/master/package_status.rb', line 150 def current_agents @current_agents ||= agents.select do |name, agent| current = agent['currents'] && agent['currents'][application] current == package end.keys end |
#fetch_queued_agents ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/mamiya/master/package_status.rb', line 88 def fetch_queued_agents @fetch_queued_agents ||= agents.select do |name, agent| queue = agent['queues'] && agent['queues']['fetch'] && agent['queues']['fetch']['queue'] queue && queue.any? { |task| app_and_pkg == task.values_at('app', 'pkg') } end.keys - fetched_agents end |
#fetched_agents ⇒ Object
104 105 106 107 108 109 |
# File 'lib/mamiya/master/package_status.rb', line 104 def fetched_agents @fetched_agents ||= agents.select do |name, agent| packages = agent['packages'] && agent['packages'][application] packages && packages.include?(package) end.keys end |
#fetching_agents ⇒ Object
97 98 99 100 101 102 |
# File 'lib/mamiya/master/package_status.rb', line 97 def fetching_agents @fetching_agents ||= agents.select do |name, agent| task = agent['queues'] && agent['queues']['fetch'] && agent['queues']['fetch'] && agent['queues']['fetch']['working'] task && app_and_pkg == task.values_at('app', 'pkg') end.keys - fetched_agents end |
#non_participants ⇒ Object
163 164 165 |
# File 'lib/mamiya/master/package_status.rb', line 163 def non_participants agents.keys - participants end |
#participants ⇒ Object
157 158 159 160 161 |
# File 'lib/mamiya/master/package_status.rb', line 157 def participants (fetch_queued_agents + fetching_agents + fetched_agents + \ prepare_queued_agents + preparing_agents + prepared_agents + \ switch_queued_agents + switching_agents + current_agents).uniq end |
#prepare_queued_agents ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/mamiya/master/package_status.rb', line 111 def prepare_queued_agents @prepare_queued_agents ||= agents.select do |name, agent| queue = agent['queues'] && agent['queues']['prepare'] && agent['queues']['prepare']['queue'] queue && queue.any? { |task| app_and_pkg == task.values_at('app', 'pkg') } end.keys - prepared_agents end |
#prepared_agents ⇒ Object
127 128 129 130 131 132 |
# File 'lib/mamiya/master/package_status.rb', line 127 def prepared_agents @prepare_agents ||= agents.select do |name, agent| packages = agent['prereleases'] && agent['prereleases'][application] packages && packages.include?(package) end.keys end |
#preparing_agents ⇒ Object
120 121 122 123 124 125 |
# File 'lib/mamiya/master/package_status.rb', line 120 def preparing_agents @preparing_agents ||= agents.select do |name, agent| task = agent['queues'] && agent['queues']['prepare'] && agent['queues']['prepare'] && agent['queues']['prepare']['working'] task && app_and_pkg == task.values_at('app', 'pkg') end.keys - prepared_agents end |
#reload ⇒ Object
167 168 169 |
# File 'lib/mamiya/master/package_status.rb', line 167 def reload @agents = nil end |
#status ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mamiya/master/package_status.rb', line 44 def status [].tap do |s| working = false case when fetched_agents == agents.keys s << :distributed when !fetching_agents.empty? || !fetch_queued_agents.empty? working = true s << :distributing end if fetched_agents != agents.keys && !fetched_agents.empty? s << :partially_distributed end # TODO: FIXME: tests case when prepared_agents == agents.keys s << :prepared when !preparing_agents.empty? || !prepare_queued_agents.empty? working = true s << :preparing end if prepared_agents != agents.keys && !prepared_agents.empty? s << :partially_prepared end # TODO: FIXME: tests case when current_agents == agents.keys s << :active when !current_agents.empty? || !switch_queued_agents.empty? working = true s << :switching end if current_agents != agents.keys && !current_agents.empty? s << :partially_active end s << :unknown if s.empty? s << :working if working end end |
#switch_queued_agents ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/mamiya/master/package_status.rb', line 134 def switch_queued_agents @switch_queued_agents ||= agents.select do |name, agent| queue = agent['queues'] && agent['queues']['switch'] && agent['queues']['switch']['queue'] queue && queue.any? { |task| app_and_pkg == task.values_at('app', 'pkg') } end.keys - current_agents end |
#switching_agents ⇒ Object
143 144 145 146 147 148 |
# File 'lib/mamiya/master/package_status.rb', line 143 def switching_agents @switching_agents ||= agents.select do |name, agent| task = agent['queues'] && agent['queues']['switch'] && agent['queues']['switch'] && agent['queues']['switch']['working'] task && app_and_pkg == task.values_at('app', 'pkg') end.keys - current_agents end |
#to_hash ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mamiya/master/package_status.rb', line 17 def to_hash { application: application, package: package, labels: labels, status: status, participants_count: participants.size, non_participants: non_participants, active: current_agents, fetch: { queued: fetch_queued_agents, working: fetching_agents, done: fetched_agents, }, prepare: { queued: prepare_queued_agents, working: preparing_agents, done: prepared_agents, }, switch: { queued: switch_queued_agents, working: switching_agents, done: current_agents, }, } end |