Class: RobotController::Verify
- Inherits:
-
Object
- Object
- RobotController::Verify
- Defined in:
- lib/robot-controller/verify.rb
Overview
Usage:
RobotController::Verify.new('robot1' => 1, 'robot2' => 2, 'robot3' => 0)
=> {
'robot1': { state: :up, running: 1 },
'robot2': { state: :down, running: 0 },
'robot3': { state: :not_enabled, running: 0 }
}
When no errors are detected, the output looks like so:
% bundle exec controller verify
OK
% bundle exec controller verify --verbose
OK robot1 is up
OK robot2 is up
OK robot3 is not enabled
OK robot4 is not enabled
If robot2 were down and robot3 were up, the output would look like so:
% bundle exec controller verify
ERROR robot2 is down (0 out of 3 processes running)
ERROR robot3 is not enabled but 1 process is running
% bundle exec controller verify --verbose
OK robot1 is up
ERROR robot2 is down (0 out of 3 processes running)
ERROR robot3 is not enabled but 1 process is running
OK robot4 is not enabled
The various states are determined as follows:
If the robot is enabled:
OK: all N processes are running
ERROR: not all N processes are running
If the robot is NOT enabled:
OK: no processes are running
ERROR: 1 or more processes are running
If the robot is unknown by the suite:
ERROR: always
Instance Attribute Summary collapse
-
#robots ⇒ Object
readonly
Returns the value of attribute robots.
Class Method Summary collapse
-
.consolidate_states_into_status(statuses) ⇒ Object
reduces individuals states into a single status.
-
.parse_status_line(line) ⇒ Hash
robot01_01_dor_gisAssemblyWF_assign-placenames(pid:29481): up robot02_01_dor_gisAssemblyWF_author-data(pid:29697): down robot03_01_dor_gisAssemblyWF_author-metadata(pid:29512): unmonitored.
-
.parse_status_output(output) ⇒ Array<Hash>
[ { robot: ‘robot123’, nth: 1 pid: 123 state: :down | :up }, robot: ‘robot456’, nth: 1 pid: 456 state: :down | :up } ].
Instance Method Summary collapse
-
#initialize(nprocesses) ⇒ Verify
constructor
A new instance of Verify.
-
#robot_status(robot) ⇒ Hash
{ state: :up | :down | :not_enabled, running: n }.
-
#running(robot) ⇒ Integer
Number of running processes expected otherwise nil.
-
#verify(reload = true) ⇒ Hash<Hash>
{ ‘robot1’ : { state: :up, running: 2 }, ‘robot2’ : { state: :down, running: 0 }, ‘robot3’ : { state: :not_enabled, running: 0 } }.
Constructor Details
#initialize(nprocesses) ⇒ Verify
Returns a new instance of Verify.
48 49 50 51 52 53 54 |
# File 'lib/robot-controller/verify.rb', line 48 def initialize(nprocesses) fail ArgumentError if nprocesses.nil? || !nprocesses.is_a?(Hash) fail ArgumentError, 'Empty argument' if nprocesses.size == 0 @running = nprocesses @robots = @running.keys @status = nil end |
Instance Attribute Details
#robots ⇒ Object (readonly)
Returns the value of attribute robots.
45 46 47 |
# File 'lib/robot-controller/verify.rb', line 45 def robots @robots end |
Class Method Details
.consolidate_states_into_status(statuses) ⇒ Object
reduces individuals states into a single status
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/robot-controller/verify.rb', line 186 def consolidate_states_into_status(statuses) if statuses.is_a?(Array) && statuses.size > 0 # XXX: assumes all statuses are for the same robot running = 0 state = :up statuses.each do |status| running += 1 if status[:state] == :up state = :down unless status[:state] == :up end { state: state, running: running } else fail 'No information from bundle exec controller status' end end |
.parse_status_line(line) ⇒ Hash
robot01_01_dor_gisAssemblyWF_assign-placenames(pid:29481): up robot02_01_dor_gisAssemblyWF_author-data(pid:29697): down robot03_01_dor_gisAssemblyWF_author-metadata(pid:29512): unmonitored
}
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/robot-controller/verify.rb', line 173 def parse_status_line(line) if line =~ /^robot\d\d_(\d\d)_(.+)\(pid:(\d+)\):\s+(.+)$/ return { nth: Regexp.last_match[1].to_i, robot: Regexp.last_match[2].to_s, pid: Regexp.last_match[3].to_i, state: (Regexp.last_match[4].to_s == 'up') ? :up : :down } end nil end |
.parse_status_output(output) ⇒ Array<Hash>
[
{
robot: 'robot123',
nth: 1
pid: 123
state: :down | :up
},
robot: 'robot456',
nth: 1
pid: 456
state: :down | :up
}
]
157 158 159 |
# File 'lib/robot-controller/verify.rb', line 157 def parse_status_output(output) output.inject([]) { |a, e| a << parse_status_line(e) }.compact end |
Instance Method Details
#robot_status(robot) ⇒ Hash
Returns { state: :up | :down | :not_enabled, running: n }.
85 86 87 88 89 90 91 |
# File 'lib/robot-controller/verify.rb', line 85 def robot_status(robot) if status[robot].nil? fail "ERROR: No status information for #{robot}" else status[robot] end end |
#running(robot) ⇒ Integer
Returns number of running processes expected otherwise nil.
79 80 81 |
# File 'lib/robot-controller/verify.rb', line 79 def running(robot) @running[robot] end |
#verify(reload = true) ⇒ Hash<Hash>
{
'robot1' : {
state: :up,
running: 2
},
'robot2' : {
state: :down,
running: 0
},
'robot3' : {
state: :not_enabled,
running: 0
}
}
72 73 74 75 |
# File 'lib/robot-controller/verify.rb', line 72 def verify(reload = true) @status = nil if reload {}.tap { |hash| robots.each { |robot| hash[robot] = robot_status(robot) } } end |