Class: OpenC3::TargetModel
- Defined in:
- lib/openc3/models/target_model.rb
Overview
Manages the target in Redis. It stores the target itself under the <SCOPE>__openc3_targets key under the target name field. All the command packets in the target are stored under the <SCOPE>openc3cmd<TARGET NAME> key and the telemetry under the <SCOPE>openc3tlm<TARGET NAME> key. Any new limits sets are merged into the <SCOPE>__limits_sets key as fields. Any new limits groups are created under <SCOPE>__limits_groups with field name. These Redis key/fields are all removed when the undeploy method is called.
Constant Summary collapse
- PRIMARY_KEY =
'openc3_targets'
- VALID_TYPES =
%i(CMD TLM)
- ERB_EXTENSIONS =
%w(.txt .rb .py .json .yaml .yml)
- ITEM_MAP_CACHE_TIMEOUT =
10.0
- @@item_map_cache =
{}
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#cleanup_poll_time ⇒ Object
Returns the value of attribute cleanup_poll_time.
-
#cmd_buffer_depth ⇒ Object
Returns the value of attribute cmd_buffer_depth.
-
#cmd_decom_log_cycle_size ⇒ Object
Returns the value of attribute cmd_decom_log_cycle_size.
-
#cmd_decom_log_cycle_time ⇒ Object
Returns the value of attribute cmd_decom_log_cycle_time.
-
#cmd_decom_log_retain_time ⇒ Object
Returns the value of attribute cmd_decom_log_retain_time.
-
#cmd_log_cycle_size ⇒ Object
Returns the value of attribute cmd_log_cycle_size.
-
#cmd_log_cycle_time ⇒ Object
Returns the value of attribute cmd_log_cycle_time.
-
#cmd_log_retain_time ⇒ Object
Returns the value of attribute cmd_log_retain_time.
-
#cmd_tlm_files ⇒ Object
Returns the value of attribute cmd_tlm_files.
-
#cmd_unique_id_mode ⇒ Object
Returns the value of attribute cmd_unique_id_mode.
-
#folder_name ⇒ Object
Returns the value of attribute folder_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ignored_items ⇒ Object
Returns the value of attribute ignored_items.
-
#ignored_parameters ⇒ Object
Returns the value of attribute ignored_parameters.
-
#limits_groups ⇒ Object
Returns the value of attribute limits_groups.
-
#needs_dependencies ⇒ Object
Returns the value of attribute needs_dependencies.
-
#reduced_day_log_retain_time ⇒ Object
Returns the value of attribute reduced_day_log_retain_time.
-
#reduced_hour_log_retain_time ⇒ Object
Returns the value of attribute reduced_hour_log_retain_time.
-
#reduced_minute_log_retain_time ⇒ Object
Returns the value of attribute reduced_minute_log_retain_time.
-
#requires ⇒ Object
Returns the value of attribute requires.
-
#target_microservices ⇒ Object
Returns the value of attribute target_microservices.
-
#tlm_buffer_depth ⇒ Object
Returns the value of attribute tlm_buffer_depth.
-
#tlm_decom_log_cycle_size ⇒ Object
Returns the value of attribute tlm_decom_log_cycle_size.
-
#tlm_decom_log_cycle_time ⇒ Object
Returns the value of attribute tlm_decom_log_cycle_time.
-
#tlm_decom_log_retain_time ⇒ Object
Returns the value of attribute tlm_decom_log_retain_time.
-
#tlm_log_cycle_size ⇒ Object
Returns the value of attribute tlm_log_cycle_size.
-
#tlm_log_cycle_time ⇒ Object
Returns the value of attribute tlm_log_cycle_time.
-
#tlm_log_retain_time ⇒ Object
Returns the value of attribute tlm_log_retain_time.
-
#tlm_unique_id_mode ⇒ Object
Returns the value of attribute tlm_unique_id_mode.
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary collapse
- .all(scope:) ⇒ Object
-
.all_modified(scope:) ⇒ Object
All targets with indication of modified targets.
-
.all_packet_name_descriptions(target_name, type: :TLM, scope:) ⇒ Array
Hash>] All packet hashes under the target_name.
- .build_item_to_packet_map(target_name, scope:) ⇒ Object
- .delete_modified(target_name, scope:) ⇒ Object
- .download(target_name, scope:) ⇒ Object
-
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work.
- .get_item_to_packet_map(target_name, scope:) ⇒ Object
-
.handle_config(parser, keyword, parameters, plugin: nil, needs_dependencies: false, scope:) ⇒ Object
Called by the PluginModel to allow this class to validate it’s top-level keyword: “TARGET”.
- .limits_groups(scope:) ⇒ Hash{String => Array<Array<String, String, String>>}
-
.modified_files(target_name, scope:) ⇒ Object
Given target’s modified file list.
- .names(scope:) ⇒ Object
-
.packet(target_name, packet_name, type: :TLM, scope:) ⇒ Hash
Packet hash or raises an exception.
-
.packet_item(target_name, packet_name, item_name, type: :TLM, scope:) ⇒ Hash
Item hash or raises an exception.
-
.packet_items(target_name, packet_name, items, type: :TLM, scope:) ⇒ Array<Hash>
Item hash array or raises an exception.
-
.packet_names(target_name, type: :TLM, scope:) ⇒ Array
Array of all the packet names.
-
.packets(target_name, type: :TLM, scope:) ⇒ Array
Hash>] All packet hashes under the target_name.
- .set_packet(target_name, packet_name, packet, type: :TLM, scope:) ⇒ Object
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
- #build_target_archive(temp_dir, target_folder) ⇒ Object
- #deploy(gem_path, variables, validate_only: false) ⇒ Object
- #deploy_cleanup_microservice(gem_path, variables, instance = nil, parent = nil) ⇒ Object
- #deploy_commmandlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_decom_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_decomcmdlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_decomlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_microservices(gem_path, variables, system) ⇒ Object
- #deploy_multi_microservice(gem_path, variables, instance = nil) ⇒ Object
- #deploy_packetlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_reducer_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
- #deploy_target_microservices(type, base_topic_list, topic_prefix) ⇒ Object
-
#handle_config(parser, keyword, parameters) ⇒ Object
Handles Target specific configuration keywords.
-
#initialize(name:, folder_name: nil, requires: [], ignored_parameters: [], ignored_items: [], limits_groups: [], cmd_tlm_files: [], cmd_unique_id_mode: false, tlm_unique_id_mode: false, id: nil, updated_at: nil, plugin: nil, cmd_buffer_depth: 5, cmd_log_cycle_time: 600, cmd_log_cycle_size: 50_000_000, cmd_log_retain_time: nil, cmd_decom_log_cycle_time: 600, cmd_decom_log_cycle_size: 50_000_000, cmd_decom_log_retain_time: nil, tlm_buffer_depth: 60, tlm_log_cycle_time: 600, tlm_log_cycle_size: 50_000_000, tlm_log_retain_time: nil, tlm_decom_log_cycle_time: 600, tlm_decom_log_cycle_size: 50_000_000, tlm_decom_log_retain_time: nil, reduced_minute_log_retain_time: nil, reduced_hour_log_retain_time: nil, reduced_day_log_retain_time: nil, cleanup_poll_time: 900, needs_dependencies: false, target_microservices: {'REDUCER' => [[]]}, reducer_disable: false, reducer_max_cpu_utilization: 30.0, scope:) ⇒ TargetModel
constructor
A new instance of TargetModel.
-
#render(template_name, options = {}) ⇒ Object
Called by the ERB template to render a partial.
- #undeploy ⇒ Object
- #update_store(system) ⇒ Object
Methods inherited from Model
#create, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get_all_models, get_model, set, store, #update
Constructor Details
#initialize(name:, folder_name: nil, requires: [], ignored_parameters: [], ignored_items: [], limits_groups: [], cmd_tlm_files: [], cmd_unique_id_mode: false, tlm_unique_id_mode: false, id: nil, updated_at: nil, plugin: nil, cmd_buffer_depth: 5, cmd_log_cycle_time: 600, cmd_log_cycle_size: 50_000_000, cmd_log_retain_time: nil, cmd_decom_log_cycle_time: 600, cmd_decom_log_cycle_size: 50_000_000, cmd_decom_log_retain_time: nil, tlm_buffer_depth: 60, tlm_log_cycle_time: 600, tlm_log_cycle_size: 50_000_000, tlm_log_retain_time: nil, tlm_decom_log_cycle_time: 600, tlm_decom_log_cycle_size: 50_000_000, tlm_decom_log_retain_time: nil, reduced_minute_log_retain_time: nil, reduced_hour_log_retain_time: nil, reduced_day_log_retain_time: nil, cleanup_poll_time: 900, needs_dependencies: false, target_microservices: {'REDUCER' => [[]]}, reducer_disable: false, reducer_max_cpu_utilization: 30.0, scope:) ⇒ TargetModel
Returns a new instance of TargetModel.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/openc3/models/target_model.rb', line 317 def initialize( name:, folder_name: nil, requires: [], ignored_parameters: [], ignored_items: [], limits_groups: [], cmd_tlm_files: [], cmd_unique_id_mode: false, tlm_unique_id_mode: false, id: nil, updated_at: nil, plugin: nil, cmd_buffer_depth: 5, cmd_log_cycle_time: 600, cmd_log_cycle_size: 50_000_000, cmd_log_retain_time: nil, cmd_decom_log_cycle_time: 600, cmd_decom_log_cycle_size: 50_000_000, cmd_decom_log_retain_time: nil, tlm_buffer_depth: 60, tlm_log_cycle_time: 600, tlm_log_cycle_size: 50_000_000, tlm_log_retain_time: nil, tlm_decom_log_cycle_time: 600, tlm_decom_log_cycle_size: 50_000_000, tlm_decom_log_retain_time: nil, reduced_minute_log_retain_time: nil, reduced_hour_log_retain_time: nil, reduced_day_log_retain_time: nil, cleanup_poll_time: 900, needs_dependencies: false, target_microservices: {'REDUCER' => [[]]}, reducer_disable: false, reducer_max_cpu_utilization: 30.0, scope: ) super("#{scope}__#{PRIMARY_KEY}", name: name, plugin: plugin, updated_at: updated_at, cmd_buffer_depth: cmd_buffer_depth, cmd_log_cycle_time: cmd_log_cycle_time, cmd_log_cycle_size: cmd_log_cycle_size, cmd_log_retain_time: cmd_log_retain_time, cmd_decom_log_cycle_time: cmd_decom_log_cycle_time, cmd_decom_log_cycle_size: cmd_decom_log_cycle_size, cmd_decom_log_retain_time: cmd_decom_log_retain_time, tlm_buffer_depth: tlm_buffer_depth, tlm_log_cycle_time: tlm_log_cycle_time, tlm_log_cycle_size: tlm_log_cycle_size, tlm_log_retain_time: tlm_log_retain_time, tlm_decom_log_cycle_time: tlm_decom_log_cycle_time, tlm_decom_log_cycle_size: tlm_decom_log_cycle_size, tlm_decom_log_retain_time: tlm_decom_log_retain_time, reduced_minute_log_retain_time: reduced_minute_log_retain_time, reduced_hour_log_retain_time: reduced_hour_log_retain_time, reduced_day_log_retain_time: reduced_day_log_retain_time, cleanup_poll_time: cleanup_poll_time, needs_dependencies: needs_dependencies, target_microservices: target_microservices, reducer_disable: reducer_disable, reducer_max_cpu_utilization: reducer_max_cpu_utilization, scope: scope) @folder_name = folder_name @requires = requires @ignored_parameters = ignored_parameters @ignored_items = ignored_items @limits_groups = limits_groups @cmd_tlm_files = cmd_tlm_files @cmd_unique_id_mode = cmd_unique_id_mode @tlm_unique_id_mode = tlm_unique_id_mode @id = id @cmd_buffer_depth = cmd_buffer_depth @cmd_log_cycle_time = cmd_log_cycle_time @cmd_log_cycle_size = cmd_log_cycle_size @cmd_log_retain_time = cmd_log_retain_time @cmd_decom_log_cycle_time = cmd_decom_log_cycle_time @cmd_decom_log_cycle_size = cmd_decom_log_cycle_size @cmd_decom_log_retain_time = cmd_decom_log_retain_time @tlm_buffer_depth = tlm_buffer_depth @tlm_log_cycle_time = tlm_log_cycle_time @tlm_log_cycle_size = tlm_log_cycle_size @tlm_log_retain_time = tlm_log_retain_time @tlm_decom_log_cycle_time = tlm_decom_log_cycle_time @tlm_decom_log_cycle_size = tlm_decom_log_cycle_size @tlm_decom_log_retain_time = tlm_decom_log_retain_time @reduced_minute_log_retain_time = reduced_minute_log_retain_time @reduced_hour_log_retain_time = reduced_hour_log_retain_time @reduced_day_log_retain_time = reduced_day_log_retain_time @cleanup_poll_time = cleanup_poll_time @needs_dependencies = needs_dependencies @target_microservices = target_microservices @reducer_disable = reducer_disable @reducer_max_cpu_utilization = reducer_max_cpu_utilization @bucket = Bucket.getClient() @children = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
80 81 82 |
# File 'lib/openc3/models/target_model.rb', line 80 def children @children end |
#cleanup_poll_time ⇒ Object
Returns the value of attribute cleanup_poll_time.
77 78 79 |
# File 'lib/openc3/models/target_model.rb', line 77 def cleanup_poll_time @cleanup_poll_time end |
#cmd_buffer_depth ⇒ Object
Returns the value of attribute cmd_buffer_depth.
60 61 62 |
# File 'lib/openc3/models/target_model.rb', line 60 def cmd_buffer_depth @cmd_buffer_depth end |
#cmd_decom_log_cycle_size ⇒ Object
Returns the value of attribute cmd_decom_log_cycle_size.
65 66 67 |
# File 'lib/openc3/models/target_model.rb', line 65 def cmd_decom_log_cycle_size @cmd_decom_log_cycle_size end |
#cmd_decom_log_cycle_time ⇒ Object
Returns the value of attribute cmd_decom_log_cycle_time.
64 65 66 |
# File 'lib/openc3/models/target_model.rb', line 64 def cmd_decom_log_cycle_time @cmd_decom_log_cycle_time end |
#cmd_decom_log_retain_time ⇒ Object
Returns the value of attribute cmd_decom_log_retain_time.
66 67 68 |
# File 'lib/openc3/models/target_model.rb', line 66 def cmd_decom_log_retain_time @cmd_decom_log_retain_time end |
#cmd_log_cycle_size ⇒ Object
Returns the value of attribute cmd_log_cycle_size.
62 63 64 |
# File 'lib/openc3/models/target_model.rb', line 62 def cmd_log_cycle_size @cmd_log_cycle_size end |
#cmd_log_cycle_time ⇒ Object
Returns the value of attribute cmd_log_cycle_time.
61 62 63 |
# File 'lib/openc3/models/target_model.rb', line 61 def cmd_log_cycle_time @cmd_log_cycle_time end |
#cmd_log_retain_time ⇒ Object
Returns the value of attribute cmd_log_retain_time.
63 64 65 |
# File 'lib/openc3/models/target_model.rb', line 63 def cmd_log_retain_time @cmd_log_retain_time end |
#cmd_tlm_files ⇒ Object
Returns the value of attribute cmd_tlm_files.
56 57 58 |
# File 'lib/openc3/models/target_model.rb', line 56 def cmd_tlm_files @cmd_tlm_files end |
#cmd_unique_id_mode ⇒ Object
Returns the value of attribute cmd_unique_id_mode.
57 58 59 |
# File 'lib/openc3/models/target_model.rb', line 57 def cmd_unique_id_mode @cmd_unique_id_mode end |
#folder_name ⇒ Object
Returns the value of attribute folder_name.
51 52 53 |
# File 'lib/openc3/models/target_model.rb', line 51 def folder_name @folder_name end |
#id ⇒ Object
Returns the value of attribute id.
59 60 61 |
# File 'lib/openc3/models/target_model.rb', line 59 def id @id end |
#ignored_items ⇒ Object
Returns the value of attribute ignored_items.
54 55 56 |
# File 'lib/openc3/models/target_model.rb', line 54 def ignored_items @ignored_items end |
#ignored_parameters ⇒ Object
Returns the value of attribute ignored_parameters.
53 54 55 |
# File 'lib/openc3/models/target_model.rb', line 53 def ignored_parameters @ignored_parameters end |
#limits_groups ⇒ Object
Returns the value of attribute limits_groups.
55 56 57 |
# File 'lib/openc3/models/target_model.rb', line 55 def limits_groups @limits_groups end |
#needs_dependencies ⇒ Object
Returns the value of attribute needs_dependencies.
78 79 80 |
# File 'lib/openc3/models/target_model.rb', line 78 def needs_dependencies @needs_dependencies end |
#reduced_day_log_retain_time ⇒ Object
Returns the value of attribute reduced_day_log_retain_time.
76 77 78 |
# File 'lib/openc3/models/target_model.rb', line 76 def reduced_day_log_retain_time @reduced_day_log_retain_time end |
#reduced_hour_log_retain_time ⇒ Object
Returns the value of attribute reduced_hour_log_retain_time.
75 76 77 |
# File 'lib/openc3/models/target_model.rb', line 75 def reduced_hour_log_retain_time @reduced_hour_log_retain_time end |
#reduced_minute_log_retain_time ⇒ Object
Returns the value of attribute reduced_minute_log_retain_time.
74 75 76 |
# File 'lib/openc3/models/target_model.rb', line 74 def reduced_minute_log_retain_time @reduced_minute_log_retain_time end |
#requires ⇒ Object
Returns the value of attribute requires.
52 53 54 |
# File 'lib/openc3/models/target_model.rb', line 52 def requires @requires end |
#target_microservices ⇒ Object
Returns the value of attribute target_microservices.
79 80 81 |
# File 'lib/openc3/models/target_model.rb', line 79 def target_microservices @target_microservices end |
#tlm_buffer_depth ⇒ Object
Returns the value of attribute tlm_buffer_depth.
67 68 69 |
# File 'lib/openc3/models/target_model.rb', line 67 def tlm_buffer_depth @tlm_buffer_depth end |
#tlm_decom_log_cycle_size ⇒ Object
Returns the value of attribute tlm_decom_log_cycle_size.
72 73 74 |
# File 'lib/openc3/models/target_model.rb', line 72 def tlm_decom_log_cycle_size @tlm_decom_log_cycle_size end |
#tlm_decom_log_cycle_time ⇒ Object
Returns the value of attribute tlm_decom_log_cycle_time.
71 72 73 |
# File 'lib/openc3/models/target_model.rb', line 71 def tlm_decom_log_cycle_time @tlm_decom_log_cycle_time end |
#tlm_decom_log_retain_time ⇒ Object
Returns the value of attribute tlm_decom_log_retain_time.
73 74 75 |
# File 'lib/openc3/models/target_model.rb', line 73 def tlm_decom_log_retain_time @tlm_decom_log_retain_time end |
#tlm_log_cycle_size ⇒ Object
Returns the value of attribute tlm_log_cycle_size.
69 70 71 |
# File 'lib/openc3/models/target_model.rb', line 69 def tlm_log_cycle_size @tlm_log_cycle_size end |
#tlm_log_cycle_time ⇒ Object
Returns the value of attribute tlm_log_cycle_time.
68 69 70 |
# File 'lib/openc3/models/target_model.rb', line 68 def tlm_log_cycle_time @tlm_log_cycle_time end |
#tlm_log_retain_time ⇒ Object
Returns the value of attribute tlm_log_retain_time.
70 71 72 |
# File 'lib/openc3/models/target_model.rb', line 70 def tlm_log_retain_time @tlm_log_retain_time end |
#tlm_unique_id_mode ⇒ Object
Returns the value of attribute tlm_unique_id_mode.
58 59 60 |
# File 'lib/openc3/models/target_model.rb', line 58 def tlm_unique_id_mode @tlm_unique_id_mode end |
Class Method Details
.all(scope:) ⇒ Object
92 93 94 |
# File 'lib/openc3/models/target_model.rb', line 92 def self.all(scope:) super("#{scope}__#{PRIMARY_KEY}") end |
.all_modified(scope:) ⇒ Object
All targets with indication of modified targets
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/openc3/models/target_model.rb', line 97 def self.all_modified(scope:) targets = self.all(scope: scope) targets.each { |target_name, target| target['modified'] = false } if ENV['OPENC3_LOCAL_MODE'] modified_targets = OpenC3::LocalMode.modified_targets(scope: scope) modified_targets.each do |target_name| targets[target_name]['modified'] = true if targets[target_name] end else modified_targets = Bucket.getClient().list_files(bucket: ENV['OPENC3_CONFIG_BUCKET'], path: "DEFAULT/targets_modified/", only_directories: true) modified_targets.each do |target_name| # A target could have been deleted without removing the modified files # Thus we have to check for the existance of the target_name key if targets.has_key?(target_name) targets[target_name]['modified'] = true end end end # Sort (which turns hash to array) and return hash # This enables a consistent listing of the targets targets.sort.to_h end |
.all_packet_name_descriptions(target_name, type: :TLM, scope:) ⇒ Array
Returns Hash>] All packet hashes under the target_name.
225 226 227 |
# File 'lib/openc3/models/target_model.rb', line 225 def self.all_packet_name_descriptions(target_name, type: :TLM, scope:) self.packets(target_name, type: type, scope: scope).map! { |hash| hash.slice("packet_name", "description") } end |
.build_item_to_packet_map(target_name, scope:) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/openc3/models/target_model.rb', line 290 def self.build_item_to_packet_map(target_name, scope:) item_map = {} packets = packets(target_name, scope: scope) packets.each do |packet| items = packet['items'] items.each do |item| item_name = item['name'] item_map[item_name] ||= [] item_map[item_name] << packet['packet_name'] end end return item_map end |
.delete_modified(target_name, scope:) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/openc3/models/target_model.rb', line 143 def self.delete_modified(target_name, scope:) if ENV['OPENC3_LOCAL_MODE'] OpenC3::LocalMode.delete_modified(target_name, scope: scope) end bucket = Bucket.getClient() # Delete the remote files as well resp = bucket.list_objects( bucket: ENV['OPENC3_CONFIG_BUCKET'], # The trailing slash is important! prefix: "#{scope}/targets_modified/#{target_name}/", ) resp.each do |item| bucket.delete_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: item.key) end end |
.download(target_name, scope:) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/openc3/models/target_model.rb', line 159 def self.download(target_name, scope:) tmp_dir = Dir.mktmpdir zip_filename = File.join(tmp_dir, "#{target_name}.zip") Zip.continue_on_exists_proc = true zip = Zip::File.open(zip_filename, Zip::File::CREATE) if ENV['OPENC3_LOCAL_MODE'] OpenC3::LocalMode.zip_target(target_name, zip, scope: scope) else bucket = Bucket.getClient() # The trailing slash is important! prefix = "#{scope}/targets_modified/#{target_name}/" resp = bucket.list_objects( bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix, ) resp.each do |item| # item.key looks like DEFAULT/targets_modified/INST/screens/blah.txt base_path = item.key.sub(prefix, '') # remove prefix local_path = File.join(tmp_dir, base_path) # Ensure dir structure exists, get_object fails if not FileUtils.mkdir_p(File.dirname(local_path)) bucket.get_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: item.key, path: local_path) zip.add(base_path, local_path) end end zip.close result = OpenStruct.new result.filename = File.basename(zip_filename) result.contents = File.read(zip_filename, mode: 'rb') return result end |
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work
84 85 86 |
# File 'lib/openc3/models/target_model.rb', line 84 def self.get(name:, scope:) super("#{scope}__#{PRIMARY_KEY}", name: name) end |
.get_item_to_packet_map(target_name, scope:) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/openc3/models/target_model.rb', line 274 def self.get_item_to_packet_map(target_name, scope:) cache_time, item_map = @@item_map_cache[target_name] return item_map if item_map and (Time.now - cache_time) < ITEM_MAP_CACHE_TIMEOUT item_map_key = "#{scope}__#{target_name}__item_to_packet_map" target_name = target_name.upcase json_data = Store.get(item_map_key) if json_data item_map = JSON.parse(json_data, :allow_nan => true, :create_additions => true) else item_map = build_item_to_packet_map(target_name, scope: scope) Store.set(item_map_key, JSON.generate(item_map, :allow_nan => true)) end @@item_map_cache[target_name] = [Time.now, item_map] return item_map end |
.handle_config(parser, keyword, parameters, plugin: nil, needs_dependencies: false, scope:) ⇒ Object
Called by the PluginModel to allow this class to validate it’s top-level keyword: “TARGET”
305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/openc3/models/target_model.rb', line 305 def self.handle_config(parser, keyword, parameters, plugin: nil, needs_dependencies: false, scope:) case keyword when 'TARGET' usage = "#{keyword} <TARGET FOLDER NAME> <TARGET NAME>" parser.verify_num_parameters(2, 2, usage) parser.verify_parameter_naming(2) # Target name is the 2nd parameter return self.new(name: parameters[1].to_s.upcase, folder_name: parameters[0].to_s.upcase, plugin: plugin, needs_dependencies: needs_dependencies, scope: scope) else raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}") end end |
.limits_groups(scope:) ⇒ Hash{String => Array<Array<String, String, String>>}
265 266 267 268 269 270 271 272 |
# File 'lib/openc3/models/target_model.rb', line 265 def self.limits_groups(scope:) groups = Store.hgetall("#{scope}__limits_groups") if groups groups.map { |group, items| [group, JSON.parse(items, :allow_nan => true, :create_additions => true)] }.to_h else {} end end |
.modified_files(target_name, scope:) ⇒ Object
Given target’s modified file list
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/openc3/models/target_model.rb', line 122 def self.modified_files(target_name, scope:) modified = [] if ENV['OPENC3_LOCAL_MODE'] modified = OpenC3::LocalMode.modified_files(target_name, scope: scope) else resp = Bucket.getClient().list_objects( bucket: ENV['OPENC3_CONFIG_BUCKET'], # The trailing slash is important! prefix: "#{scope}/targets_modified/#{target_name}/", ) resp.each do |item| # Results look like DEFAULT/targets_modified/INST/procedures/new.rb # so split on '/' and ignore the first two values modified << item.key.split('/')[2..-1].join('/') end end # Sort to enable a consistent listing of the modified files modified.sort end |
.names(scope:) ⇒ Object
88 89 90 |
# File 'lib/openc3/models/target_model.rb', line 88 def self.names(scope:) super("#{scope}__#{PRIMARY_KEY}") end |
.packet(target_name, packet_name, type: :TLM, scope:) ⇒ Hash
Returns Packet hash or raises an exception.
201 202 203 204 205 206 207 208 209 |
# File 'lib/openc3/models/target_model.rb', line 201 def self.packet(target_name, packet_name, type: :TLM, scope:) raise "Unknown type #{type} for #{target_name} #{packet_name}" unless VALID_TYPES.include?(type) # Assume it exists and just try to get it to avoid an extra call to Store.exist? json = Store.hget("#{scope}__openc3#{type.to_s.downcase}__#{target_name}", packet_name) raise "Packet '#{target_name} #{packet_name}' does not exist" if json.nil? JSON.parse(json, :allow_nan => true, :create_additions => true) end |
.packet_item(target_name, packet_name, item_name, type: :TLM, scope:) ⇒ Hash
Returns Item hash or raises an exception.
241 242 243 244 245 246 |
# File 'lib/openc3/models/target_model.rb', line 241 def self.packet_item(target_name, packet_name, item_name, type: :TLM, scope:) packet = packet(target_name, packet_name, type: type, scope: scope) item = packet['items'].find { |item| item['name'] == item_name.to_s } raise "Item '#{packet['target_name']} #{packet['packet_name']} #{item_name}' does not exist" unless item item end |
.packet_items(target_name, packet_name, items, type: :TLM, scope:) ⇒ Array<Hash>
Returns Item hash array or raises an exception.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/openc3/models/target_model.rb', line 249 def self.packet_items(target_name, packet_name, items, type: :TLM, scope:) packet = packet(target_name, packet_name, type: type, scope: scope) found = packet['items'].find_all { |item| items.map(&:to_s).include?(item['name']) } if found.length != items.length # we didn't find them all found_items = found.collect { |item| item['name'] } not_found = [] (items - found_items).each do |item| not_found << "'#{target_name} #{packet_name} #{item}'" end # 'does not exist' not gramatically correct but we use it in every other exception raise "Item(s) #{not_found.join(', ')} does not exist" end found end |
.packet_names(target_name, type: :TLM, scope:) ⇒ Array
Returns Array of all the packet names.
194 195 196 197 198 |
# File 'lib/openc3/models/target_model.rb', line 194 def self.packet_names(target_name, type: :TLM, scope:) raise "Unknown type #{type} for #{target_name}" unless VALID_TYPES.include?(type) # If the key doesn't exist or if there are no packets we return empty array Store.hkeys("#{scope}__openc3#{type.to_s.downcase}__#{target_name}").sort end |
.packets(target_name, type: :TLM, scope:) ⇒ Array
Returns Hash>] All packet hashes under the target_name.
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/openc3/models/target_model.rb', line 212 def self.packets(target_name, type: :TLM, scope:) raise "Unknown type #{type} for #{target_name}" unless VALID_TYPES.include?(type) raise "Target '#{target_name}' does not exist for scope: #{scope}" unless get(name: target_name, scope: scope) result = [] packets = Store.hgetall("#{scope}__openc3#{type.to_s.downcase}__#{target_name}") packets.sort.each do |packet_name, packet_json| result << JSON.parse(packet_json, :allow_nan => true, :create_additions => true) end result end |
.set_packet(target_name, packet_name, packet, type: :TLM, scope:) ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/openc3/models/target_model.rb', line 229 def self.set_packet(target_name, packet_name, packet, type: :TLM, scope:) raise "Unknown type #{type} for #{target_name} #{packet_name}" unless VALID_TYPES.include?(type) begin Store.hset("#{scope}__openc3#{type.to_s.downcase}__#{target_name}", packet_name, JSON.generate(packet.as_json(:allow_nan => true))) rescue JSON::GeneratorError => err Logger.error("Invalid text present in #{target_name} #{packet_name} #{type.to_s.downcase} packet") raise err end end |
Instance Method Details
#as_json(*a) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/openc3/models/target_model.rb', line 403 def as_json(*a) { 'name' => @name, 'folder_name' => @folder_name, 'requires' => @requires, 'ignored_parameters' => @ignored_parameters, 'ignored_items' => @ignored_items, 'limits_groups' => @limits_groups, 'cmd_tlm_files' => @cmd_tlm_files, 'cmd_unique_id_mode' => cmd_unique_id_mode, 'tlm_unique_id_mode' => @tlm_unique_id_mode, 'id' => @id, 'updated_at' => @updated_at, 'plugin' => @plugin, 'cmd_buffer_depth' => @cmd_buffer_depth, 'cmd_log_cycle_time' => @cmd_log_cycle_time, 'cmd_log_cycle_size' => @cmd_log_cycle_size, 'cmd_log_retain_time' => @cmd_log_retain_time, 'cmd_decom_log_cycle_time' => @cmd_decom_log_cycle_time, 'cmd_decom_log_cycle_size' => @cmd_decom_log_cycle_size, 'cmd_decom_log_retain_time' => @cmd_decom_log_retain_time, 'tlm_buffer_depth' => @tlm_buffer_depth, 'tlm_log_cycle_time' => @tlm_log_cycle_time, 'tlm_log_cycle_size' => @tlm_log_cycle_size, 'tlm_log_retain_time' => @tlm_log_retain_time, 'tlm_decom_log_cycle_time' => @tlm_decom_log_cycle_time, 'tlm_decom_log_cycle_size' => @tlm_decom_log_cycle_size, 'tlm_decom_log_retain_time' => @tlm_decom_log_retain_time, 'reduced_minute_log_retain_time' => @reduced_minute_log_retain_time, 'reduced_hour_log_retain_time' => @reduced_hour_log_retain_time, 'reduced_day_log_retain_time' => @reduced_day_log_retain_time, 'cleanup_poll_time' => @cleanup_poll_time, 'needs_dependencies' => @needs_dependencies, 'target_microservices' => @target_microservices.as_json(:allow_nan => true), 'reducer_disable' => @reducer_disable, 'reducer_max_cpu_utilization' => @reducer_max_cpu_utilization } end |
#build_target_archive(temp_dir, target_folder) ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
# File 'lib/openc3/models/target_model.rb', line 691 def build_target_archive(temp_dir, target_folder) target_files = [] Find.find(target_folder) { |file| target_files << file } target_files.sort! hash = OpenC3.hash_files(target_files, nil, 'SHA256').hexdigest File.open(File.join(target_folder, 'target_id.txt'), 'wb') { |file| file.write(hash) } key = "#{@scope}/targets/#{@name}/target_id.txt" @bucket.put_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: key, body: hash) # Create target archive zip file prefix = File.dirname(target_folder) + '/' output_file = File.join(temp_dir, @name + '_' + hash + '.zip') Zip.continue_on_exists_proc = true Zip::File.open(output_file, Zip::File::CREATE) do |zipfile| target_files.each do |target_file| zip_file_path = target_file.delete_prefix(prefix) if File.directory?(target_file) zipfile.mkdir(zip_file_path) else zipfile.add(zip_file_path, target_file) end end end # Write Target Archive to bucket File.open(output_file, 'rb') do |file| bucket_key = key = "#{@scope}/target_archives/#{@name}/#{@name}_current.zip" @bucket.put_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: bucket_key, body: file) end File.open(output_file, 'rb') do |file| bucket_key = key = "#{@scope}/target_archives/#{@name}/#{@name}_#{hash}.zip" @bucket.put_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: bucket_key, body: file) end end |
#deploy(gem_path, variables, validate_only: false) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/openc3/models/target_model.rb', line 553 def deploy(gem_path, variables, validate_only: false) variables["target_name"] = @name start_path = "/targets/#{@folder_name}/" temp_dir = Dir.mktmpdir found = false begin target_path = gem_path + start_path + "**/*" Dir.glob(target_path) do |filename| next if filename == '.' or filename == '..' or File.directory?(filename) path = filename.split(gem_path)[-1] target_folder_path = path.split(start_path)[-1] key = "#{@scope}/targets/#{@name}/#{target_folder_path}" # Load target files @filename = filename # For render data = File.read(filename, mode: "rb") begin OpenC3.set_working_dir(File.dirname(filename)) do if ERB_EXTENSIONS.include?(File.extname(filename).downcase) and File.basename(filename)[0] != '_' data = ERB.new(data.force_encoding("UTF-8").comment_erb(), trim_mode: "-").result(binding.set_variables(variables)) end end rescue => error # ERB error parsing a screen is just a logger error because life can go on # With cmd/tlm or scripts this is a serious error and we raise if (filename.include?('/screens/')) Logger.error("ERB error parsing #{key} due to #{error.}") else raise "ERB error parsing #{key} due to #{error.}" end end local_path = File.join(temp_dir, @name, target_folder_path) FileUtils.mkdir_p(File.dirname(local_path)) File.open(local_path, 'wb') { |file| file.write(data) } found = true @bucket.put_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: key, body: data) unless validate_only end raise "No target files found at #{target_path}" unless found target_folder = File.join(temp_dir, @name) # Build a System for just this target system = System.new([@name], temp_dir) if variables["xtce_output"] puts "Converting target #{@name} to .xtce files in #{variables["xtce_output"]}/#{@name}" system.packet_config.to_xtce(variables["xtce_output"]) end unless validate_only build_target_archive(temp_dir, target_folder) system = update_store(system) deploy_microservices(gem_path, variables, system) ConfigTopic.write({ kind: 'created', type: 'target', name: @name, plugin: @plugin }, scope: @scope) end ensure FileUtils.remove_entry(temp_dir) if temp_dir and File.exist?(temp_dir) end end |
#deploy_cleanup_microservice(gem_path, variables, instance = nil, parent = nil) ⇒ Object
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/openc3/models/target_model.rb', line 943 def deploy_cleanup_microservice(gem_path, variables, instance = nil, parent = nil) microservice_name = "#{@scope}__CLEANUP#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, cmd: ["ruby", "cleanup_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', plugin: @plugin, parent: parent, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_commmandlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/openc3/models/target_model.rb', line 796 def deploy_commmandlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__COMMANDLOG#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "log_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', options: [ ["RAW_OR_DECOM", "RAW"], ["CMD_OR_TLM", "CMD"], ["CYCLE_TIME", @cmd_log_cycle_time], ["CYCLE_SIZE", @cmd_log_cycle_size], ["BUFFER_DEPTH", @cmd_buffer_depth] ], topics: topics, plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_decom_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
# File 'lib/openc3/models/target_model.rb', line 900 def deploy_decom_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__DECOM#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "decom_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', topics: topics, target_names: [@name], plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_decomcmdlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 |
# File 'lib/openc3/models/target_model.rb', line 822 def deploy_decomcmdlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__DECOMCMDLOG#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "log_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', options: [ ["RAW_OR_DECOM", "DECOM"], ["CMD_OR_TLM", "CMD"], ["CYCLE_TIME", @cmd_decom_log_cycle_time], ["CYCLE_SIZE", @cmd_decom_log_cycle_size], ["BUFFER_DEPTH", @cmd_buffer_depth] ], topics: topics, plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_decomlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/openc3/models/target_model.rb', line 874 def deploy_decomlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__DECOMLOG#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "log_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', options: [ ["RAW_OR_DECOM", "DECOM"], ["CMD_OR_TLM", "TLM"], ["CYCLE_TIME", @tlm_decom_log_cycle_time], ["CYCLE_SIZE", @tlm_decom_log_cycle_size], ["BUFFER_DEPTH", @tlm_buffer_depth] ], topics: topics, plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_microservices(gem_path, variables, system) ⇒ Object
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
# File 'lib/openc3/models/target_model.rb', line 1012 def deploy_microservices(gem_path, variables, system) command_topic_list = [] decom_command_topic_list = [] packet_topic_list = [] decom_topic_list = [] reduced_topic_list = [] begin system.commands.packets(@name).each do |packet_name, packet| command_topic_list << "#{@scope}__COMMAND__{#{@name}}__#{packet_name}" decom_command_topic_list << "#{@scope}__DECOMCMD__{#{@name}}__#{packet_name}" end rescue # No command packets for this target end begin system.telemetry.packets(@name).each do |packet_name, packet| packet_topic_list << "#{@scope}__TELEMETRY__{#{@name}}__#{packet_name}" decom_topic_list << "#{@scope}__DECOM__{#{@name}}__#{packet_name}" reduced_topic_list << "#{@scope}__REDUCED_MINUTE__{#{@name}}__#{packet_name}" reduced_topic_list << "#{@scope}__REDUCED_HOUR__{#{@name}}__#{packet_name}" reduced_topic_list << "#{@scope}__REDUCED_DAY__{#{@name}}__#{packet_name}" end rescue # No telemetry packets for this target end @parent = nil %w(DECOM COMMANDLOG DECOMCMDLOG PACKETLOG DECOMLOG REDUCER CLEANUP).each do |type| unless @target_microservices[type] @parent = "#{@scope}__MULTI__#{@name}" break end end unless command_topic_list.empty? # CommandLog Microservice deploy_target_microservices('COMMANDLOG', command_topic_list, "#{@scope}__COMMAND__{#{@name}}") do |topics, instance, parent| deploy_commmandlog_microservice(gem_path, variables, topics, instance, parent) end # DecomCmdLog Microservice deploy_target_microservices('DECOMCMDLOG', decom_command_topic_list, "#{@scope}__DECOMCMD__{#{@name}}") do |topics, instance, parent| deploy_decomcmdlog_microservice(gem_path, variables, topics, instance, parent) end end unless packet_topic_list.empty? # PacketLog Microservice deploy_target_microservices('PACKETLOG', packet_topic_list, "#{@scope}__TELEMETRY__{#{@name}}") do |topics, instance, parent| deploy_packetlog_microservice(gem_path, variables, topics, instance, parent) end # DecomLog Microservice deploy_target_microservices('DECOMLOG', decom_topic_list, "#{@scope}__DECOM__{#{@name}}") do |topics, instance, parent| deploy_decomlog_microservice(gem_path, variables, topics, instance, parent) end # Decommutation Microservice deploy_target_microservices('DECOM', packet_topic_list, "#{@scope}__TELEMETRY__{#{@name}}") do |topics, instance, parent| deploy_decom_microservice(gem_path, variables, topics, instance, parent) end # Reducer Microservice unless @reducer_disable deploy_target_microservices('REDUCER', decom_topic_list, "#{@scope}__DECOM__{#{@name}}") do |topics, instance, parent| deploy_reducer_microservice(gem_path, variables, topics, instance, parent) end end end if @cmd_log_retain_time or @cmd_decom_log_retain_time or @tlm_log_retain_time or @tlm_decom_log_retain_time or @reduced_minute_log_retain_time or @reduced_hour_log_retain_time or @reduced_day_log_retain_time # Cleanup Microservice deploy_target_microservices('CLEANUP', nil, nil) do |_, instance, parent| deploy_cleanup_microservice(gem_path, variables, instance, parent) end end if @parent # Multi Microservice to parent other target microservices deploy_multi_microservice(gem_path, variables) end end |
#deploy_multi_microservice(gem_path, variables, instance = nil) ⇒ Object
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/openc3/models/target_model.rb', line 959 def deploy_multi_microservice(gem_path, variables, instance = nil) if @children.length > 0 microservice_name = "#{@scope}__MULTI#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, cmd: ["ruby", "multi_microservice.rb", *@children], work_dir: '/openc3/lib/openc3/microservices', target_names: [@name], plugin: @plugin, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) Logger.info "Configured microservice #{microservice_name}" end end |
#deploy_packetlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/openc3/models/target_model.rb', line 848 def deploy_packetlog_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__PACKETLOG#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "log_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', options: [ ["RAW_OR_DECOM", "RAW"], ["CMD_OR_TLM", "TLM"], ["CYCLE_TIME", @tlm_log_cycle_time], ["CYCLE_SIZE", @tlm_log_cycle_size], ["BUFFER_DEPTH", @tlm_buffer_depth] ], topics: topics, plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_reducer_microservice(gem_path, variables, topics, instance = nil, parent = nil) ⇒ Object
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 |
# File 'lib/openc3/models/target_model.rb', line 920 def deploy_reducer_microservice(gem_path, variables, topics, instance = nil, parent = nil) microservice_name = "#{@scope}__REDUCER#{instance}__#{@name}" microservice = MicroserviceModel.new( name: microservice_name, folder_name: @folder_name, cmd: ["ruby", "reducer_microservice.rb", microservice_name], work_dir: '/openc3/lib/openc3/microservices', options: [ ["MAX_CPU_UTILIZATION", @reducer_max_cpu_utilization], ["BUFFER_DEPTH", @tlm_buffer_depth] ], topics: topics, plugin: @plugin, parent: parent, needs_dependencies: @needs_dependencies, scope: @scope ) microservice.create microservice.deploy(gem_path, variables) @children << microservice_name if parent Logger.info "Configured microservice #{microservice_name}" end |
#deploy_target_microservices(type, base_topic_list, topic_prefix) ⇒ Object
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/openc3/models/target_model.rb', line 976 def deploy_target_microservices(type, base_topic_list, topic_prefix) target_microservices = @target_microservices[type] if target_microservices if base_topic_list deploy_count = 0 all_topics = base_topic_list.dup target_microservices.sort! {|a, b| a.length <=> b.length} target_microservices.each_with_index do |packet_names, index| topics = [] packet_names.each do |packet_name| topics << "#{topic_prefix}__#{packet_name}" end topics = all_topics.dup if topics.length <= 0 if topics.length > 0 instance = nil instance = deploy_count unless deploy_count == 0 yield topics, instance, nil deploy_count += 1 topics.each do |topic| all_topics.delete(topic) end end end if all_topics.length > 0 instance = nil instance = deploy_count unless deploy_count == 0 yield all_topics, instance, nil end else yield nil, nil, nil end else yield base_topic_list, nil, @parent if not base_topic_list or base_topic_list.length > 0 end end |
#handle_config(parser, keyword, parameters) ⇒ Object
Handles Target specific configuration keywords
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/openc3/models/target_model.rb', line 443 def handle_config(parser, keyword, parameters) case keyword when 'CMD_BUFFER_DEPTH' parser.verify_num_parameters(1, 1, "#{keyword} <Number of commands to buffer to ensure logged in order>") @cmd_buffer_depth = parameters[0].to_i when 'CMD_LOG_CYCLE_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum time between files in seconds>") @cmd_log_cycle_time = parameters[0].to_i when 'CMD_LOG_CYCLE_SIZE' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum file size in bytes>") @cmd_log_cycle_size = parameters[0].to_i when 'CMD_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for cmd log files in seconds - nil = Forever>") @cmd_log_retain_time = ConfigParser.handle_nil(parameters[0]) @cmd_log_retain_time = @cmd_log_retain_time.to_i if @cmd_log_retain_time when 'CMD_DECOM_LOG_CYCLE_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum time between files in seconds>") @cmd_decom_log_cycle_time = parameters[0].to_i when 'CMD_DECOM_LOG_CYCLE_SIZE' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum file size in bytes>") @cmd_decom_log_cycle_size = parameters[0].to_i when 'CMD_DECOM_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for cmd decom log files in seconds - nil = Forever>") @cmd_decom_log_retain_time = ConfigParser.handle_nil(parameters[0]) @cmd_decom_log_retain_time = @cmd_decom_log_retain_time.to_i if @cmd_decom_log_retain_time when 'TLM_BUFFER_DEPTH' parser.verify_num_parameters(1, 1, "#{keyword} <Number of telemetry packets to buffer to ensure logged in order>") @tlm_buffer_depth = parameters[0].to_i when 'TLM_LOG_CYCLE_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum time between files in seconds>") @tlm_log_cycle_time = parameters[0].to_i when 'TLM_LOG_CYCLE_SIZE' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum file size in bytes>") @tlm_log_cycle_size = parameters[0].to_i when 'TLM_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for tlm log files in seconds - nil = Forever>") @tlm_log_retain_time = ConfigParser.handle_nil(parameters[0]) @tlm_log_retain_time = @tlm_log_retain_time.to_i if @tlm_log_retain_time when 'TLM_DECOM_LOG_CYCLE_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum time between files in seconds>") @tlm_decom_log_cycle_time = parameters[0].to_i when 'TLM_DECOM_LOG_CYCLE_SIZE' parser.verify_num_parameters(1, 1, "#{keyword} <Maximum file size in bytes>") @tlm_decom_log_cycle_size = parameters[0].to_i when 'TLM_DECOM_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for tlm decom log files in seconds - nil = Forever>") @tlm_decom_log_retain_time = ConfigParser.handle_nil(parameters[0]) @tlm_decom_log_retain_time = @tlm_decom_log_retain_time.to_i if @tlm_decom_log_retain_time when 'REDUCED_MINUTE_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for reduced minute log files in seconds - nil = Forever>") @reduced_minute_log_retain_time = ConfigParser.handle_nil(parameters[0]) @reduced_minute_log_retain_time = @reduced_minute_log_retain_time.to_i if @reduced_minute_log_retain_time when 'REDUCED_HOUR_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for reduced hour log files in seconds - nil = Forever>") @reduced_hour_log_retain_time = ConfigParser.handle_nil(parameters[0]) @reduced_hour_log_retain_time = @reduced_hour_log_retain_time.to_i if @reduced_hour_log_retain_time when 'REDUCED_DAY_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for reduced day log files in seconds - nil = Forever>") @reduced_day_log_retain_time = ConfigParser.handle_nil(parameters[0]) @reduced_day_log_retain_time = @reduced_day_log_retain_time.to_i if @reduced_day_log_retain_time when 'LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for all log files in seconds - nil = Forever>") log_retain_time = ConfigParser.handle_nil(parameters[0]) if log_retain_time @cmd_log_retain_time = log_retain_time.to_i @cmd_decom_log_retain_time = log_retain_time.to_i @tlm_log_retain_time = log_retain_time.to_i @tlm_decom_log_retain_time = log_retain_time.to_i end when 'REDUCED_LOG_RETAIN_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Retention time for all reduced log files in seconds - nil = Forever>") reduced_log_retain_time = ConfigParser.handle_nil(parameters[0]) if reduced_log_retain_time @reduced_minute_log_retain_time = reduced_log_retain_time.to_i @reduced_hour_log_retain_time = reduced_log_retain_time.to_i @reduced_day_log_retain_time = reduced_log_retain_time.to_i end when 'REDUCER_DISABLE', 'REDUCER_DISABLED' # Handle typos @reducer_disable = true when 'REDUCER_MAX_CPU_UTILIZATION', 'REDUCED_MAX_CPU_UTILIZATION' # Handle typos parser.verify_num_parameters(1, 1, "#{keyword} <Max cpu utilization to allocate to the reducer microservice - 0.0 to 100.0>") @reducer_max_cpu_utilization = Float(parameters[0]) when 'CLEANUP_POLL_TIME' parser.verify_num_parameters(1, 1, "#{keyword} <Cleanup polling period in seconds>") @cleanup_poll_time = parameters[0].to_i when 'TARGET_MICROSERVICE' parser.verify_num_parameters(1, 1, "#{keyword} <Type: DECOM COMMANDLOG DECOMCMDLOG PACKETLOG DECOMLOG REDUCER CLEANUP>") type = parameters[0].to_s.upcase unless %w(DECOM COMMANDLOG DECOMCMDLOG PACKETLOG DECOMLOG REDUCER CLEANUP).include?(type) raise "Unknown TARGET_MICROSERVICE #{type}" end @target_microservices[type] ||= [] @target_microservices[type] << [] @current_target_microservice = type when 'PACKET' if @current_target_microservice parser.verify_num_parameters(1, 1, "#{keyword} <Packet Name>") if @current_target_microservice == 'REDUCER' or @current_target_microservice == 'CLEANUP' raise ConfigParser::Error.new(parser, "PACKET cannot be used with target microservice #{@current_target_microservice}") end @target_microservices[@current_target_microservice][-1] << parameters[0].to_s.upcase else raise ConfigParser::Error.new(parser, "PACKET cannot be used without a TARGET_MICROSERVICE") end else raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}") end return nil end |
#render(template_name, options = {}) ⇒ Object
Called by the ERB template to render a partial
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/openc3/models/target_model.rb', line 666 def render(template_name, = {}) raise "Partial name '#{template_name}' must begin with an underscore." if File.basename(template_name)[0] != '_' b = binding b.local_variable_set(:target_name, @name) if [:locals] [:locals].each { |key, value| b.local_variable_set(key, value) } end # Assume the file is there. If not we raise a pretty obvious error if File.(template_name) == template_name # absolute path path = template_name else # relative to the current @filename path = File.join(File.dirname(@filename), template_name) end begin OpenC3.set_working_dir(File.dirname(path)) do return ERB.new(File.read(path).force_encoding("UTF-8").comment_erb(), trim_mode: "-").result(b) end rescue => error raise "ERB error parsing: #{path}: #{error.formatted}" end end |
#undeploy ⇒ Object
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/openc3/models/target_model.rb', line 611 def undeploy prefix = "#{@scope}/targets/#{@name}/" @bucket.list_objects(bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix).each do |object| @bucket.delete_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: object.key) end self.class.get_model(name: @name, scope: @scope).limits_groups.each do |group| Store.hdel("#{@scope}__limits_groups", group) end self.class.packets(@name, type: :CMD, scope: @scope).each do |packet| Topic.del("#{@scope}__COMMAND__{#{@name}}__#{packet['packet_name']}") Topic.del("#{@scope}__DECOMCMD__{#{@name}}__#{packet['packet_name']}") end self.class.packets(@name, scope: @scope).each do |packet| Topic.del("#{@scope}__TELEMETRY__{#{@name}}__#{packet['packet_name']}") Topic.del("#{@scope}__DECOM__{#{@name}}__#{packet['packet_name']}") Topic.del("#{@scope}__REDUCED_MINUTE__{#{@name}}__#{packet['packet_name']}") Topic.del("#{@scope}__REDUCED_HOUR__{#{@name}}__#{packet['packet_name']}") Topic.del("#{@scope}__REDUCED_DAY__{#{@name}}__#{packet['packet_name']}") CvtModel.del(target_name: @name, packet_name: packet['packet_name'], scope: @scope) end LimitsEventTopic.delete(@name, scope: @scope) Store.del("#{@scope}__openc3tlm__#{@name}") Store.del("#{@scope}__openc3cmd__#{@name}") # Note: these match the names of the services in deploy_microservices %w(MULTI DECOM COMMANDLOG DECOMCMDLOG PACKETLOG DECOMLOG REDUCER CLEANUP).each do |type| target_microservices = @target_microservices[type] if target_microservices max_instances = target_microservices.length + 1 else max_instances = 1 end max_instances.times do |index| instance = nil instance = index unless index == 0 model = MicroserviceModel.get_model(name: "#{@scope}__#{type}#{instance}__#{@name}", scope: @scope) model.destroy if model end end # Delete item_map item_map_key = "#{@scope}__#{@name}__item_to_packet_map" Store.del(item_map_key) @@item_map_cache[@name] = nil ConfigTopic.write({ kind: 'deleted', type: 'target', name: @name, plugin: @plugin }, scope: @scope) rescue Exception => error Logger.error("Error undeploying target model #{@name} in scope #{@scope} due to #{error}") end |
#update_store(system) ⇒ Object
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/openc3/models/target_model.rb', line 726 def update_store(system) target = system.targets[@name] # Add in the information from the target and update @requires = target.requires @ignored_parameters = target.ignored_parameters @ignored_items = target.ignored_items @cmd_tlm_files = target.cmd_tlm_files @cmd_unique_id_mode = target.cmd_unique_id_mode @tlm_unique_id_mode = target.tlm_unique_id_mode @id = target.id @limits_groups = system.limits.groups.keys update() # Store Packet Definitions system.telemetry.all.each do |target_name, packets| Store.del("#{@scope}__openc3tlm__#{target_name}") packets.each do |packet_name, packet| Logger.info "Configuring tlm packet: #{target_name} #{packet_name}" begin Store.hset("#{@scope}__openc3tlm__#{target_name}", packet_name, JSON.generate(packet.as_json(:allow_nan => true))) rescue JSON::GeneratorError => err Logger.error("Invalid text present in #{target_name} #{packet_name} tlm packet") raise err end json_hash = Hash.new packet.sorted_items.each do |item| json_hash[item.name] = nil end CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: @scope) end end system.commands.all.each do |target_name, packets| Store.del("#{@scope}__openc3cmd__#{target_name}") packets.each do |packet_name, packet| Logger.info "Configuring cmd packet: #{target_name} #{packet_name}" begin Store.hset("#{@scope}__openc3cmd__#{target_name}", packet_name, JSON.generate(packet.as_json(:allow_nan => true))) rescue JSON::GeneratorError => err Logger.error("Invalid text present in #{target_name} #{packet_name} cmd packet") raise err end end end # Store Limits Groups system.limits.groups.each do |group, items| begin Store.hset("#{@scope}__limits_groups", group, JSON.generate(items)) rescue JSON::GeneratorError => err Logger.error("Invalid text present in #{group} limits group") raise err end end # Merge in Limits Sets sets = Store.hgetall("#{@scope}__limits_sets") sets ||= {} system.limits.sets.each do |set| sets[set.to_s] = "false" unless sets.key?(set.to_s) end Store.hmset("#{@scope}__limits_sets", *sets) # Create item_map item_map_key = "#{@scope}__#{@name}__item_to_packet_map" item_map = self.class.build_item_to_packet_map(@name, scope: @scope) Store.set(item_map_key, JSON.generate(item_map, :allow_nan => true)) @@item_map_cache[@name] = [Time.now, item_map] return system end |