rsmp 0.37.0 → 0.38.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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +22 -0
  3. data/.github/workflows/rubocop.yaml +17 -0
  4. data/.gitignore +5 -6
  5. data/.rubocop.yml +80 -0
  6. data/Gemfile +13 -1
  7. data/Gemfile.lock +34 -1
  8. data/Rakefile +3 -3
  9. data/lib/rsmp/cli.rb +147 -124
  10. data/lib/rsmp/collect/ack_collector.rb +8 -7
  11. data/lib/rsmp/collect/aggregated_status_collector.rb +4 -4
  12. data/lib/rsmp/collect/alarm_collector.rb +31 -23
  13. data/lib/rsmp/collect/alarm_matcher.rb +3 -3
  14. data/lib/rsmp/collect/collector/logging.rb +17 -0
  15. data/lib/rsmp/collect/collector/reporting.rb +44 -0
  16. data/lib/rsmp/collect/collector/status.rb +34 -0
  17. data/lib/rsmp/collect/collector.rb +69 -150
  18. data/lib/rsmp/collect/command_matcher.rb +19 -6
  19. data/lib/rsmp/collect/command_response_collector.rb +7 -7
  20. data/lib/rsmp/collect/distributor.rb +14 -11
  21. data/lib/rsmp/collect/filter.rb +31 -15
  22. data/lib/rsmp/collect/matcher.rb +7 -11
  23. data/lib/rsmp/collect/queue.rb +4 -4
  24. data/lib/rsmp/collect/receiver.rb +10 -12
  25. data/lib/rsmp/collect/state_collector.rb +116 -77
  26. data/lib/rsmp/collect/status_collector.rb +6 -6
  27. data/lib/rsmp/collect/status_matcher.rb +17 -7
  28. data/lib/rsmp/{alarm_state.rb → component/alarm_state.rb} +76 -37
  29. data/lib/rsmp/{component.rb → component/component.rb} +15 -15
  30. data/lib/rsmp/component/component_base.rb +89 -0
  31. data/lib/rsmp/component/component_proxy.rb +75 -0
  32. data/lib/rsmp/component/components.rb +63 -0
  33. data/lib/rsmp/convert/export/json_schema.rb +116 -110
  34. data/lib/rsmp/convert/import/yaml.rb +21 -18
  35. data/lib/rsmp/{rsmp.rb → helpers/clock.rb} +5 -6
  36. data/lib/rsmp/{deep_merge.rb → helpers/deep_merge.rb} +2 -1
  37. data/lib/rsmp/helpers/error.rb +71 -0
  38. data/lib/rsmp/{inspect.rb → helpers/inspect.rb} +6 -10
  39. data/lib/rsmp/log/archive.rb +98 -0
  40. data/lib/rsmp/log/colorization.rb +41 -0
  41. data/lib/rsmp/log/filtering.rb +54 -0
  42. data/lib/rsmp/log/logger.rb +206 -0
  43. data/lib/rsmp/{logging.rb → log/logging.rb} +5 -7
  44. data/lib/rsmp/message.rb +159 -148
  45. data/lib/rsmp/{node.rb → node/node.rb} +19 -17
  46. data/lib/rsmp/{protocol.rb → node/protocol.rb} +5 -3
  47. data/lib/rsmp/node/site/site.rb +195 -0
  48. data/lib/rsmp/node/supervisor/modules/configuration.rb +59 -0
  49. data/lib/rsmp/node/supervisor/modules/connection.rb +140 -0
  50. data/lib/rsmp/node/supervisor/modules/sites.rb +64 -0
  51. data/lib/rsmp/node/supervisor/supervisor.rb +72 -0
  52. data/lib/rsmp/{task.rb → node/task.rb} +12 -14
  53. data/lib/rsmp/proxy/modules/acknowledgements.rb +144 -0
  54. data/lib/rsmp/proxy/modules/receive.rb +119 -0
  55. data/lib/rsmp/proxy/modules/send.rb +76 -0
  56. data/lib/rsmp/proxy/modules/state.rb +25 -0
  57. data/lib/rsmp/proxy/modules/tasks.rb +105 -0
  58. data/lib/rsmp/proxy/modules/versions.rb +69 -0
  59. data/lib/rsmp/proxy/modules/watchdogs.rb +66 -0
  60. data/lib/rsmp/proxy/proxy.rb +199 -0
  61. data/lib/rsmp/proxy/site/modules/aggregated_status.rb +52 -0
  62. data/lib/rsmp/proxy/site/modules/alarms.rb +27 -0
  63. data/lib/rsmp/proxy/site/modules/commands.rb +31 -0
  64. data/lib/rsmp/proxy/site/modules/status.rb +110 -0
  65. data/lib/rsmp/proxy/site/site_proxy.rb +205 -0
  66. data/lib/rsmp/proxy/supervisor/modules/aggregated_status.rb +47 -0
  67. data/lib/rsmp/proxy/supervisor/modules/alarms.rb +73 -0
  68. data/lib/rsmp/proxy/supervisor/modules/commands.rb +53 -0
  69. data/lib/rsmp/proxy/supervisor/modules/status.rb +204 -0
  70. data/lib/rsmp/proxy/supervisor/supervisor_proxy.rb +178 -0
  71. data/lib/rsmp/tlc/detector_logic.rb +18 -34
  72. data/lib/rsmp/tlc/input_states.rb +126 -0
  73. data/lib/rsmp/tlc/modules/detector_logics.rb +50 -0
  74. data/lib/rsmp/tlc/modules/display.rb +78 -0
  75. data/lib/rsmp/tlc/modules/helpers.rb +41 -0
  76. data/lib/rsmp/tlc/modules/inputs.rb +173 -0
  77. data/lib/rsmp/tlc/modules/modes.rb +253 -0
  78. data/lib/rsmp/tlc/modules/outputs.rb +30 -0
  79. data/lib/rsmp/tlc/modules/plans.rb +218 -0
  80. data/lib/rsmp/tlc/modules/signal_groups.rb +109 -0
  81. data/lib/rsmp/tlc/modules/startup_sequence.rb +22 -0
  82. data/lib/rsmp/tlc/modules/system.rb +140 -0
  83. data/lib/rsmp/tlc/modules/traffic_data.rb +49 -0
  84. data/lib/rsmp/tlc/signal_group.rb +37 -41
  85. data/lib/rsmp/tlc/signal_plan.rb +14 -11
  86. data/lib/rsmp/tlc/signal_priority.rb +39 -35
  87. data/lib/rsmp/tlc/startup_sequence.rb +59 -0
  88. data/lib/rsmp/tlc/traffic_controller.rb +38 -1010
  89. data/lib/rsmp/tlc/traffic_controller_site.rb +58 -57
  90. data/lib/rsmp/version.rb +1 -1
  91. data/lib/rsmp.rb +82 -48
  92. data/rsmp.gemspec +24 -31
  93. metadata +79 -139
  94. data/lib/rsmp/archive.rb +0 -76
  95. data/lib/rsmp/collect/message_matchers.rb +0 -0
  96. data/lib/rsmp/component_base.rb +0 -87
  97. data/lib/rsmp/component_proxy.rb +0 -57
  98. data/lib/rsmp/components.rb +0 -65
  99. data/lib/rsmp/error.rb +0 -71
  100. data/lib/rsmp/logger.rb +0 -216
  101. data/lib/rsmp/proxy.rb +0 -693
  102. data/lib/rsmp/site.rb +0 -188
  103. data/lib/rsmp/site_proxy.rb +0 -389
  104. data/lib/rsmp/supervisor.rb +0 -302
  105. data/lib/rsmp/supervisor_proxy.rb +0 -510
  106. data/lib/rsmp/tlc/inputs.rb +0 -134
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f2687b5748524376a9316cadcf6776a6d9a9ccddbb8b763ea222246f7efb602
4
- data.tar.gz: 942347899e8f26aae13eb6ead6dce7c2b2d17020c0e11b04af530a5e91904ed5
3
+ metadata.gz: 3f1f32aacd75ffad7d36662c3e7abd0b0a851b35b287f444dd63cdebc9db1c00
4
+ data.tar.gz: 32d9db803bc5ef274c1838cb961f677863745bb2e2eca105eb17b8ee4f39cea1
5
5
  SHA512:
6
- metadata.gz: 77ba8af9b9be03e22bef3fa9a83c28f407c2371f7b6c3064e00396f8f9e2a1e088d52afb9c06270352c602cea91b88468e8674a5555b6a7383cd8b389f5a2567
7
- data.tar.gz: 1f17f3055a0c88a2848fc5ef0b1fe93fd7ad02e321cdfbe90824f418c61054c6085940e5c3c87a186ab46ed7e6c5e8bceb0dc905e0109d055d484519cb030659
6
+ metadata.gz: a655dab4868d9544a0242303da7d26254f3d953ecc5d789c78f7e4553e946b98eebab7f59fa4ee69c736123dfa198417885595db490724b6238fa051b1fb2a87
7
+ data.tar.gz: f24fe238a17439e6e0b91e75f816733da49f9e348dd22cc00f3c68938505ca68ba7ed32575a71e9dfc18330a10f2b92fe23ade7679bdb3f0878b37e894fd55aa
@@ -0,0 +1,22 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "Ruby",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "image": "mcr.microsoft.com/devcontainers/ruby:3.4",
7
+
8
+ // Features to add to the dev container. More info: https://containers.dev/features.
9
+ // "features": {},
10
+
11
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
12
+ // "forwardPorts": [],
13
+
14
+ // A command to run when creating the container and rerun when the workspace content was updated while creating the container
15
+ "updateContentCommand": "bundle install"
16
+
17
+ // Configure tool-specific properties.
18
+ // "customizations": {},
19
+
20
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
21
+ // "remoteUser": "root"
22
+ }
@@ -0,0 +1,17 @@
1
+ # This workflow runs RSpec tests
2
+
3
+ name: Rubocop
4
+ on: [push]
5
+ jobs:
6
+ test:
7
+ timeout-minutes: 10
8
+ strategy:
9
+ fail-fast: false
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ bundler-cache: true
16
+ - run: bundle exec rubocop
17
+
data/.gitignore CHANGED
@@ -1,10 +1,9 @@
1
- ignore
2
- log
3
- .DS_Store
4
- .rspec_status
5
-
1
+ /.DS_Store
2
+ /.rspec_status
3
+ /ignore/
4
+ /log/
6
5
  /.bundle/
7
- /.yardoc
6
+ /.yardoc/
8
7
  /_yardoc/
9
8
  /coverage/
10
9
  /doc/
data/.rubocop.yml ADDED
@@ -0,0 +1,80 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.4
4
+ Exclude:
5
+ - 'vendor/**/*'
6
+ - 'bin/**/*'
7
+ - '.bundle/**/*'
8
+ - 'ignore/**/*'
9
+ - 'config/private/**/*'
10
+
11
+ # Allow longer line lengths for tests with long JSON strings
12
+ Layout/LineLength:
13
+ Max: 120
14
+ Exclude:
15
+ - 'spec/**/*'
16
+
17
+ # Allow some reasonable flexibility for domain-specific code
18
+ Metrics/MethodLength:
19
+ Max: 25
20
+
21
+ Metrics/ClassLength:
22
+ Max: 200
23
+
24
+ Metrics/ModuleLength:
25
+ Max: 200
26
+
27
+ Metrics/AbcSize:
28
+ Max: 20
29
+
30
+ Metrics/CyclomaticComplexity:
31
+ Max: 10
32
+
33
+ Metrics/PerceivedComplexity:
34
+ Max: 10
35
+
36
+ Metrics/ParameterLists:
37
+ Max: 5
38
+
39
+ # Allow some blocks to be longer for complex configurations and tests
40
+ Metrics/BlockLength:
41
+ Exclude:
42
+ - 'spec/**/*'
43
+ - 'features/**/*'
44
+ - '*.gemspec'
45
+
46
+ # Keep some reasonable exceptions
47
+ Style/Documentation:
48
+ Enabled: false
49
+
50
+ Style/FrozenStringLiteralComment:
51
+ Enabled: false
52
+
53
+ # Allow double negation for boolean coercion - common Ruby pattern
54
+ Style/DoubleNegation:
55
+ Enabled: false
56
+
57
+ # Allow mix-in usage at top level in test files
58
+ Style/MixinUsage:
59
+ Exclude:
60
+ - 'spec/**/*'
61
+ - 'features/**/*'
62
+
63
+ # Allow constant definition in blocks for test helpers
64
+ Lint/ConstantDefinitionInBlock:
65
+ Exclude:
66
+ - 'spec/**/*'
67
+
68
+ # Keep critical domain-specific logic intact
69
+ Style/ReturnNilInPredicateMethodDefinition:
70
+ Enabled: false
71
+
72
+
73
+ plugins:
74
+ - rubocop-rspec
75
+
76
+ RSpec/MultipleExpectations:
77
+ Max: 20
78
+
79
+ RSpec/ExampleLength:
80
+ Max: 50
data/Gemfile CHANGED
@@ -1,5 +1,17 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rsmp.gemspec
4
4
 
5
5
  gemspec
6
+
7
+ group :development do
8
+ gem 'aruba', '~> 2.3'
9
+ gem 'bundler', '~> 2.6'
10
+ gem 'cucumber', '~> 9.2'
11
+ gem 'rake', '~> 13.2'
12
+ gem 'rspec', '~> 3.13'
13
+ gem 'rspec-expectations', '~> 3.13'
14
+ gem 'rubocop', '~> 1.65'
15
+ gem 'rubocop-rspec', require: false
16
+ gem 'timecop', '~> 0.9'
17
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.37.0)
4
+ rsmp (0.38.0)
5
5
  async (~> 2.32)
6
6
  colorize (~> 1.1)
7
7
  io-endpoint (~> 0.15)
@@ -19,6 +19,7 @@ GEM
19
19
  cucumber (>= 8.0, < 11.0)
20
20
  rspec-expectations (~> 3.4)
21
21
  thor (~> 1.0)
22
+ ast (2.4.3)
22
23
  async (2.32.0)
23
24
  console (~> 1.29)
24
25
  fiber-annotation
@@ -75,12 +76,21 @@ GEM
75
76
  hana (~> 1.3)
76
77
  regexp_parser (~> 2.0)
77
78
  simpleidn (~> 0.2)
79
+ language_server-protocol (3.17.0.5)
80
+ lint_roller (1.1.0)
78
81
  logger (1.7.0)
79
82
  memoist3 (1.0.0)
80
83
  metrics (0.15.0)
81
84
  mini_mime (1.1.5)
82
85
  multi_test (1.1.0)
83
86
  ostruct (0.6.3)
87
+ parallel (1.27.0)
88
+ parser (3.3.9.0)
89
+ ast (~> 2.4.1)
90
+ racc
91
+ prism (1.5.1)
92
+ racc (1.8.1)
93
+ rainbow (3.1.1)
84
94
  rake (13.3.0)
85
95
  regexp_parser (2.11.2)
86
96
  rsmp_schema (0.8.9)
@@ -99,6 +109,24 @@ GEM
99
109
  diff-lcs (>= 1.2.0, < 2.0)
100
110
  rspec-support (~> 3.13.0)
101
111
  rspec-support (3.13.5)
112
+ rubocop (1.81.0)
113
+ json (~> 2.3)
114
+ language_server-protocol (~> 3.17.0.2)
115
+ lint_roller (~> 1.1.0)
116
+ parallel (~> 1.10)
117
+ parser (>= 3.3.0.2)
118
+ rainbow (>= 2.2.2, < 4.0)
119
+ regexp_parser (>= 2.9.3, < 3.0)
120
+ rubocop-ast (>= 1.47.1, < 2.0)
121
+ ruby-progressbar (~> 1.7)
122
+ unicode-display_width (>= 2.4.0, < 4.0)
123
+ rubocop-ast (1.47.1)
124
+ parser (>= 3.3.7.2)
125
+ prism (~> 1.4)
126
+ rubocop-rspec (3.7.0)
127
+ lint_roller (~> 1.1)
128
+ rubocop (~> 1.72, >= 1.72.1)
129
+ ruby-progressbar (1.13.0)
102
130
  simpleidn (0.2.3)
103
131
  sys-uname (1.4.1)
104
132
  ffi (~> 1.1)
@@ -106,6 +134,9 @@ GEM
106
134
  thor (1.4.0)
107
135
  timecop (0.9.10)
108
136
  traces (0.18.2)
137
+ unicode-display_width (3.2.0)
138
+ unicode-emoji (~> 4.1)
139
+ unicode-emoji (4.1.0)
109
140
 
110
141
  PLATFORMS
111
142
  arm64-darwin-22
@@ -127,6 +158,8 @@ DEPENDENCIES
127
158
  rsmp!
128
159
  rspec (~> 3.13)
129
160
  rspec-expectations (~> 3.13)
161
+ rubocop (~> 1.65)
162
+ rubocop-rspec
130
163
  timecop (~> 0.9)
131
164
 
132
165
  BUNDLED WITH
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/lib/rsmp/cli.rb CHANGED
@@ -1,186 +1,208 @@
1
1
  require 'thor'
2
- require 'rsmp'
2
+ require_relative '../rsmp'
3
3
 
4
4
  module RSMP
5
5
  class CLI < Thor
6
- desc "version", "Show version"
6
+ desc 'version', 'Show version'
7
7
  def version
8
8
  puts RSMP::VERSION
9
9
  end
10
10
 
11
- desc "site", "Run RSMP site"
12
- method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
13
- method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
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'
17
- method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
18
- method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
11
+ desc 'site', 'Run RSMP site'
12
+ method_option :config, type: :string, aliases: '-c', banner: 'Path to .yaml config file'
13
+ method_option :id, type: :string, aliases: '-i', banner: 'RSMP site id'
14
+ method_option :supervisors, type: :string, aliases: '-s',
15
+ banner: 'ip:port,... list of supervisor to connect to'
16
+ method_option :core, type: :string, banner: "Core version: [#{RSMP::Schema.core_versions.join(' ')}]", enum: RSMP::Schema.core_versions
17
+ method_option :type, type: :string, aliases: '-t', banner: 'Type of site: [tlc]', enum: ['tlc'],
18
+ default: 'tlc'
19
+ method_option :log, type: :string, aliases: '-l', banner: 'Path to log file'
20
+ method_option :json, type: :boolean, aliases: '-j', banner: 'Show JSON messages in log'
19
21
  def site
20
- settings = {}
21
- log_settings = { 'active' => true }
22
+ settings, log_settings = load_site_configuration
23
+ apply_site_options(settings, log_settings)
24
+ site_class = determine_site_class(settings)
25
+ run_site(site_class, settings, log_settings)
26
+ rescue Interrupt
27
+ # ctrl-c
28
+ rescue StandardError => e
29
+ puts "Uncaught error: #{e}"
30
+ puts caller.join("\n")
31
+ end
32
+
33
+ desc 'supervisor', 'Run RSMP supervisor'
34
+ method_option :config, type: :string, aliases: '-c', banner: 'Path to .yaml config file'
35
+ method_option :id, type: :string, aliases: '-i', banner: 'RSMP site id'
36
+ method_option :ip, type: :string, banner: 'IP address to listen on'
37
+ method_option :port, type: :string, aliases: '-p', banner: 'Port to listen on'
38
+ method_option :core, type: :string, banner: "Core version: [#{RSMP::Schema.core_versions.join(' ')}]", enum: RSMP::Schema.core_versions
39
+ method_option :log, type: :string, aliases: '-l', banner: 'Path to log file'
40
+ method_option :json, type: :boolean, aliases: '-j', banner: 'Show JSON messages in log'
41
+ def supervisor
42
+ settings, log_settings = load_supervisor_configuration
43
+ apply_supervisor_options(settings, log_settings)
44
+ run_supervisor(settings, log_settings)
45
+ rescue Interrupt
46
+ # ctrl-c
47
+ end
48
+
49
+ desc 'convert', 'Convert SXL from YAML to JSON Schema'
50
+ method_option :in, type: :string, aliases: '-i', banner: 'Path to YAML input file'
51
+ method_option :out, type: :string, aliases: '-o', banner: 'Path to JSON Schema output file'
52
+ def convert
53
+ validate_convert_options
54
+ validate_input_file_exists
55
+ perform_conversion
56
+ end
57
+
58
+ no_commands do
59
+ def load_site_configuration
60
+ settings = {}
61
+ log_settings = { 'active' => true }
62
+
63
+ return [settings, log_settings] unless options[:config]
22
64
 
23
- if options[:config]
24
65
  if File.exist? options[:config]
25
66
  settings = YAML.load_file options[:config]
26
- log_settings = settings.delete('log') || {}
67
+ log_settings = settings.delete('log') || log_settings
27
68
  else
28
69
  puts "Error: Config #{options[:config]} not found"
29
70
  exit
30
71
  end
31
- end
32
72
 
33
- if options[:id]
34
- settings['site_id'] = options[:id]
73
+ [settings, log_settings]
35
74
  end
75
+ end
36
76
 
37
- if options[:supervisors]
38
- settings['supervisors'] = []
39
- options[:supervisors].split(',').each do |supervisor|
40
- ip, port = supervisor.split ':'
41
- ip = '127.0.0.1' if ip.empty?
42
- port = '12111' if port.empty?
43
- settings['supervisors'] << {"ip"=>ip, "port"=>port}
44
- end
45
- end
77
+ private
46
78
 
47
- if options[:core]
48
- settings['core_version'] = options[:core]
49
- end
79
+ def apply_site_options(settings, log_settings)
80
+ apply_basic_site_options(settings)
81
+ parse_supervisors(settings) if options[:supervisors]
82
+ apply_log_options(log_settings)
83
+ end
50
84
 
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
85
+ def apply_basic_site_options(settings)
86
+ settings['site_id'] = options[:id] if options[:id]
87
+ settings['core_version'] = options[:core] if options[:core]
88
+ end
60
89
 
61
- if options[:log]
62
- log_settings['path'] = options[:log]
90
+ def parse_supervisors(settings)
91
+ settings['supervisors'] = []
92
+ options[:supervisors].split(',').each do |supervisor|
93
+ ip, port = supervisor.split ':'
94
+ ip = '127.0.0.1' if ip.empty?
95
+ port = '12111' if port.empty?
96
+ settings['supervisors'] << { 'ip' => ip, 'port' => port }
63
97
  end
98
+ end
64
99
 
65
- if options[:json]
66
- log_settings['json'] = options[:json]
100
+ def determine_site_class(settings)
101
+ site_type = options[:type] || settings['type']
102
+ case site_type
103
+ when 'tlc'
104
+ RSMP::TLC::TrafficControllerSite
105
+ else
106
+ puts "Error: Unknown site type #{site_type}"
107
+ exit
67
108
  end
109
+ end
68
110
 
111
+ def run_site(site_class, settings, log_settings)
69
112
  Async do |task|
70
113
  task.annotate 'cli'
71
114
  loop do
72
- begin
73
- site = site_class.new(site_settings: settings, log_settings: log_settings)
74
- site.start
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
88
- rescue RSMP::Restart
89
- site.stop
90
- end
115
+ site = site_class.new(site_settings: settings, log_settings: log_settings)
116
+ site.start
117
+ site.wait
118
+ rescue Psych::SyntaxError => e
119
+ puts "Cannot read config file #{e}"
120
+ break
121
+ rescue RSMP::Schema::UnknownSchemaTypeError, RSMP::Schema::UnknownSchemaVersionError,
122
+ RSMP::ConfigurationError => e
123
+ puts "Cannot start site: #{e}"
124
+ break
125
+ rescue RSMP::Restart
126
+ site.stop
91
127
  end
92
128
  end
93
- rescue Interrupt
94
- # cntr-c
95
- rescue Exception => e
96
- puts "Uncaught error: #{e}"
97
- puts caller.join("\n")
98
129
  end
99
130
 
100
- desc "supervisor", "Run RSMP supervisor"
101
- method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
102
- method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
103
- method_option :ip, :type => :numeric, banner: 'IP address to listen on'
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
106
- method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
107
- method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
108
- def supervisor
131
+ def load_supervisor_configuration
109
132
  settings = {}
110
133
  log_settings = { 'active' => true }
111
134
 
112
- if options[:config]
113
- if File.exist? options[:config]
114
- settings = YAML.load_file options[:config]
115
- log_settings = settings.delete 'log'
116
- else
117
- puts "Error: Config #{options[:config]} not found"
118
- exit
119
- end
120
- end
135
+ return [settings, log_settings] unless options[:config]
121
136
 
122
- if options[:id]
123
- settings['site_id'] = options[:id]
137
+ if File.exist? options[:config]
138
+ settings = YAML.load_file options[:config]
139
+ log_settings = settings.delete('log') || log_settings
140
+ else
141
+ puts "Error: Config #{options[:config]} not found"
142
+ exit
124
143
  end
125
144
 
126
- if options[:ip]
127
- settings['ip'] = options[:ip]
128
- end
145
+ [settings, log_settings]
146
+ end
129
147
 
130
- if options[:port]
131
- settings['port'] = options[:port]
132
- end
148
+ def apply_supervisor_options(settings, log_settings)
149
+ apply_basic_supervisor_options(settings)
150
+ apply_core_version_option(settings)
151
+ apply_log_options(log_settings)
152
+ end
133
153
 
134
- if options[:core]
135
- settings['guest'] = {}
136
- settings['guest']['core_version'] = options[:core]
137
- end
154
+ def apply_basic_supervisor_options(settings)
155
+ settings['site_id'] = options[:id] if options[:id]
156
+ settings['ip'] = options[:ip] if options[:ip]
157
+ settings['port'] = options[:port] if options[:port]
158
+ end
138
159
 
139
- if options[:log]
140
- log_settings['path'] = options[:log]
141
- end
160
+ def apply_core_version_option(settings)
161
+ return unless options[:core]
142
162
 
143
- if options[:json]
144
- log_settings['json'] = options[:json]
145
- end
163
+ settings['guest'] ||= {}
164
+ settings['guest']['core_version'] = options[:core]
165
+ end
146
166
 
167
+ def apply_log_options(log_settings)
168
+ log_settings['path'] = options[:log] if options[:log]
169
+ log_settings['json'] = options[:json] if options[:json]
170
+ end
171
+
172
+ def run_supervisor(settings, log_settings)
147
173
  Async do |task|
148
174
  task.annotate 'cli'
149
- supervisor = RSMP::Supervisor.new(supervisor_settings:settings,log_settings:log_settings)
175
+ supervisor = RSMP::Supervisor.new(supervisor_settings: settings, log_settings: log_settings)
150
176
  supervisor.start
151
177
  supervisor.wait
152
178
  rescue Psych::SyntaxError => e
153
179
  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
180
+ rescue RSMP::Schema::UnknownSchemaTypeError, RSMP::Schema::UnknownSchemaVersionError,
181
+ RSMP::ConfigurationError => e
159
182
  puts "Cannot start supervisor: #{e}"
160
183
  end
161
- rescue Interrupt
162
- # ctrl-c
163
184
  end
164
185
 
165
- desc "convert", "Convert SXL from YAML to JSON Schema"
166
- method_option :in, :type => :string, :aliases => "-i", banner: 'Path to YAML input file'
167
- method_option :out, :type => :string, :aliases => "-o", banner: 'Path to JSON Schema output file'
168
- def convert
186
+ def validate_convert_options
169
187
  unless options[:in]
170
- puts "Error: Input option missing"
188
+ puts 'Error: Input option missing'
171
189
  exit
172
190
  end
173
191
 
174
- unless options[:out]
175
- puts "Error: Output option missing"
176
- exit
177
- end
192
+ return if options[:out]
178
193
 
179
- unless File.exist? options[:in]
180
- puts "Error: Input path file #{options[:in]} not found"
181
- exit
182
- end
194
+ puts 'Error: Output option missing'
195
+ exit
196
+ end
197
+
198
+ def validate_input_file_exists
199
+ return if File.exist? options[:in]
200
+
201
+ puts "Error: Input path file #{options[:in]} not found"
202
+ exit
203
+ end
183
204
 
205
+ def perform_conversion
184
206
  sxl = RSMP::Convert::Import::YAML.read options[:in]
185
207
  RSMP::Convert::Export::JSONSchema.write sxl, options[:out]
186
208
  end
@@ -190,5 +212,6 @@ module RSMP
190
212
  def self.exit_on_failure?
191
213
  true
192
214
  end
215
+ private_class_method :exit_on_failure?
193
216
  end
194
- end
217
+ end
@@ -1,18 +1,19 @@
1
1
  module RSMP
2
2
  # Class for waiting for a message acknowledgement
3
3
  class AckCollector < Collector
4
- def initialize proxy, options={}
5
- raise ArgumentError.new("m_id must be provided") unless options[:m_id]
6
- super proxy, options.merge(
4
+ def initialize(proxy, options = {})
5
+ raise ArgumentError, 'm_id must be provided' unless options[:m_id]
6
+
7
+ super(proxy, options.merge(
7
8
  filter: RSMP::Filter.new(ingoing: true, outgoing: false, type: 'MessageAck'),
8
9
  num: 1,
9
10
  title: 'message acknowledgement'
10
- )
11
+ ))
11
12
  end
12
13
 
13
14
  # Check if we the MessageAck related to initiating request, identified by @m_id.
14
- def acceptable? message
15
- super(message) && message.attribute('oMId') == @m_id
15
+ def acceptable?(message)
16
+ super && message.attribute('oMId') == @m_id
16
17
  end
17
18
  end
18
- end
19
+ end
@@ -1,11 +1,11 @@
1
1
  module RSMP
2
2
  # Class for waiting for an aggregated status response
3
3
  class AggregatedStatusCollector < Collector
4
- def initialize proxy, options={}
5
- super proxy, options.merge(
4
+ def initialize(proxy, options = {})
5
+ super(proxy, options.merge(
6
6
  filter: RSMP::Filter.new(ingoing: true, outgoing: false, type: 'AggregatedStatus'),
7
7
  title: 'aggregated status'
8
- )
8
+ ))
9
9
  end
10
10
  end
11
- end
11
+ end