cosmos 5.0.2 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cosmos +183 -42
  3. data/data/config/microservice.yaml +47 -35
  4. data/data/config/plugins.yaml +10 -147
  5. data/data/config/target.yaml +70 -0
  6. data/data/config/tool.yaml +37 -31
  7. data/ext/cosmos/ext/cosmos_io/cosmos_io.c +14 -14
  8. data/ext/cosmos/ext/packet/packet.c +3 -3
  9. data/ext/cosmos/ext/structure/structure.c +31 -31
  10. data/lib/cosmos/api/api.rb +1 -25
  11. data/lib/cosmos/api/cmd_api.rb +17 -6
  12. data/lib/cosmos/api/config_api.rb +10 -4
  13. data/lib/cosmos/api/limits_api.rb +1 -1
  14. data/lib/cosmos/api/settings_api.rb +19 -7
  15. data/lib/cosmos/api/target_api.rb +2 -2
  16. data/lib/cosmos/api/tlm_api.rb +65 -41
  17. data/lib/cosmos/config/config_parser.rb +19 -22
  18. data/lib/cosmos/config/meta_config_parser.rb +1 -1
  19. data/lib/cosmos/conversions/generic_conversion.rb +2 -2
  20. data/lib/cosmos/conversions/polynomial_conversion.rb +5 -8
  21. data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +26 -9
  22. data/lib/cosmos/io/json_drb.rb +5 -1
  23. data/lib/cosmos/logs/log_writer.rb +78 -29
  24. data/lib/cosmos/microservices/cleanup_microservice.rb +28 -29
  25. data/lib/cosmos/microservices/decom_microservice.rb +1 -1
  26. data/lib/cosmos/microservices/interface_microservice.rb +0 -16
  27. data/lib/cosmos/microservices/microservice.rb +3 -3
  28. data/lib/cosmos/microservices/reducer_microservice.rb +12 -10
  29. data/lib/cosmos/models/cvt_model.rb +6 -6
  30. data/lib/cosmos/models/gem_model.rb +9 -3
  31. data/lib/cosmos/models/info_model.rb +1 -1
  32. data/lib/cosmos/models/interface_model.rb +16 -7
  33. data/lib/cosmos/models/interface_status_model.rb +1 -1
  34. data/lib/cosmos/models/metadata_model.rb +69 -219
  35. data/lib/cosmos/models/metric_model.rb +2 -2
  36. data/lib/cosmos/models/microservice_model.rb +7 -4
  37. data/lib/cosmos/models/microservice_status_model.rb +1 -1
  38. data/lib/cosmos/models/model.rb +23 -16
  39. data/lib/cosmos/models/note_model.rb +122 -0
  40. data/lib/cosmos/models/ping_model.rb +2 -1
  41. data/lib/cosmos/models/plugin_model.rb +108 -48
  42. data/lib/cosmos/models/process_status_model.rb +1 -1
  43. data/lib/cosmos/models/scope_model.rb +10 -25
  44. data/lib/cosmos/models/settings_model.rb +55 -0
  45. data/lib/cosmos/models/sorted_model.rb +167 -0
  46. data/lib/cosmos/models/target_model.rb +143 -27
  47. data/lib/cosmos/models/tool_config_model.rb +38 -0
  48. data/lib/cosmos/models/tool_model.rb +9 -9
  49. data/lib/cosmos/models/widget_model.rb +11 -11
  50. data/lib/cosmos/operators/microservice_operator.rb +2 -1
  51. data/lib/cosmos/packets/packet.rb +24 -1
  52. data/lib/cosmos/packets/packet_config.rb +2 -2
  53. data/lib/cosmos/packets/packet_item.rb +57 -0
  54. data/lib/cosmos/packets/packet_item_limits.rb +14 -2
  55. data/lib/cosmos/packets/parsers/packet_item_parser.rb +1 -1
  56. data/lib/cosmos/packets/parsers/packet_parser.rb +1 -1
  57. data/lib/cosmos/packets/parsers/xtce_parser.rb +1 -1
  58. data/lib/cosmos/packets/structure.rb +30 -33
  59. data/lib/cosmos/packets/structure_item.rb +10 -1
  60. data/lib/cosmos/script/api_shared.rb +30 -25
  61. data/lib/cosmos/script/calendar.rb +37 -15
  62. data/lib/cosmos/script/commands.rb +5 -7
  63. data/lib/cosmos/script/script.rb +19 -39
  64. data/lib/cosmos/script/storage.rb +92 -105
  65. data/lib/cosmos/system/system.rb +2 -1
  66. data/lib/cosmos/tools/table_manager/table_config.rb +16 -1
  67. data/lib/cosmos/tools/table_manager/table_item.rb +1 -1
  68. data/lib/cosmos/tools/table_manager/table_manager_core.rb +213 -309
  69. data/lib/cosmos/top_level.rb +5 -1
  70. data/lib/cosmos/topics/autonomic_topic.rb +2 -2
  71. data/lib/cosmos/topics/calendar_topic.rb +1 -1
  72. data/lib/cosmos/topics/command_decom_topic.rb +35 -1
  73. data/lib/cosmos/topics/command_topic.rb +6 -4
  74. data/lib/cosmos/topics/config_topic.rb +68 -0
  75. data/lib/cosmos/topics/interface_topic.rb +8 -8
  76. data/lib/cosmos/topics/limits_event_topic.rb +5 -3
  77. data/lib/cosmos/topics/notifications_topic.rb +1 -1
  78. data/lib/cosmos/topics/router_topic.rb +9 -9
  79. data/lib/cosmos/topics/telemetry_decom_topic.rb +5 -1
  80. data/lib/cosmos/topics/telemetry_topic.rb +1 -1
  81. data/lib/cosmos/topics/timeline_topic.rb +1 -1
  82. data/lib/cosmos/topics/topic.rb +23 -8
  83. data/lib/cosmos/utilities/logger.rb +4 -3
  84. data/lib/cosmos/utilities/metric.rb +32 -26
  85. data/lib/cosmos/utilities/s3.rb +61 -0
  86. data/lib/cosmos/utilities/s3_file_cache.rb +12 -6
  87. data/lib/cosmos/utilities/store.rb +1 -0
  88. data/lib/cosmos/utilities/store_autoload.rb +25 -134
  89. data/lib/cosmos/version.rb +5 -4
  90. data/templates/plugin-template/plugin.gemspec +0 -2
  91. metadata +12 -10
  92. data/bin/xtce_converter +0 -92
  93. 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
- # Get a handle to access a target file
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 original [Boolean] Whether to get the original or modified file
30
- # @return [File|nil]
31
- def get_target_file(path, original: false, scope: $cosmos_scope)
32
- # Create Tempfile to store data
33
- file = Tempfile.new('target', binmode: true)
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
- # Get presigned url
36
- if original
37
- part = "targets"
38
- else
39
- part = "targets_modified"
40
- end
41
- # Loop to allow redo
42
- loop do
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
- raise "#{path} not found"
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
- result = JSON.parse(response.body)
72
+ rescue => error
73
+ raise "Failed to write #{upload_path}"
74
+ end
75
+ nil
76
+ end
60
77
 
61
- # Try to get the file
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
- if $cosmos_in_cluster
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 "#{path} not found"
95
+ raise error
87
96
  end
88
97
  end
89
98
  break
90
99
  end
91
100
  end
92
101
 
93
- # Get a handle to write a target file
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
- # Try to put the file
115
- success = false
116
- begin
117
- if $cosmos_in_cluster
118
- uri = URI.parse("http://cosmos-minio:9000" + result['url'])
119
- else
120
- uri = URI.parse($api_server.generate_url + result['url'])
121
- end
122
- Net::HTTP.start(uri.host, uri.port) do |http|
123
- request = Net::HTTP::Put.new(uri, {'Content-Length' => io_or_string.length.to_s})
124
- if String === io_or_string
125
- request.body = io_or_string
126
- else
127
- request.body_stream = io_or_string
128
- end
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
- nil
123
+ return file
139
124
  end
140
125
 
141
- # Delete a file on a target
142
- #
143
- # @param [String] Path to a file in a target directory
144
- def delete_target_file(path, scope: $cosmos_scope)
145
- begin
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
- nil
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
@@ -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
- Store.hget("#{$cosmos_scope}__cosmos_system", 'limits_set').intern
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
 
@@ -80,7 +80,7 @@ module Cosmos
80
80
  alias dup clone
81
81
 
82
82
  # Create a hash of this item's attributes
83
- def to_hash
83
+ def as_json
84
84
  hash = super()
85
85
  hash['editable'] = self.editable
86
86
  hash['hidden'] = self.hidden