Class: Cosmos::System
- Defined in:
- lib/cosmos/system/system.rb,
ext/cosmos/ext/telemetry/telemetry.c
Constant Summary collapse
- @@instance =
Variable that holds the singleton instance
nil
- @@instance_mutex =
Mutex used to ensure that only one instance of System is created
Mutex.new
Class Method Summary collapse
-
.instance(target_names = nil, target_config_dir = nil) ⇒ System
Get the singleton instance of System.
-
.limits_set ⇒ Symbol
The current limits_set of the system returned from Redis.
- .setup_targets(target_names, base_dir, scope:) ⇒ Object
Instance Method Summary collapse
- #add_target(target_name, target_config_dir) ⇒ Object
-
#commands ⇒ Commands
Access to the command definition.
-
#initialize(target_names, target_config_dir) ⇒ System
constructor
Create a new System object.
-
#limits ⇒ Limits
Access to the limits definition.
-
#packet_config ⇒ PacketConfig
Access to the packet configuration.
-
#targets ⇒ Hash<String,Target>
Hash of all the known targets.
-
#telemetry ⇒ Telemetry
Access to the telemetry definition.
Constructor Details
#initialize(target_names, target_config_dir) ⇒ System
Create a new System object.
102 103 104 105 106 107 108 109 |
# File 'lib/cosmos/system/system.rb', line 102 def initialize(target_names, target_config_dir) @targets = {} @packet_config = PacketConfig.new @commands = Commands.new(@packet_config) @telemetry = Telemetry.new(@packet_config) @limits = Limits.new(@packet_config) target_names.each { |target_name| add_target(target_name, target_config_dir) } end |
Class Method Details
.instance(target_names = nil, target_config_dir = nil) ⇒ System
Get the singleton instance of System
88 89 90 91 92 93 94 95 96 |
# File 'lib/cosmos/system/system.rb', line 88 def self.instance(target_names = nil, target_config_dir = nil) return @@instance if @@instance raise "System.instance parameters are required on first call" unless target_names and target_config_dir @@instance_mutex.synchronize do @@instance ||= self.new(target_names, target_config_dir) return @@instance end end |
.limits_set ⇒ Symbol
Returns The current limits_set of the system returned from Redis.
56 57 58 |
# File 'lib/cosmos/system/system.rb', line 56 def self.limits_set Store.hget("#{$cosmos_scope}__cosmos_system", 'limits_set').intern end |
.setup_targets(target_names, base_dir, scope:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cosmos/system/system.rb', line 60 def self.setup_targets(target_names, base_dir, scope:) FileUtils.mkdir_p("#{base_dir}/targets") rubys3_client = Aws::S3::Client.new target_names.each do |target_name| # Retrieve bucket/targets/target_name/target_id.zip response_target = "#{base_dir}/targets/#{target_name}_current.zip" FileUtils.mkdir_p(File.dirname(response_target)) s3_key = "#{scope}/target_archives/#{target_name}/#{target_name}_current.zip" Logger.info("Retrieving #{s3_key} from targets bucket") rubys3_client.get_object(bucket: "config", key: s3_key, response_target: response_target) Zip::File.open(response_target) do |zip_file| zip_file.each do |entry| path = File.join("#{base_dir}/targets", entry.name) FileUtils.mkdir_p(File.dirname(path)) zip_file.extract(entry, path) unless File.exist?(path) end end end # Build System from targets System.instance(target_names, "#{base_dir}/targets") end |
Instance Method Details
#add_target(target_name, target_config_dir) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cosmos/system/system.rb', line 111 def add_target(target_name, target_config_dir) parser = ConfigParser.new folder_name = File.join(target_config_dir, target_name) raise parser.error("Target folder must exist '#{folder_name}'.") unless Dir.exist?(folder_name) target = Target.new(target_name, target_config_dir) @targets[target.name] = target target.cmd_tlm_files.each do |cmd_tlm_file| @packet_config.process_file(cmd_tlm_file, target.name) rescue Exception => err Logger.error "Problem processing #{cmd_tlm_file}: #{err}." raise err end end |
#commands ⇒ Commands
Returns Access to the command definition.
41 |
# File 'lib/cosmos/system/system.rb', line 41 instance_attr_reader :commands |
#limits ⇒ Limits
Returns Access to the limits definition.
47 |
# File 'lib/cosmos/system/system.rb', line 47 instance_attr_reader :limits |
#packet_config ⇒ PacketConfig
Returns Access to the packet configuration.
38 |
# File 'lib/cosmos/system/system.rb', line 38 instance_attr_reader :packet_config |
#targets ⇒ Hash<String,Target>
Returns Hash of all the known targets.
35 |
# File 'lib/cosmos/system/system.rb', line 35 instance_attr_reader :targets |
#telemetry ⇒ Telemetry
Returns Access to the telemetry definition.
44 |
# File 'lib/cosmos/system/system.rb', line 44 instance_attr_reader :telemetry |