rsmp 0.31.0 → 0.32.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4daeeb9fb712ab275d4b0711a6ea69e766124a2fcd55ea955eeb1c46f05ed3
4
- data.tar.gz: a47c38c49b46fb2ad412ced388f6e654653292dd439ea31d2bbaf33988f024f0
3
+ metadata.gz: c4dc16f45d38459c4ab31445f39e74c8e0fe71ce906759a4f842ddcc8ca78471
4
+ data.tar.gz: 50d8ff8a27a2f16ddba8206236cc17997a582b5b5ec01348a55e9a7b3a8004b7
5
5
  SHA512:
6
- metadata.gz: ec4a4057b53a27d12e1c81af4623b03bcd7cf93b39bad72f1d228c1a0dfd74495541abae496a3fa783c159a16df2e161eb0f5fbaa13d96daa8d8c99a847a0f9f
7
- data.tar.gz: 704c11a6d854a0fb48f9cb6d84514ac40791bb85fe56186b9ff217e876458be6a214fbb69b8c3aaf09db35bd334345f7ca6ee31da8f9fbf717a3ae790e77252a
6
+ metadata.gz: 735d346b07fb2ad71cead5a0d934bb415125429e2fa628e9c4aa93a73f7e1e40a8db5cce27b6329fbb520f13f9018fb2f221e4cf60051818043e58cbab2f0523
7
+ data.tar.gz: aad8d0d4b871916080c7c981a00fea551fb0c7b62599149b017b955d46e6c810fd246682206d89f2a6a99b5ec19cc0285fb6c68e2cde8b594cbe40402e542834
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.31.0)
4
+ rsmp (0.32.0)
5
5
  async (~> 2.12.0)
6
6
  async-io (~> 1.43.0)
7
7
  colorize (~> 1.1)
@@ -96,7 +96,7 @@ GEM
96
96
  simpleidn (0.2.3)
97
97
  sys-uname (1.3.0)
98
98
  ffi (~> 1.1)
99
- thor (1.3.1)
99
+ thor (1.3.2)
100
100
  timecop (0.9.10)
101
101
 
102
102
  PLATFORMS
data/lib/rsmp/cli.rb CHANGED
@@ -12,9 +12,10 @@ module RSMP
12
12
  method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
13
13
  method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
14
14
  method_option :supervisors, :type => :string, :aliases => "-s", banner: 'ip:port,... list of supervisor to connect to'
15
+ method_option :core, :string => :string, banner: "Core version: [#{RSMP::Schema.core_versions.join(' ')}]", enum: RSMP::Schema.core_versions
16
+ method_option :type, :type => :string, :aliases => "-t", banner: 'Type of site: [tlc]', enum: ['tlc'], default: 'tlc'
15
17
  method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
16
18
  method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
17
- method_option :type, :type => :string, :aliases => "-t", banner: 'Type of site: [tlc]'
18
19
  def site
19
20
  settings = {}
20
21
  log_settings = { 'active' => true }
@@ -43,6 +44,20 @@ module RSMP
43
44
  end
44
45
  end
45
46
 
47
+ if options[:core]
48
+ settings['core_versions'] = [options[:core]]
49
+ end
50
+
51
+ site_class = RSMP::Site
52
+ site_type = options[:type] || settings['type']
53
+ case site_type
54
+ when 'tlc'
55
+ site_class = RSMP::TLC::TrafficControllerSite
56
+ else
57
+ puts "Error: Unknown site type #{site_type}"
58
+ exit
59
+ end
60
+
46
61
  if options[:log]
47
62
  log_settings['path'] = options[:log]
48
63
  end
@@ -51,22 +66,25 @@ module RSMP
51
66
  log_settings['json'] = options[:json]
52
67
  end
53
68
 
54
- site_class = RSMP::Site
55
- if options[:type]
56
- case options[:type]
57
- when 'tlc'
58
- site_class = RSMP::TLC::TrafficControllerSite
59
- else
60
- site_class = RSMP::Site
61
- end
62
- end
63
69
  Async do |task|
64
70
  task.annotate 'cli'
65
71
  loop do
66
72
  begin
67
- site = site_class.new(site_settings:settings, log_settings: log_settings)
73
+ site = site_class.new(site_settings: settings, log_settings: log_settings)
68
74
  site.start
69
75
  site.wait
76
+ rescue Psych::SyntaxError => e
77
+ puts "Cannot read config file #{e}"
78
+ break
79
+ rescue RSMP::Schema::UnknownSchemaTypeError => e
80
+ puts "Cannot start site: #{e}"
81
+ break
82
+ rescue RSMP::Schema::UnknownSchemaVersionError => e
83
+ puts "Cannot start site: #{e}"
84
+ break
85
+ rescue RSMP::ConfigurationError => e
86
+ puts "Cannot start site: #{e}"
87
+ break
70
88
  rescue RSMP::Restart
71
89
  site.stop
72
90
  end
@@ -74,12 +92,6 @@ module RSMP
74
92
  end
75
93
  rescue Interrupt
76
94
  # cntr-c
77
- rescue RSMP::Schema::UnknownSchemaTypeError => e
78
- puts "Cannot start site: #{e}"
79
- rescue RSMP::Schema::UnknownSchemaVersionError => e
80
- puts "Cannot start site: #{e}"
81
- rescue Psych::SyntaxError => e
82
- puts "Cannot read config file #{e}"
83
95
  rescue Exception => e
84
96
  puts "Uncaught error: #{e}"
85
97
  puts caller.join("\n")
@@ -90,6 +102,7 @@ module RSMP
90
102
  method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
91
103
  method_option :ip, :type => :numeric, banner: 'IP address to listen on'
92
104
  method_option :port, :type => :string, :aliases => "-p", banner: 'Port to listen on'
105
+ method_option :core, :string => :string, banner: "Core version: [#{RSMP::Schema.core_versions.join(' ')}]", enum: RSMP::Schema.core_versions
93
106
  method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
94
107
  method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
95
108
  def supervisor
@@ -118,6 +131,11 @@ module RSMP
118
131
  settings['port'] = options[:port]
119
132
  end
120
133
 
134
+ if options[:core]
135
+ settings['guest'] = {}
136
+ settings['guest']['core_versions'] = [options[:core]]
137
+ end
138
+
121
139
  if options[:log]
122
140
  log_settings['path'] = options[:log]
123
141
  end
@@ -131,11 +149,17 @@ module RSMP
131
149
  supervisor = RSMP::Supervisor.new(supervisor_settings:settings,log_settings:log_settings)
132
150
  supervisor.start
133
151
  supervisor.wait
152
+ rescue Psych::SyntaxError => e
153
+ puts "Cannot read config file #{e}"
154
+ rescue RSMP::Schema::UnknownSchemaTypeError => e
155
+ puts "Cannot start supervisor: #{e}"
156
+ rescue RSMP::Schema::UnknownSchemaVersionError => e
157
+ puts "Cannot start supervisor: #{e}"
158
+ rescue RSMP::ConfigurationError => e
159
+ puts "Cannot start supervisor: #{e}"
134
160
  end
135
161
  rescue Interrupt
136
162
  # ctrl-c
137
- rescue RSMP::ConfigurationError => e
138
- puts "Cannot start supervisor: #{e}"
139
163
  end
140
164
 
141
165
  desc "convert", "Convert SXL from YAML to JSON Schema"
data/lib/rsmp/proxy.rb CHANGED
@@ -340,8 +340,8 @@ module RSMP
340
340
  schemas
341
341
  end
342
342
 
343
- def send_message message, reason=nil, validate: true
344
- raise NotReady unless connected?
343
+ def send_message message, reason=nil, validate: true, force: false
344
+ raise NotReady unless connected? unless force
345
345
  raise IOError unless @protocol
346
346
  message.direction = :out
347
347
  message.generate_json
@@ -486,7 +486,9 @@ module RSMP
486
486
  if candidates.any?
487
487
  @core_version = candidates.sort_by { |v| Gem::Version.new(v) }.last # pick latest version
488
488
  else
489
- raise HandshakeError.new "RSMP versions [#{message.versions.join(',')}] requested, but only [#{versions.join(',')}] supported."
489
+ reason = "RSMP versions [#{message.versions.join(',')}] requested, but only [#{versions.join(',')}] supported."
490
+ dont_acknowledge message, "Version message rejected", reason, force: true
491
+ raise HandshakeError.new reason
490
492
  end
491
493
  end
492
494
 
@@ -501,7 +503,7 @@ module RSMP
501
503
  check_ingoing_acknowledged original
502
504
  end
503
505
 
504
- def dont_acknowledge original, prefix=nil, reason=nil
506
+ def dont_acknowledge original, prefix=nil, reason=nil, force: true
505
507
  raise InvalidArgument unless original
506
508
  str = [prefix,reason].join(' ')
507
509
  log str, message: original, level: :warning if reason
@@ -510,7 +512,7 @@ module RSMP
510
512
  "rea" => reason || "Unknown reason"
511
513
  })
512
514
  message.original = original.clone
513
- send_message message, "for #{original.type} #{original.m_id_short}"
515
+ send_message message, "for #{original.type} #{original.m_id_short}", force: force
514
516
  end
515
517
 
516
518
  def wait_for_state state, timeout:
data/lib/rsmp/site.rb CHANGED
@@ -58,6 +58,7 @@ module RSMP
58
58
 
59
59
  @site_settings = defaults.deep_merge options[:site_settings]
60
60
  check_sxl_version
61
+ check_core_versions
61
62
  setup_components @site_settings['components']
62
63
  end
63
64
 
@@ -67,10 +68,49 @@ module RSMP
67
68
  RSMP::Schema::find_schema! sxl, version, lenient: true
68
69
  end
69
70
 
71
+ def check_core_versions
72
+ return if @site_settings['core_versions'] == 'all'
73
+ requested = [@site_settings['core_versions']].flatten
74
+ invalid = requested - RSMP::Schema::core_versions
75
+ if invalid.any?
76
+ if invalid.size == 1
77
+ error_str = "Unknown core version: #{invalid.first}"
78
+ else
79
+ error_str = "Unknown core versions: [#{invalid.join(' ')}]"
80
+ end
81
+
82
+ raise RSMP::ConfigurationError.new(error_str)
83
+ end
84
+ end
85
+
86
+ def site_type_name
87
+ "site"
88
+ end
89
+
90
+ def log_site_starting
91
+ log "Starting #{site_type_name} #{@site_settings["site_id"]}", level: :info, timestamp: @clock.now
92
+
93
+ sxl = "Using #{@site_settings["sxl"]} sxl #{@site_settings["sxl_version"]}"
94
+
95
+ versions = @site_settings["core_versions"]
96
+ if versions.is_a?(Array) && versions.size == 1
97
+ versions = versions.first
98
+ end
99
+ if versions == 'all'
100
+ core = "accepting all core versions [#{RSMP::Schema.core_versions.join(', ')}]"
101
+ else
102
+ if versions.is_a?(String)
103
+ core = "accepting only core version #{versions}"
104
+ else
105
+ core = "accepting core versions [#{versions.join(', ')}]"
106
+ end
107
+ end
108
+
109
+ log "#{sxl}, #{core}", level: :info, timestamp: @clock.now
110
+ end
111
+
70
112
  def run
71
- log "Starting site #{@site_settings["site_id"]}",
72
- level: :info,
73
- timestamp: @clock.now
113
+ log_site_starting
74
114
  @proxies.each { |proxy| proxy.start }
75
115
  @proxies.each { |proxy| proxy.wait }
76
116
  end
@@ -94,7 +94,7 @@ module RSMP
94
94
  else
95
95
  reject_connection socket, info
96
96
  end
97
- rescue ConnectionError => e
97
+ rescue ConnectionError, HandshakeError => e
98
98
  log "Rejected connection from #{remote_ip}:#{remote_port}, #{e.to_s}", level: :warning
99
99
  distribute_error e
100
100
  rescue StandardError => e
@@ -15,7 +15,7 @@ module RSMP
15
15
  @signal_groups = []
16
16
  @detector_logics = []
17
17
  @plans = signal_plans
18
- @cycle_time = cycle_time
18
+ @cycle_time = cycle_time || 10
19
19
  @num_traffic_situations = 1
20
20
 
21
21
  if inputs
@@ -18,7 +18,10 @@ module RSMP
18
18
  unless main
19
19
  raise ConfigurationError.new "TLC must have a main component"
20
20
  end
21
+ end
21
22
 
23
+ def site_type_name
24
+ "TLC"
22
25
  end
23
26
 
24
27
  def start
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.31.0"
2
+ VERSION = "0.32.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async