openc3 7.5.1 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/bin/openc3cli +82 -5
- data/data/config/_params.yaml +3 -0
- data/data/config/command_modifiers.yaml +5 -3
- data/data/config/default_plugins.yaml +1 -0
- data/data/config/interface_modifiers.yaml +17 -1
- data/data/config/item_modifiers.yaml +24 -1
- data/data/config/microservice.yaml +15 -1
- data/data/config/parameter_modifiers.yaml +4 -4
- data/data/config/plugins.yaml +511 -3
- data/data/config/settings.yaml +17 -0
- data/data/config/target.yaml +53 -0
- data/data/config/telemetry.yaml +58 -2
- data/data/config/widgets.yaml +30 -0
- data/lib/openc3/accessors/accessor.rb +14 -2
- data/lib/openc3/accessors/binary_accessor.rb +25 -5
- data/lib/openc3/api/CLAUDE.md +1 -0
- data/lib/openc3/api/api.rb +1 -0
- data/lib/openc3/api/cmd_api.rb +9 -1
- data/lib/openc3/api/interface_api.rb +7 -2
- data/lib/openc3/api/limits_api.rb +93 -41
- data/lib/openc3/api/router_api.rb +7 -2
- data/lib/openc3/api/settings_api.rb +4 -1
- data/lib/openc3/api/shared_resource_api.rb +107 -0
- data/lib/openc3/api/tlm_api.rb +10 -0
- data/lib/openc3/interfaces/http_client_interface.rb +84 -27
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
- data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
- data/lib/openc3/io/json_api.rb +2 -10
- data/lib/openc3/io/json_api_object.rb +2 -10
- data/lib/openc3/logs/packet_log_writer.rb +8 -3
- data/lib/openc3/microservices/decom_common.rb +4 -1
- data/lib/openc3/microservices/decom_microservice.rb +52 -6
- data/lib/openc3/microservices/interface_decom_common.rb +13 -0
- data/lib/openc3/microservices/interface_microservice.rb +50 -11
- data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
- data/lib/openc3/microservices/log_microservice.rb +22 -8
- data/lib/openc3/microservices/microservice.rb +8 -2
- data/lib/openc3/microservices/multi_microservice.rb +76 -22
- data/lib/openc3/microservices/queue_microservice.rb +29 -24
- data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
- data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
- data/lib/openc3/models/bridge_model.rb +3 -3
- data/lib/openc3/models/cvt_model.rb +3 -1
- data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
- data/lib/openc3/models/interface_model.rb +27 -7
- data/lib/openc3/models/microservice_group.rb +167 -0
- data/lib/openc3/models/microservice_model.rb +88 -2
- data/lib/openc3/models/panel_model.rb +109 -0
- data/lib/openc3/models/plugin_model.rb +1006 -26
- data/lib/openc3/models/plugin_store_model.rb +6 -1
- data/lib/openc3/models/protected_storage_model.rb +64 -0
- data/lib/openc3/models/queue_model.rb +19 -10
- data/lib/openc3/models/scope_model.rb +80 -3
- data/lib/openc3/models/setting_model.rb +2 -2
- data/lib/openc3/models/shared_resource_model.rb +381 -0
- data/lib/openc3/models/target_model.rb +324 -68
- data/lib/openc3/operators/microservice_operator.rb +76 -9
- data/lib/openc3/operators/operator.rb +29 -0
- data/lib/openc3/packets/commands.rb +16 -16
- data/lib/openc3/packets/limits.rb +2 -0
- data/lib/openc3/packets/packet.rb +75 -4
- data/lib/openc3/packets/packet_config.rb +152 -13
- data/lib/openc3/packets/packet_item.rb +35 -14
- data/lib/openc3/packets/packet_item_limits.rb +67 -6
- data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
- data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
- data/lib/openc3/packets/parsers/state_parser.rb +1 -1
- data/lib/openc3/script/CLAUDE.md +1 -0
- data/lib/openc3/script/api_shared.rb +17 -9
- data/lib/openc3/script/calendar.rb +18 -6
- data/lib/openc3/script/commands.rb +11 -9
- data/lib/openc3/script/critical_cmd.rb +22 -2
- data/lib/openc3/script/metadata.rb +30 -4
- data/lib/openc3/script/plugins.rb +8 -0
- data/lib/openc3/script/script.rb +8 -24
- data/lib/openc3/script/web_socket_api.rb +23 -17
- data/lib/openc3/system/system.rb +9 -3
- data/lib/openc3/top_level.rb +17 -0
- data/lib/openc3/topics/command_topic.rb +7 -1
- data/lib/openc3/topics/decom_interface_topic.rb +9 -3
- data/lib/openc3/topics/discovery_topic.rb +84 -0
- data/lib/openc3/topics/limits_event_topic.rb +236 -17
- data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
- data/lib/openc3/topics/topic.rb +2 -1
- data/lib/openc3/utilities/authentication.rb +67 -16
- data/lib/openc3/utilities/cli_generator.rb +117 -25
- data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
- data/lib/openc3/utilities/config_overlay.rb +24 -1
- data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
- data/lib/openc3/utilities/hardware_discovery.rb +279 -0
- data/lib/openc3/utilities/limits_rollup.rb +81 -0
- data/lib/openc3/utilities/local_mode.rb +48 -5
- data/lib/openc3/utilities/questdb_client.rb +130 -22
- data/lib/openc3/utilities/reingest_job.rb +12 -3
- data/lib/openc3/utilities/running_script.rb +206 -49
- data/lib/openc3/utilities/script.rb +24 -12
- data/lib/openc3/utilities/script_env.rb +164 -0
- data/lib/openc3/utilities/script_message_signing.rb +133 -0
- data/lib/openc3/utilities/store_autoload.rb +32 -1
- data/lib/openc3/utilities/store_queued.rb +5 -1
- data/lib/openc3/version.rb +6 -6
- data/templates/command_validator/command_validator.py +9 -9
- data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
- data/templates/panel/Rakefile +24 -0
- data/templates/panel/package.json +17 -0
- data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
- data/templates/panel/src/Panel.js +52 -0
- data/templates/panel/src/Panel.vue +60 -0
- data/templates/panel/src/panelSdk.js +24 -0
- data/templates/panel/vite-Panel.config.js +43 -0
- data/templates/tool_vue/package.json +3 -3
- data/templates/widget/package.json +2 -2
- metadata +24 -56
- data/templates/tool_angular/.editorconfig +0 -16
- data/templates/tool_angular/.gitignore +0 -44
- data/templates/tool_angular/.vscode/extensions.json +0 -4
- data/templates/tool_angular/.vscode/launch.json +0 -20
- data/templates/tool_angular/.vscode/tasks.json +0 -42
- data/templates/tool_angular/angular.json +0 -111
- data/templates/tool_angular/extra-webpack.config.js +0 -8
- data/templates/tool_angular/package.json +0 -48
- data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
- data/templates/tool_angular/src/app/app.component.html +0 -22
- data/templates/tool_angular/src/app/app.component.scss +0 -18
- data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
- data/templates/tool_angular/src/app/app.component.ts +0 -52
- data/templates/tool_angular/src/app/app.module.ts +0 -30
- data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
- data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
- data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
- data/templates/tool_angular/src/assets/.gitkeep +0 -0
- data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
- data/templates/tool_angular/src/environments/environment.ts +0 -16
- data/templates/tool_angular/src/favicon.ico +0 -0
- data/templates/tool_angular/src/index.html +0 -13
- data/templates/tool_angular/src/main.single-spa.ts +0 -40
- data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
- data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
- data/templates/tool_angular/src/styles.scss +0 -1
- data/templates/tool_angular/tsconfig.app.json +0 -13
- data/templates/tool_angular/tsconfig.json +0 -33
- data/templates/tool_angular/tsconfig.spec.json +0 -14
- data/templates/tool_react/.eslintrc +0 -7
- data/templates/tool_react/.gitignore +0 -71
- data/templates/tool_react/.prettierignore +0 -8
- data/templates/tool_react/babel.config.json +0 -29
- data/templates/tool_react/jest.config.js +0 -12
- data/templates/tool_react/package.json +0 -51
- data/templates/tool_react/src/openc3-tool_name.js +0 -24
- data/templates/tool_react/src/root.component.js +0 -88
- data/templates/tool_react/src/root.component.test.js +0 -9
- data/templates/tool_react/webpack.config.js +0 -27
- data/templates/tool_svelte/.gitignore +0 -71
- data/templates/tool_svelte/.prettierignore +0 -8
- data/templates/tool_svelte/.prettierrc.js +0 -5
- data/templates/tool_svelte/babel.config.js +0 -12
- data/templates/tool_svelte/build/smui.css +0 -1
- data/templates/tool_svelte/jest.config.js +0 -9
- data/templates/tool_svelte/package.json +0 -49
- data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
- data/templates/tool_svelte/rollup.config.js +0 -74
- data/templates/tool_svelte/src/App.svelte +0 -42
- data/templates/tool_svelte/src/App.test.js +0 -9
- data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
- data/templates/tool_svelte/src/tool_name.js +0 -17
- data/templates/widget/LICENSE.md +0 -20
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 OpenC3, Inc.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU Affero General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU Affero General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# This file may also be used under the terms of a commercial license
|
|
17
|
+
# if purchased from OpenC3, Inc.
|
|
18
|
+
|
|
19
|
+
require 'securerandom'
|
|
20
|
+
require 'openc3/models/microservice_model'
|
|
21
|
+
require 'openc3/utilities/store'
|
|
22
|
+
|
|
23
|
+
module OpenC3
|
|
24
|
+
# Targets that declare MICROSERVICE_GROUP <NAME> keep their own target
|
|
25
|
+
# microservices (DECOM, COMMANDLOG, PACKETLOG, CLEANUP, TSDB) but run them as
|
|
26
|
+
# threads in two shared processes instead of one or more processes per target:
|
|
27
|
+
#
|
|
28
|
+
# - SCOPE__MULTIGROUP__<NAME> runs the Ruby microservices (multi_microservice.rb)
|
|
29
|
+
# - SCOPE__PYMULTIGROUP__<NAME> runs the Python microservices, TSDB and the
|
|
30
|
+
# decom of Python targets (multi_microservice.py)
|
|
31
|
+
#
|
|
32
|
+
# A target microservice joins a group by naming one of these as its parent.
|
|
33
|
+
# The parents find their children by that when they start, and the operator
|
|
34
|
+
# restarts a parent when a child is added, changed, or removed, so the parents
|
|
35
|
+
# themselves only change when they are first needed or no longer needed.
|
|
36
|
+
class MicroserviceGroup
|
|
37
|
+
RUBY_TYPE = 'MULTIGROUP'
|
|
38
|
+
PYTHON_TYPE = 'PYMULTIGROUP'
|
|
39
|
+
TYPES = [RUBY_TYPE, PYTHON_TYPE]
|
|
40
|
+
|
|
41
|
+
LOCK_TIMEOUT_SECONDS = 60
|
|
42
|
+
LOCK_EXPIRE_SECONDS = 120
|
|
43
|
+
# The parent settings that come from the children (see build_model). The
|
|
44
|
+
# rest, such as enabled, keep what was set on the parent.
|
|
45
|
+
MANAGED_KEYS = %w(cmd work_dir plugin needs_dependencies shard db_shard)
|
|
46
|
+
|
|
47
|
+
def self.microservice_name(type, group, scope:)
|
|
48
|
+
"#{scope}__#{type}__#{group}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Boolean] Whether name is a group's parent microservice
|
|
52
|
+
def self.parent?(name)
|
|
53
|
+
TYPES.include?(name.to_s.split('__')[1])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @return [Array<Hash>] TargetModel JSON of the other members of the group
|
|
57
|
+
def self.members(group, scope:, exclude: nil)
|
|
58
|
+
TargetModel.all(scope: scope).values.select do |target|
|
|
59
|
+
target['microservice_group'] == group and target['name'] != exclude
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Raise if the target can't join its group. Called before anything is
|
|
64
|
+
# written so a failed install leaves the group as it was, and again under
|
|
65
|
+
# the group lock right before the target is saved (see TargetModel#deploy)
|
|
66
|
+
# so that two targets installed at once can't both join.
|
|
67
|
+
# @param target [TargetModel] Target being deployed
|
|
68
|
+
def self.validate_member(target)
|
|
69
|
+
group = target.microservice_group
|
|
70
|
+
unless target.target_microservices.empty?
|
|
71
|
+
raise "Target #{target.name} cannot use both MICROSERVICE_GROUP and TARGET_MICROSERVICE"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
members(group, scope: target.scope, exclude: target.name).each do |member|
|
|
75
|
+
if member['db_shard'].to_i != target.db_shard
|
|
76
|
+
raise "Target #{target.name} has DB_SHARD #{target.db_shard} but microservice group #{group} uses DB_SHARD #{member['db_shard'].to_i} (target #{member['name']})"
|
|
77
|
+
end
|
|
78
|
+
if member['shard'].to_i != target.shard
|
|
79
|
+
raise "Target #{target.name} has SHARD #{target.shard} but microservice group #{group} uses SHARD #{member['shard'].to_i} (target #{member['name']})"
|
|
80
|
+
end
|
|
81
|
+
# The Python process can only use one plugin's Python packages
|
|
82
|
+
if target.language == 'python' and member['language'] == 'python' and member['plugin'] != target.plugin
|
|
83
|
+
raise "Target #{target.name} uses Python decom but microservice group #{group} already has Python decom target #{member['name']} from another plugin (#{member['plugin']})"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Create, update, or remove the group's parent microservices so that each
|
|
89
|
+
# one exists only while it has children. Called after a member's
|
|
90
|
+
# microservices are deployed or removed.
|
|
91
|
+
def self.update(group, scope:)
|
|
92
|
+
with_lock(group, scope: scope) do
|
|
93
|
+
microservices = MicroserviceModel.all(scope: scope)
|
|
94
|
+
TYPES.each do |type|
|
|
95
|
+
name = microservice_name(type, group, scope: scope)
|
|
96
|
+
children = microservices.values.select { |config| config['parent'] == name }.sort_by { |config| config['name'] }
|
|
97
|
+
existing = microservices[name]
|
|
98
|
+
if children.empty?
|
|
99
|
+
if existing
|
|
100
|
+
MicroserviceModel.get_model(name: name, scope: scope)&.destroy
|
|
101
|
+
Logger.info "Removed microservice #{name} for microservice group #{group}"
|
|
102
|
+
end
|
|
103
|
+
next
|
|
104
|
+
end
|
|
105
|
+
model = build_model(type, name, children, scope: scope)
|
|
106
|
+
if existing
|
|
107
|
+
desired = existing.merge(model.as_json.slice(*MANAGED_KEYS))
|
|
108
|
+
next if same_config?(existing, desired)
|
|
109
|
+
|
|
110
|
+
MicroserviceModel.from_json(desired, scope: scope).update
|
|
111
|
+
Logger.info "Updated microservice #{name} for microservice group #{group}"
|
|
112
|
+
else
|
|
113
|
+
model.create
|
|
114
|
+
Logger.info "Configured microservice #{name} for microservice group #{group}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# The parent takes its settings from its children. They all have the same
|
|
121
|
+
# shard and db_shard (see validate_member).
|
|
122
|
+
def self.build_model(type, name, children, scope:)
|
|
123
|
+
needs_dependencies = children.any? { |child| child['needs_dependencies'] }
|
|
124
|
+
if type == RUBY_TYPE
|
|
125
|
+
cmd = ['ruby', 'multi_microservice.rb']
|
|
126
|
+
work_dir = '/openc3/lib/openc3/microservices'
|
|
127
|
+
plugin = nil
|
|
128
|
+
else
|
|
129
|
+
cmd = [ENV['OPENC3_PYTHON_BIN'] || '/openc3/python/.venv/bin/python', 'multi_microservice.py']
|
|
130
|
+
work_dir = '/openc3/python/openc3/microservices'
|
|
131
|
+
# The operator picks the Python virtual environment by plugin, so use
|
|
132
|
+
# the plugin of the Python decom targets (all one plugin, see
|
|
133
|
+
# validate_member). Other parents have no plugin so that removing one
|
|
134
|
+
# member's plugin doesn't remove the parent of the other members.
|
|
135
|
+
plugin = children.find { |child| child['cmd'].include?('decom_microservice.py') }&.dig('plugin')
|
|
136
|
+
end
|
|
137
|
+
MicroserviceModel.new(name: name, cmd: cmd, work_dir: work_dir, plugin: plugin,
|
|
138
|
+
needs_dependencies: needs_dependencies, shard: children[0]['shard'].to_i,
|
|
139
|
+
db_shard: children[0]['db_shard'].to_i, scope: scope)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Ignore updated_at which changes on every write
|
|
143
|
+
def self.same_config?(existing, desired)
|
|
144
|
+
strip = ->(config) { JSON.parse(JSON.generate(config, allow_nan: true), allow_nan: true).reject { |key, _| key == 'updated_at' } }
|
|
145
|
+
strip.call(existing) == strip.call(desired)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Serialize updates of one group. Concurrent plugin installs would otherwise
|
|
149
|
+
# each read, modify, and write the same parent models.
|
|
150
|
+
def self.with_lock(group, scope:)
|
|
151
|
+
key = "#{scope}__microservice_group_lock__#{group}"
|
|
152
|
+
token = SecureRandom.uuid
|
|
153
|
+
deadline = Time.now + LOCK_TIMEOUT_SECONDS
|
|
154
|
+
until Store.set(key, token, nx: true, ex: LOCK_EXPIRE_SECONDS)
|
|
155
|
+
raise "Timeout waiting for microservice group #{group} lock" if Time.now > deadline
|
|
156
|
+
|
|
157
|
+
sleep 0.1
|
|
158
|
+
end
|
|
159
|
+
begin
|
|
160
|
+
yield
|
|
161
|
+
ensure
|
|
162
|
+
# Only release the lock if it's still ours (it may have expired)
|
|
163
|
+
Store.del(key) if Store.get(key) == token
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -19,6 +19,7 @@ require 'openc3/top_level'
|
|
|
19
19
|
require 'openc3/models/model'
|
|
20
20
|
require 'openc3/models/config_keyword_model'
|
|
21
21
|
require 'openc3/models/metric_model'
|
|
22
|
+
require 'openc3/models/shared_resource_model'
|
|
22
23
|
require 'openc3/topics/config_topic'
|
|
23
24
|
require 'openc3/utilities/bucket'
|
|
24
25
|
require 'openc3/utilities/python_venv'
|
|
@@ -29,6 +30,34 @@ module OpenC3
|
|
|
29
30
|
|
|
30
31
|
PRIMARY_KEY = 'openc3_microservices'
|
|
31
32
|
|
|
33
|
+
# A ROUTE_PREFIX becomes a traefik rule on the COSMOS web port. Limit it to
|
|
34
|
+
# plain path segments so it is always a valid traefik rule, and keep it off the
|
|
35
|
+
# paths used by the built in traefik routers and the COSMOS front end.
|
|
36
|
+
ROUTE_PREFIX_REGEX = /\A(\/[A-Za-z0-9_\-]+)+\z/
|
|
37
|
+
# First path segments a ROUTE_PREFIX may not use (compared case-insensitively).
|
|
38
|
+
# Includes the Enterprise routes (auth, metrics, grafana, mcp) and the
|
|
39
|
+
# directories served from tools/base (js, css, fonts, icons, img, assets).
|
|
40
|
+
RESERVED_ROUTE_PREFIXES = %w(openc3-api script-api tools files login js css fonts icons img assets auth metrics grafana mcp)
|
|
41
|
+
|
|
42
|
+
# Validate a ROUTE_PREFIX and return it with a leading and no trailing slash
|
|
43
|
+
# @param prefix [String] Route prefix, e.g. '/mymicroservice' or 'mymicroservice'
|
|
44
|
+
# @return [String] Normalized prefix, e.g. '/mymicroservice'
|
|
45
|
+
def self.validate_route_prefix(prefix)
|
|
46
|
+
normalized = prefix.to_s.strip
|
|
47
|
+
normalized = "/#{normalized}" unless normalized.start_with?('/')
|
|
48
|
+
normalized = normalized.chomp('/')
|
|
49
|
+
unless ROUTE_PREFIX_REGEX.match?(normalized)
|
|
50
|
+
raise "Invalid ROUTE_PREFIX '#{prefix}': must be one or more path segments containing only letters, numbers, '_' or '-' (e.g. /mymicroservice)"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
first_segment = normalized.split('/')[1].downcase
|
|
54
|
+
if RESERVED_ROUTE_PREFIXES.include?(first_segment)
|
|
55
|
+
raise "Invalid ROUTE_PREFIX '#{prefix}': '/#{first_segment}' is reserved by COSMOS"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
normalized
|
|
59
|
+
end
|
|
60
|
+
|
|
32
61
|
attr_accessor :cmd
|
|
33
62
|
attr_accessor :container
|
|
34
63
|
attr_accessor :env
|
|
@@ -47,6 +76,7 @@ module OpenC3
|
|
|
47
76
|
attr_accessor :shard
|
|
48
77
|
attr_accessor :db_shard
|
|
49
78
|
attr_accessor :enabled
|
|
79
|
+
attr_accessor :shared_resource
|
|
50
80
|
|
|
51
81
|
# NOTE: The following three class methods are used by the ModelController
|
|
52
82
|
# and are reimplemented to enable various Model class methods to work
|
|
@@ -111,6 +141,7 @@ module OpenC3
|
|
|
111
141
|
shard: 0,
|
|
112
142
|
db_shard: 0,
|
|
113
143
|
enabled: true,
|
|
144
|
+
shared_resource: nil,
|
|
114
145
|
scope:
|
|
115
146
|
)
|
|
116
147
|
parts = name.split("__")
|
|
@@ -141,6 +172,7 @@ module OpenC3
|
|
|
141
172
|
@db_shard = db_shard.to_i # to_i to handle nil
|
|
142
173
|
@enabled = enabled
|
|
143
174
|
@enabled = true if @enabled.nil?
|
|
175
|
+
@shared_resource = shared_resource
|
|
144
176
|
@bucket = Bucket.getClient()
|
|
145
177
|
end
|
|
146
178
|
|
|
@@ -187,6 +219,7 @@ module OpenC3
|
|
|
187
219
|
'shard' => @shard,
|
|
188
220
|
'db_shard' => @db_shard,
|
|
189
221
|
'enabled' => @enabled,
|
|
222
|
+
'shared_resource' => @shared_resource,
|
|
190
223
|
}
|
|
191
224
|
end
|
|
192
225
|
|
|
@@ -237,8 +270,13 @@ module OpenC3
|
|
|
237
270
|
@secrets << parameters[0..2]
|
|
238
271
|
end
|
|
239
272
|
when 'ROUTE_PREFIX'
|
|
240
|
-
|
|
241
|
-
|
|
273
|
+
usage = "#{keyword} <Route Prefix>"
|
|
274
|
+
parser.verify_num_parameters(1, 1, usage)
|
|
275
|
+
begin
|
|
276
|
+
@prefix = MicroserviceModel.validate_route_prefix(parameters[0])
|
|
277
|
+
rescue RuntimeError => error
|
|
278
|
+
raise ConfigParser::Error.new(parser, error.message, usage)
|
|
279
|
+
end
|
|
242
280
|
when 'DISABLE_ERB'
|
|
243
281
|
# 0 to unlimited parameters
|
|
244
282
|
@disable_erb ||= []
|
|
@@ -254,12 +292,53 @@ module OpenC3
|
|
|
254
292
|
when 'STOPPED'
|
|
255
293
|
parser.verify_num_parameters(0, 0, "#{keyword}")
|
|
256
294
|
@enabled = false
|
|
295
|
+
when 'SHARED_RESOURCE'
|
|
296
|
+
parser.verify_num_parameters(1, 1, "#{keyword} <Shared Resource Name>")
|
|
297
|
+
begin
|
|
298
|
+
@shared_resource = SharedResourceModel.validate_name(parameters[0])
|
|
299
|
+
rescue => e
|
|
300
|
+
raise parser.error(e.message)
|
|
301
|
+
end
|
|
257
302
|
else
|
|
258
303
|
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Microservice: #{keyword} #{parameters.join(" ")}")
|
|
259
304
|
end
|
|
260
305
|
return nil
|
|
261
306
|
end
|
|
262
307
|
|
|
308
|
+
# Validate the route prefix on every write, including microservices created
|
|
309
|
+
# directly through the API rather than from a plugin.txt. An update that keeps
|
|
310
|
+
# the stored prefix is allowed, so a microservice stored before prefixes were
|
|
311
|
+
# validated can still be started and stopped (#traefik doesn't route it).
|
|
312
|
+
#
|
|
313
|
+
# Join the shared resource before the operator can see the microservice so
|
|
314
|
+
# it is never started in a scope where the resource isn't active.
|
|
315
|
+
def create(update: false, force: false, queued: false)
|
|
316
|
+
if @prefix
|
|
317
|
+
existing = self.class.get(name: @name) if update
|
|
318
|
+
unless existing and existing['prefix'] == @prefix
|
|
319
|
+
@prefix = self.class.validate_route_prefix(@prefix)
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
added = false
|
|
323
|
+
if @shared_resource and not update
|
|
324
|
+
type = shared_resource_member_type()
|
|
325
|
+
existed = SharedResourceModel.member?(@shared_resource, scope: @scope, type: type, member_name: @name)
|
|
326
|
+
SharedResourceModel.add_member(@shared_resource, scope: @scope, type: type, member_name: @name, shard: @shard)
|
|
327
|
+
added = !existed
|
|
328
|
+
end
|
|
329
|
+
super(update: update, force: force, queued: queued)
|
|
330
|
+
rescue
|
|
331
|
+
# Don't leave a member behind for a microservice that wasn't created
|
|
332
|
+
SharedResourceModel.remove_member(@shared_resource, scope: @scope, type: shared_resource_member_type(), member_name: @name) if added
|
|
333
|
+
raise
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# @return [String] INTERFACE, ROUTER, or MICROSERVICE
|
|
337
|
+
def shared_resource_member_type
|
|
338
|
+
type = @name.split('__')[1]
|
|
339
|
+
%w(INTERFACE ROUTER).include?(type) ? type : 'MICROSERVICE'
|
|
340
|
+
end
|
|
341
|
+
|
|
263
342
|
def deploy(gem_path, variables, validate_only: false)
|
|
264
343
|
return unless @folder_name
|
|
265
344
|
|
|
@@ -291,6 +370,13 @@ module OpenC3
|
|
|
291
370
|
end
|
|
292
371
|
|
|
293
372
|
def undeploy
|
|
373
|
+
if @shared_resource
|
|
374
|
+
begin
|
|
375
|
+
SharedResourceModel.remove_member(@shared_resource, scope: @scope, type: shared_resource_member_type(), member_name: @name)
|
|
376
|
+
rescue => error
|
|
377
|
+
Logger.error("Error removing microservice #{@name} from shared resource #{@shared_resource} in scope #{@scope} due to #{error}")
|
|
378
|
+
end
|
|
379
|
+
end
|
|
294
380
|
prefix = "#{@scope}/microservices/#{@name}/"
|
|
295
381
|
objects = @bucket.list_objects(bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix)
|
|
296
382
|
keys = objects.map(&:key)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 OpenC3, Inc.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is distributed in the hope that it will be useful,
|
|
7
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
9
|
+
# See LICENSE.md for more details.
|
|
10
|
+
#
|
|
11
|
+
# This file may also be used under the terms of a commercial license
|
|
12
|
+
# if purchased from OpenC3, Inc.
|
|
13
|
+
|
|
14
|
+
require 'openc3/models/model'
|
|
15
|
+
require 'openc3/utilities/bucket'
|
|
16
|
+
require 'openc3/utilities/bucket_utilities'
|
|
17
|
+
|
|
18
|
+
module OpenC3
|
|
19
|
+
# A custom Dashboards panel type installed by a plugin:
|
|
20
|
+
#
|
|
21
|
+
# PANEL MAP
|
|
22
|
+
#
|
|
23
|
+
# deploys tools/panels/MAP/MAP.js (a SystemJS module, plus its
|
|
24
|
+
# optional .map) from the plugin gem to the tools bucket, where the
|
|
25
|
+
# Dashboards tool loads it.
|
|
26
|
+
class PanelModel < Model
|
|
27
|
+
PRIMARY_KEY = 'openc3_panels'
|
|
28
|
+
|
|
29
|
+
attr_accessor :name
|
|
30
|
+
attr_accessor :filename
|
|
31
|
+
attr_accessor :bucket_key
|
|
32
|
+
|
|
33
|
+
# NOTE: The following three class methods are used by the ModelController
|
|
34
|
+
# and are reimplemented to enable various Model class methods to work
|
|
35
|
+
def self.get(name:, scope: nil)
|
|
36
|
+
super("#{scope}__#{PRIMARY_KEY}", name: name)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.names(scope: nil)
|
|
40
|
+
super("#{scope}__#{PRIMARY_KEY}")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.all(scope: nil)
|
|
44
|
+
super("#{scope}__#{PRIMARY_KEY}")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Called by the PluginModel to validate its top-level keyword: "PANEL".
|
|
48
|
+
# ** takes needs_dependencies, which panels don't use.
|
|
49
|
+
def self.handle_config(parser, keyword, parameters, plugin: nil, scope:, **)
|
|
50
|
+
case keyword
|
|
51
|
+
when 'PANEL'
|
|
52
|
+
parser.verify_num_parameters(1, 1, "PANEL <Panel Type>")
|
|
53
|
+
name = parameters[0].upcase
|
|
54
|
+
# The name becomes a bucket key and a URL path segment
|
|
55
|
+
# (tools/panels/<NAME>/<NAME>.js) so keep it to a plain identifier
|
|
56
|
+
unless name.match?(/\A[A-Z0-9_-]+\z/)
|
|
57
|
+
raise ConfigParser::Error.new(parser, "Invalid PANEL type: #{parameters[0]}. Must only contain letters, numbers, '_' and '-'")
|
|
58
|
+
end
|
|
59
|
+
return self.new(name: name, plugin: plugin, scope: scope)
|
|
60
|
+
else
|
|
61
|
+
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Panel: #{keyword} #{parameters.join(" ")}")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# ** takes url (ignored, it's derived from the name) because models are
|
|
66
|
+
# rebuilt from their as_json, e.g. to find a plugin's models on upgrade
|
|
67
|
+
# or uninstall
|
|
68
|
+
def initialize(name:, updated_at: nil, plugin: nil, scope:, **)
|
|
69
|
+
super("#{scope}__#{PRIMARY_KEY}", name: name, plugin: plugin, updated_at: updated_at, scope: scope)
|
|
70
|
+
@filename = "#{@name}.js"
|
|
71
|
+
@bucket_key = "panels/#{@name}/#{@filename}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def as_json(*)
|
|
75
|
+
{
|
|
76
|
+
'name' => @name,
|
|
77
|
+
'updated_at' => @updated_at,
|
|
78
|
+
'plugin' => @plugin,
|
|
79
|
+
'url' => "/tools/#{@bucket_key}",
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def handle_config(parser, keyword, parameters)
|
|
84
|
+
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Panel: #{keyword} #{parameters.join(" ")}")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def deploy(gem_path, _variables, validate_only: false)
|
|
88
|
+
filename = File.join(gem_path, 'tools', 'panels', @name, @filename)
|
|
89
|
+
# Bundled JavaScript isn't run through ERB; it can legitimately contain '<%'
|
|
90
|
+
data = File.read(filename, mode: "rb")
|
|
91
|
+
return if validate_only
|
|
92
|
+
|
|
93
|
+
bucket = Bucket.getClient()
|
|
94
|
+
cache_control = BucketUtilities.get_cache_control(@filename)
|
|
95
|
+
bucket.put_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], content_type: 'application/javascript', cache_control: cache_control, key: @bucket_key, body: data)
|
|
96
|
+
if File.exist?(filename + '.map')
|
|
97
|
+
bucket.put_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], content_type: 'application/json', cache_control: cache_control, key: @bucket_key + '.map', body: File.read(filename + '.map', mode: "rb"))
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def undeploy
|
|
102
|
+
bucket = Bucket.getClient()
|
|
103
|
+
bucket.delete_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], key: @bucket_key)
|
|
104
|
+
bucket.delete_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], key: @bucket_key + '.map')
|
|
105
|
+
rescue Exception => e
|
|
106
|
+
Logger.error("Error undeploying panel model #{@name} in scope #{@scope} due to #{e}")
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|