Skip to content

Commit

Permalink
simplify core config to accept only a single version
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Sep 4, 2024
1 parent ff2435b commit 1cfa0a7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 37 deletions.
1 change: 0 additions & 1 deletion config/tlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ site_id: RN+SI0001
supervisors:
- ip: 127.0.0.1
port: 12111
core_versions: '3.2.2'
sxl: tlc
sxl_version: '1.2.1'
components:
Expand Down
4 changes: 2 additions & 2 deletions lib/rsmp/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def site
end

if options[:core]
settings['core_versions'] = [options[:core]]
settings['core_version'] = options[:core]
end

site_class = RSMP::Site
Expand Down Expand Up @@ -133,7 +133,7 @@ def supervisor

if options[:core]
settings['guest'] = {}
settings['guest']['core_versions'] = [options[:core]]
settings['guest']['core_version'] = options[:core]
end

if options[:log]
Expand Down
13 changes: 9 additions & 4 deletions lib/rsmp/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,14 @@ def extraneous_version message
end

def core_versions
return [RSMP::Schema.latest_core_version] if @site_settings["core_versions"] == 'latest'
return RSMP::Schema.core_versions if @site_settings["core_versions"] == 'all'
[@site_settings["core_versions"]].flatten
version = @site_settings["core_version"]
if version == 'latest'
[RSMP::Schema.latest_core_version]
elsif version
[version]
else
RSMP::Schema.core_versions
end
end

def check_core_version message
Expand All @@ -486,7 +491,7 @@ def check_core_version message
if candidates.any?
@core_version = candidates.sort_by { |v| Gem::Version.new(v) }.last # pick latest version
else
reason = "RSMP versions [#{message.versions.join(',')}] requested, but only [#{versions.join(',')}] supported."
reason = "RSMP versions [#{message.versions.join(', ')}] requested, but only [#{versions.join(', ')}] supported."
dont_acknowledge message, "Version message rejected", reason, force: true
raise HandshakeError.new reason
end
Expand Down
34 changes: 9 additions & 25 deletions lib/rsmp/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RSMP
class Site < Node
include Components

attr_reader :core_versions, :site_settings, :logger, :proxies
attr_reader :core_version, :site_settings, :logger, :proxies

def initialize options={}
super options
Expand All @@ -32,7 +32,6 @@ def handle_site_settings options={}
'supervisors' => [
{ 'ip' => '127.0.0.1', 'port' => 12111 }
],
'core_versions' => 'all',
'sxl' => 'tlc',
'sxl_version' => RSMP::Schema.latest_version(:tlc),
'intervals' => {
Expand All @@ -57,6 +56,7 @@ def handle_site_settings options={}
end

@site_settings = defaults.deep_merge options[:site_settings]

check_sxl_version
check_core_versions
setup_components @site_settings['components']
Expand All @@ -69,16 +69,10 @@ def check_sxl_version
end

def check_core_versions
return if @site_settings['core_versions'] == 'all'
requested = [@site_settings['core_versions']].flatten
invalid = requested - RSMP::Schema::core_versions
if invalid.any?
if invalid.size == 1
error_str = "Unknown core version: #{invalid.first}"
else
error_str = "Unknown core versions: [#{invalid.join(' ')}]"
end

version = @site_settings['core_version']
return unless version
unless RSMP::Schema::core_versions.include? version
error_str = "Unknown core version: #{version}"
raise RSMP::ConfigurationError.new(error_str)
end
end
Expand All @@ -89,23 +83,13 @@ def site_type_name

def log_site_starting
log "Starting #{site_type_name} #{@site_settings["site_id"]}", level: :info, timestamp: @clock.now

sxl = "Using #{@site_settings["sxl"]} sxl #{@site_settings["sxl_version"]}"

versions = @site_settings["core_versions"]
if versions.is_a?(Array) && versions.size == 1
versions = versions.first
end
if versions == 'all'
version = @site_settings["core_version"]
unless version
core = "accepting all core versions [#{RSMP::Schema.core_versions.join(', ')}]"
else
if versions.is_a?(String)
core = "accepting only core version #{versions}"
else
core = "accepting core versions [#{versions.join(', ')}]"
end
core = "accepting only core version #{version}"
end

log "#{sxl}, #{core}", level: :info, timestamp: @clock.now
end

Expand Down
5 changes: 2 additions & 3 deletions lib/rsmp/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RSMP
class Supervisor < Node
attr_reader :core_versions, :site_id, :supervisor_settings, :proxies, :logger
attr_reader :core_version, :site_id, :supervisor_settings, :proxies, :logger

def initialize options={}
handle_supervisor_settings( options[:supervisor_settings] || {} )
Expand All @@ -22,7 +22,6 @@ def handle_supervisor_settings supervisor_settings
'port' => 12111,
'ips' => 'all',
'guest' => {
'core_versions' => 'all',
'sxl' => 'tlc',
'intervals' => {
'timer' => 1,
Expand All @@ -37,7 +36,7 @@ def handle_supervisor_settings supervisor_settings

# merge options into defaults
@supervisor_settings = defaults.deep_merge(supervisor_settings)
@core_versions = @supervisor_settings["guest"]["core_versions"]
@core_version = @supervisor_settings["guest"]["core_version"]
check_site_sxl_types
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rsmp/supervisor_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def run
end

def start_handshake
send_version @site_settings['site_id'], @site_settings["core_versions"]
send_version @site_settings['site_id'], core_versions
end

# connect to the supervisor and initiate handshake supervisor
Expand Down
2 changes: 1 addition & 1 deletion lib/rsmp/tlc/traffic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def handle_m0013 arg, options={}

def find_plan plan_nr
plan = @plans[plan_nr.to_i]
raise InvalidMessage.new "unknown signal plan #{plan_nr}, known only [#{@plans.keys.join(',')}]" unless plan
raise InvalidMessage.new "unknown signal plan #{plan_nr}, known only [#{@plans.keys.join(', ')}]" unless plan
plan
end

Expand Down

0 comments on commit 1cfa0a7

Please sign in to comment.