cosmos 5.0.2 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cosmos +183 -42
- data/data/config/microservice.yaml +47 -35
- data/data/config/plugins.yaml +10 -147
- data/data/config/target.yaml +70 -0
- data/data/config/tool.yaml +37 -31
- data/ext/cosmos/ext/cosmos_io/cosmos_io.c +14 -14
- data/ext/cosmos/ext/packet/packet.c +3 -3
- data/ext/cosmos/ext/structure/structure.c +31 -31
- data/lib/cosmos/api/api.rb +1 -25
- data/lib/cosmos/api/cmd_api.rb +17 -6
- data/lib/cosmos/api/config_api.rb +10 -4
- data/lib/cosmos/api/limits_api.rb +1 -1
- data/lib/cosmos/api/settings_api.rb +19 -7
- data/lib/cosmos/api/target_api.rb +2 -2
- data/lib/cosmos/api/tlm_api.rb +65 -41
- data/lib/cosmos/config/config_parser.rb +19 -22
- data/lib/cosmos/config/meta_config_parser.rb +1 -1
- data/lib/cosmos/conversions/generic_conversion.rb +2 -2
- data/lib/cosmos/conversions/polynomial_conversion.rb +5 -8
- data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +26 -9
- data/lib/cosmos/io/json_drb.rb +5 -1
- data/lib/cosmos/logs/log_writer.rb +78 -29
- data/lib/cosmos/microservices/cleanup_microservice.rb +28 -29
- data/lib/cosmos/microservices/decom_microservice.rb +1 -1
- data/lib/cosmos/microservices/interface_microservice.rb +0 -16
- data/lib/cosmos/microservices/microservice.rb +3 -3
- data/lib/cosmos/microservices/reducer_microservice.rb +12 -10
- data/lib/cosmos/models/cvt_model.rb +6 -6
- data/lib/cosmos/models/gem_model.rb +9 -3
- data/lib/cosmos/models/info_model.rb +1 -1
- data/lib/cosmos/models/interface_model.rb +16 -7
- data/lib/cosmos/models/interface_status_model.rb +1 -1
- data/lib/cosmos/models/metadata_model.rb +69 -219
- data/lib/cosmos/models/metric_model.rb +2 -2
- data/lib/cosmos/models/microservice_model.rb +7 -4
- data/lib/cosmos/models/microservice_status_model.rb +1 -1
- data/lib/cosmos/models/model.rb +23 -16
- data/lib/cosmos/models/note_model.rb +122 -0
- data/lib/cosmos/models/ping_model.rb +2 -1
- data/lib/cosmos/models/plugin_model.rb +108 -48
- data/lib/cosmos/models/process_status_model.rb +1 -1
- data/lib/cosmos/models/scope_model.rb +10 -25
- data/lib/cosmos/models/settings_model.rb +55 -0
- data/lib/cosmos/models/sorted_model.rb +167 -0
- data/lib/cosmos/models/target_model.rb +143 -27
- data/lib/cosmos/models/tool_config_model.rb +38 -0
- data/lib/cosmos/models/tool_model.rb +9 -9
- data/lib/cosmos/models/widget_model.rb +11 -11
- data/lib/cosmos/operators/microservice_operator.rb +2 -1
- data/lib/cosmos/packets/packet.rb +24 -1
- data/lib/cosmos/packets/packet_config.rb +2 -2
- data/lib/cosmos/packets/packet_item.rb +57 -0
- data/lib/cosmos/packets/packet_item_limits.rb +14 -2
- data/lib/cosmos/packets/parsers/packet_item_parser.rb +1 -1
- data/lib/cosmos/packets/parsers/packet_parser.rb +1 -1
- data/lib/cosmos/packets/parsers/xtce_parser.rb +1 -1
- data/lib/cosmos/packets/structure.rb +30 -33
- data/lib/cosmos/packets/structure_item.rb +10 -1
- data/lib/cosmos/script/api_shared.rb +30 -25
- data/lib/cosmos/script/calendar.rb +37 -15
- data/lib/cosmos/script/commands.rb +5 -7
- data/lib/cosmos/script/script.rb +19 -39
- data/lib/cosmos/script/storage.rb +92 -105
- data/lib/cosmos/system/system.rb +2 -1
- data/lib/cosmos/tools/table_manager/table_config.rb +16 -1
- data/lib/cosmos/tools/table_manager/table_item.rb +1 -1
- data/lib/cosmos/tools/table_manager/table_manager_core.rb +213 -309
- data/lib/cosmos/top_level.rb +5 -1
- data/lib/cosmos/topics/autonomic_topic.rb +2 -2
- data/lib/cosmos/topics/calendar_topic.rb +1 -1
- data/lib/cosmos/topics/command_decom_topic.rb +35 -1
- data/lib/cosmos/topics/command_topic.rb +6 -4
- data/lib/cosmos/topics/config_topic.rb +68 -0
- data/lib/cosmos/topics/interface_topic.rb +8 -8
- data/lib/cosmos/topics/limits_event_topic.rb +5 -3
- data/lib/cosmos/topics/notifications_topic.rb +1 -1
- data/lib/cosmos/topics/router_topic.rb +9 -9
- data/lib/cosmos/topics/telemetry_decom_topic.rb +5 -1
- data/lib/cosmos/topics/telemetry_topic.rb +1 -1
- data/lib/cosmos/topics/timeline_topic.rb +1 -1
- data/lib/cosmos/topics/topic.rb +23 -8
- data/lib/cosmos/utilities/logger.rb +4 -3
- data/lib/cosmos/utilities/metric.rb +32 -26
- data/lib/cosmos/utilities/s3.rb +61 -0
- data/lib/cosmos/utilities/s3_file_cache.rb +12 -6
- data/lib/cosmos/utilities/store.rb +1 -0
- data/lib/cosmos/utilities/store_autoload.rb +25 -134
- data/lib/cosmos/version.rb +5 -4
- data/templates/plugin-template/plugin.gemspec +0 -2
- metadata +12 -10
- data/bin/xtce_converter +0 -92
- data/lib/cosmos/models/narrative_model.rb +0 -280
@@ -23,137 +23,124 @@ module Cosmos
|
|
23
23
|
module Script
|
24
24
|
private
|
25
25
|
|
26
|
-
#
|
26
|
+
# Delete a file on a target
|
27
|
+
#
|
28
|
+
# @param [String] Path to a file in a target directory
|
29
|
+
def delete_target_file(path, scope: $cosmos_scope)
|
30
|
+
begin
|
31
|
+
# Only delete from the targets_modified
|
32
|
+
delete_path = "#{scope}/targets_modified/#{path}"
|
33
|
+
endpoint = "/cosmos-api/storage/delete/#{delete_path}"
|
34
|
+
Cosmos::Logger.info "Deleting #{delete_path}"
|
35
|
+
response = $api_server.request('delete', endpoint, query: {bucket: 'config'})
|
36
|
+
if response.nil? || response.code != 200
|
37
|
+
raise "Failed to delete #{delete_path}. Note: #{scope}/targets is read-only."
|
38
|
+
end
|
39
|
+
rescue => error
|
40
|
+
raise "Failed deleting #{path} due to #{error.message}"
|
41
|
+
end
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get a handle to write a target file
|
27
46
|
#
|
28
47
|
# @param path [String] Path to a file in a target directory
|
29
|
-
# @param
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
# @param io_or_string [Io or String] IO object
|
49
|
+
def put_target_file(path, io_or_string, scope: $cosmos_scope)
|
50
|
+
raise "Disallowed path modifier '..' found in #{path}" if path.include?('..')
|
51
|
+
upload_path = "#{scope}/targets_modified/#{path}"
|
52
|
+
endpoint = "/cosmos-api/storage/upload/#{upload_path}"
|
53
|
+
Cosmos::Logger.info "Writing #{upload_path}"
|
54
|
+
result = _get_presigned_request(endpoint)
|
34
55
|
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
endpoint = "/cosmos-api/storage/download/#{scope}/#{part}/#{path}"
|
44
|
-
Cosmos::Logger.info "Reading #{scope}/#{part}/#{path}"
|
45
|
-
if $cosmos_in_cluster
|
46
|
-
response = $api_server.request('get', endpoint, query: {bucket: 'config', internal: true})
|
47
|
-
else
|
48
|
-
response = $api_server.request('get', endpoint, query: {bucket: 'config'})
|
49
|
-
end
|
50
|
-
if response.nil? || response.code != 201
|
51
|
-
Cosmos::Logger.error "Failed Get Presigned URL for #{scope}/#{part}/#{path}"
|
52
|
-
if part == "targets_modified"
|
53
|
-
part = "targets"
|
54
|
-
redo
|
56
|
+
# Try to put the file
|
57
|
+
success = false
|
58
|
+
begin
|
59
|
+
uri = _get_uri(result['url'])
|
60
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
61
|
+
request = Net::HTTP::Put.new(uri, {'Content-Length' => io_or_string.length.to_s})
|
62
|
+
if String === io_or_string
|
63
|
+
request.body = io_or_string
|
55
64
|
else
|
56
|
-
|
65
|
+
request.body_stream = io_or_string
|
66
|
+
end
|
67
|
+
result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
68
|
+
http.request(request)
|
57
69
|
end
|
70
|
+
return result
|
58
71
|
end
|
59
|
-
|
72
|
+
rescue => error
|
73
|
+
raise "Failed to write #{upload_path}"
|
74
|
+
end
|
75
|
+
nil
|
76
|
+
end
|
60
77
|
|
61
|
-
|
78
|
+
# Get a handle to access a target file
|
79
|
+
#
|
80
|
+
# @param path [String] Path to a file in a target directory, e.g. "INST/procedures/test.rb"
|
81
|
+
# @param original [Boolean] Whether to get the original or modified file
|
82
|
+
# @return [File|nil]
|
83
|
+
def get_target_file(path, original: false, scope: $cosmos_scope)
|
84
|
+
part = "targets"
|
85
|
+
part += "_modified" unless original
|
86
|
+
# Loop to allow redo when switching from modified to original
|
87
|
+
loop do
|
62
88
|
begin
|
63
|
-
|
64
|
-
uri = URI.parse("http://cosmos-minio:9000" + result['url'])
|
65
|
-
else
|
66
|
-
uri = URI.parse($api_server.generate_url + result['url'])
|
67
|
-
end
|
68
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
69
|
-
request = Net::HTTP::Get.new uri
|
70
|
-
|
71
|
-
http.request request do |response|
|
72
|
-
response.read_body do |chunk|
|
73
|
-
puts chunk.length
|
74
|
-
file.write chunk
|
75
|
-
end
|
76
|
-
end
|
77
|
-
file.rewind
|
78
|
-
end
|
79
|
-
return file
|
89
|
+
return _get_storage_file("#{part}/#{path}", scope: scope)
|
80
90
|
rescue => error
|
81
|
-
Cosmos::Logger.info("#{scope}/#{part}/#{path} not found")
|
82
91
|
if part == "targets_modified"
|
83
92
|
part = "targets"
|
84
93
|
redo
|
85
94
|
else
|
86
|
-
raise
|
95
|
+
raise error
|
87
96
|
end
|
88
97
|
end
|
89
98
|
break
|
90
99
|
end
|
91
100
|
end
|
92
101
|
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# @param path [String] Path to a file in a target directory
|
96
|
-
# @param io_or_string [Io or String] IO object
|
97
|
-
def put_target_file(path, io_or_string, scope: $cosmos_scope)
|
98
|
-
# Get presigned url
|
99
|
-
part = "targets_modified"
|
100
|
-
begin
|
101
|
-
endpoint = "/cosmos-api/storage/upload/#{scope}/#{part}/#{path}"
|
102
|
-
Cosmos::Logger.info "Writing #{scope}/#{part}/#{path}"
|
103
|
-
if $cosmos_in_cluster
|
104
|
-
response = $api_server.request('get', endpoint, query: {bucket: 'config', internal: true})
|
105
|
-
else
|
106
|
-
response = $api_server.request('get', endpoint, query: {bucket: 'config'})
|
107
|
-
end
|
108
|
-
if response.nil? || response.code != 201
|
109
|
-
Cosmos::Logger.error "Failed Get Presigned URL for #{scope}/#{part}/#{path}"
|
110
|
-
return nil
|
111
|
-
end
|
112
|
-
result = JSON.parse(response.body)
|
102
|
+
# These are helper methods ... should not be used directly
|
113
103
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
130
|
-
http.request(request)
|
131
|
-
end
|
132
|
-
return result
|
104
|
+
def _get_storage_file(path, scope: $cosmos_scope)
|
105
|
+
# Create Tempfile to store data
|
106
|
+
file = Tempfile.new('target', binmode: true)
|
107
|
+
|
108
|
+
endpoint = "/cosmos-api/storage/download/#{scope}/#{path}"
|
109
|
+
Cosmos::Logger.info "Reading #{scope}/#{path}"
|
110
|
+
result = _get_presigned_request(endpoint)
|
111
|
+
|
112
|
+
# Try to get the file
|
113
|
+
uri = _get_uri(result['url'])
|
114
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
115
|
+
request = Net::HTTP::Get.new uri
|
116
|
+
http.request request do |response|
|
117
|
+
response.read_body do |chunk|
|
118
|
+
file.write chunk
|
133
119
|
end
|
134
|
-
rescue => error
|
135
|
-
raise "Failed to write #{scope}/#{part}/#{path}"
|
136
120
|
end
|
121
|
+
file.rewind
|
137
122
|
end
|
138
|
-
|
123
|
+
return file
|
139
124
|
end
|
140
125
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
# Only delete from the targets_modified
|
147
|
-
endpoint = "/cosmos-api/storage/delete/#{scope}/targets_modified/#{path}"
|
148
|
-
Cosmos::Logger.info "Deleting #{scope}/targets_modified/#{path}"
|
149
|
-
response = $api_server.request('delete', endpoint, query: {bucket: 'config'})
|
150
|
-
if response.nil? || response.code != 200
|
151
|
-
raise "Failed to delete #{scope}/targets_modified/#{path}"
|
152
|
-
end
|
153
|
-
rescue => error
|
154
|
-
raise "Failed deleting #{path} due to #{error.message}"
|
126
|
+
def _get_uri(url)
|
127
|
+
if $cosmos_in_cluster
|
128
|
+
uri = URI.parse("http://cosmos-minio:9000" + url)
|
129
|
+
else
|
130
|
+
uri = URI.parse($api_server.generate_url + url)
|
155
131
|
end
|
156
|
-
|
132
|
+
end
|
133
|
+
|
134
|
+
def _get_presigned_request(endpoint)
|
135
|
+
if $cosmos_in_cluster
|
136
|
+
response = $api_server.request('get', endpoint, query: { bucket: 'config', internal: true })
|
137
|
+
else
|
138
|
+
response = $api_server.request('get', endpoint, query: { bucket: 'config' })
|
139
|
+
end
|
140
|
+
if response.nil? || response.code != 201
|
141
|
+
raise "Failed to get presigned URL for #{endpoint}"
|
142
|
+
end
|
143
|
+
JSON.parse(response.body)
|
157
144
|
end
|
158
145
|
end
|
159
146
|
end
|
data/lib/cosmos/system/system.rb
CHANGED
@@ -26,6 +26,7 @@ require 'cosmos/packets/limits'
|
|
26
26
|
require 'cosmos/system/target'
|
27
27
|
require 'cosmos/utilities/s3'
|
28
28
|
require 'cosmos/utilities/zip'
|
29
|
+
require 'cosmos/models/scope_model'
|
29
30
|
require 'thread'
|
30
31
|
require 'fileutils'
|
31
32
|
|
@@ -54,7 +55,7 @@ module Cosmos
|
|
54
55
|
|
55
56
|
# @return [Symbol] The current limits_set of the system returned from Redis
|
56
57
|
def self.limits_set
|
57
|
-
|
58
|
+
ScopeModel.limits_set(scope: $cosmos_scope)
|
58
59
|
end
|
59
60
|
|
60
61
|
def self.setup_targets(target_names, base_dir, scope:)
|
@@ -32,12 +32,19 @@ module Cosmos
|
|
32
32
|
# @return [String] Table configuration filename
|
33
33
|
attr_reader :filename
|
34
34
|
|
35
|
+
def self.process_file(filename)
|
36
|
+
instance = self.new()
|
37
|
+
instance.process_file(filename)
|
38
|
+
instance
|
39
|
+
end
|
40
|
+
|
35
41
|
# Create the table configuration
|
36
42
|
def initialize
|
37
43
|
super
|
38
|
-
|
39
44
|
# Override commands with the Table::TARGET name to store tables
|
40
45
|
@commands[Table::TARGET] = {}
|
46
|
+
@definitions = {}
|
47
|
+
@last_config = [] # Stores array of [filename, contents]
|
41
48
|
end
|
42
49
|
|
43
50
|
# @return [Array<Table>] All tables defined in the configuration file
|
@@ -45,6 +52,11 @@ module Cosmos
|
|
45
52
|
@commands[Table::TARGET]
|
46
53
|
end
|
47
54
|
|
55
|
+
# @return [String] Table definition for the specific table
|
56
|
+
def definition(table_name)
|
57
|
+
@definitions[table_name.upcase]
|
58
|
+
end
|
59
|
+
|
48
60
|
# @return [Array<String>] All the table names
|
49
61
|
def table_names
|
50
62
|
tables.keys
|
@@ -64,6 +76,7 @@ module Cosmos
|
|
64
76
|
# Partial files are included into another file and thus aren't directly processed
|
65
77
|
return if File.basename(filename)[0] == '_' # Partials start with underscore
|
66
78
|
@filename = filename
|
79
|
+
@last_config = [File.basename(filename), File.read(filename)]
|
67
80
|
@converted_type = nil
|
68
81
|
@converted_bit_size = nil
|
69
82
|
@proc_text = ''
|
@@ -111,10 +124,12 @@ module Cosmos
|
|
111
124
|
)
|
112
125
|
end
|
113
126
|
process_file(table_filename)
|
127
|
+
|
114
128
|
when 'TABLE'
|
115
129
|
finish_packet
|
116
130
|
@current_packet =
|
117
131
|
TableParser.parse_table(parser, @commands, @warnings)
|
132
|
+
@definitions[@current_packet.packet_name] = @last_config
|
118
133
|
@current_cmd_or_tlm = COMMAND
|
119
134
|
@default_index = 0
|
120
135
|
|