Class: Cosmos::Limits
Overview
Limits uses PacketConfig to parse the command and telemetry configuration files. It provides the API layer which other classes use to access information about and manipulate limits. This includes getting, setting and checking individual limit items as well as manipulating limits groups.
Constant Summary collapse
- LATEST_PACKET_NAME =
'LATEST'.freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#disable(target_name, packet_name, item_name) ⇒ Object
Disables limit checking for the specified item.
-
#disable_group(group_name) ⇒ Object
Disables limit checking for all the items in the given group.
-
#enable(target_name, packet_name, item_name) ⇒ Object
Enables limit checking for the specified item.
-
#enable_group(group_name) ⇒ Object
Enables limit checking for all the items in the given group.
-
#enabled?(target_name, packet_name, item_name) ⇒ Boolean
Checks whether the limits are enabled for the specified item.
-
#get(target_name, packet_name, item_name, limits_set = nil) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information
Get the limits for a telemetry item.
-
#groups ⇒ Hash(String, Array)
The defined limits groups.
-
#initialize(config) ⇒ Limits
constructor
A new instance of Limits.
-
#out_of_limits ⇒ Array<Array<String, String, String, Symbol>>
Return an array of arrays indicating all items in the packet that are out of limits [[target name, packet name, item name, item limits state], …].
-
#overall_limits_state(ignored_items = nil) ⇒ Symbol
The overall limits state for the system.
-
#set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information
Set the limits for a telemetry item.
-
#sets ⇒ Array<Symbol>
The defined limits sets for all items in the packet.
-
#warnings ⇒ Array<String>
Array of strings listing all the warnings that were created while parsing the configuration file.
Constructor Details
#initialize(config) ⇒ Limits
Returns a new instance of Limits.
36 37 38 |
# File 'lib/cosmos/packets/limits.rb', line 36 def initialize(config) @config = config end |
Instance Attribute Details
Instance Method Details
#disable(target_name, packet_name, item_name) ⇒ Object
Disables limit checking for the specified item
161 162 163 |
# File 'lib/cosmos/packets/limits.rb', line 161 def disable(target_name, packet_name, item_name) get_packet(target_name, packet_name).disable_limits(item_name) end |
#disable_group(group_name) ⇒ Object
Disables limit checking for all the items in the given group.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cosmos/packets/limits.rb', line 130 def disable_group(group_name) group_upcase = group_name.to_s.upcase limits_group = @config.limits_groups[group_upcase] if limits_group limits_group.each do |target_name, packet_name, item_name| disable(target_name, packet_name, item_name) end else raise "LIMITS_GROUP #{group_upcase} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_upcase}" end end |
#enable(target_name, packet_name, item_name) ⇒ Object
Enables limit checking for the specified item
154 155 156 |
# File 'lib/cosmos/packets/limits.rb', line 154 def enable(target_name, packet_name, item_name) get_packet(target_name, packet_name).enable_limits(item_name) end |
#enable_group(group_name) ⇒ Object
Enables limit checking for all the items in the given group.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cosmos/packets/limits.rb', line 115 def enable_group(group_name) group_upcase = group_name.to_s.upcase limits_group = @config.limits_groups[group_upcase] if limits_group limits_group.each do |target_name, packet_name, item_name| enable(target_name, packet_name, item_name) end else raise "LIMITS_GROUP #{group_upcase} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_upcase}" end end |
#enabled?(target_name, packet_name, item_name) ⇒ Boolean
Checks whether the limits are enabled for the specified item
147 148 149 |
# File 'lib/cosmos/packets/limits.rb', line 147 def enabled?(target_name, packet_name, item_name) get_packet(target_name, packet_name).get_item(item_name).limits.enabled end |
#get(target_name, packet_name, item_name, limits_set = nil) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information
Get the limits for a telemetry item
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/cosmos/packets/limits.rb', line 172 def get(target_name, packet_name, item_name, limits_set = nil) limits = get_packet(target_name, packet_name).get_item(item_name).limits if limits.values if limits_set limits_set = limits_set.to_s.upcase.intern else limits_set = System.limits_set end limits_for_set = limits.values[limits_set] if limits_for_set return [limits_set, limits.persistence_setting, limits.enabled, limits_for_set[0], limits_for_set[1], limits_for_set[2], limits_for_set[3], limits_for_set[4], limits_for_set[5]] else return [nil, nil, nil, nil, nil, nil, nil, nil, nil] end else return [nil, nil, nil, nil, nil, nil, nil, nil, nil] end end |
#groups ⇒ Hash(String, Array)
Returns The defined limits groups.
108 109 110 |
# File 'lib/cosmos/packets/limits.rb', line 108 def groups return @config.limits_groups end |
#out_of_limits ⇒ Array<Array<String, String, String, Symbol>>
Return an array of arrays indicating all items in the packet that are out of limits
[[target name, packet name, item name, item limits state], ...]
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cosmos/packets/limits.rb', line 51 def out_of_limits items = [] @config.telemetry.each do |target_name, target_packets| target_packets.each do |packet_name, packet| new_items = packet.out_of_limits items.concat(new_items) end end return items end |
#overall_limits_state(ignored_items = nil) ⇒ Symbol
Returns The overall limits state for the system.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cosmos/packets/limits.rb', line 64 def overall_limits_state(ignored_items = nil) overall = :GREEN limits_packet_stale = false items_out_of_limits = [] # Note: If anything with limits is stale then overall limits state cannot be green or blue @config.telemetry.each do |target_name, target_packets| target_packets.each do |packet_name, packet| if packet.stale && !packet.limits_items.empty? if ignored_items all_ignored = true packet.limits_items.each do |item| all_ignored = false unless includes_item?(ignored_items, target_name, packet_name, item.name) end else all_ignored = false end limits_packet_stale = true unless all_ignored end items_out_of_limits.concat(packet.out_of_limits) end end items_out_of_limits.each do |target_name, packet_name, item_name, limits_state| next if ignored_items && includes_item?(ignored_items, target_name, packet_name, item_name) case overall # If our overall state is currently blue or green we can go to any state when :BLUE, :GREEN, :GREEN_HIGH, :GREEN_LOW overall = limits_state # If our overal state is yellow we can only go higher to red when :YELLOW, :YELLOW_HIGH, :YELLOW_LOW if limits_state == :RED || limits_state == :RED_HIGH || limits_state == :RED_LOW overall = limits_state break # Red is as high as we go so no need to look for more end end end overall = :GREEN if overall == :GREEN_HIGH || overall == :GREEN_LOW || overall == :BLUE overall = :YELLOW if overall == :YELLOW_HIGH || overall == :YELLOW_LOW overall = :RED if overall == :RED_HIGH || overall == :RED_LOW overall = :STALE if (overall == :GREEN || overall == :BLUE) && limits_packet_stale return overall end |
#set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information
Set the limits for a telemetry item
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/cosmos/packets/limits.rb', line 206 def set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true) packet = get_packet(target_name, packet_name) item = packet.get_item(item_name) limits = item.limits if limits_set limits_set = limits_set.to_s.upcase.intern else limits_set = System.limits_set end if !limits.values if limits_set == :DEFAULT limits.values = { :DEFAULT => [] } else raise "DEFAULT limits must be defined for #{target_name} #{packet_name} #{item_name} before setting limits set #{limits_set}" end end limits_for_set = limits.values[limits_set] unless limits_for_set limits.values[limits_set] = [] limits_for_set = limits.values[limits_set] end limits_for_set[0] = red_low.to_f limits_for_set[1] = yellow_low.to_f limits_for_set[2] = yellow_high.to_f limits_for_set[3] = red_high.to_f limits_for_set.delete_at(5) if limits_for_set[5] limits_for_set.delete_at(4) if limits_for_set[4] if green_low && green_high limits_for_set[4] = green_low.to_f limits_for_set[5] = green_high.to_f end limits.enabled = enabled limits.persistence_setting = Integer(persistence) if persistence packet.update_limits_items_cache(item) @config.limits_sets << limits_set @config.limits_sets.uniq! return [limits_set, limits.persistence_setting, limits.enabled, limits_for_set[0], limits_for_set[1], limits_for_set[2], limits_for_set[3], limits_for_set[4], limits_for_set[5]] end |