rsmp 0.1.4 → 0.1.5

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: 4b02662d725fdbbddfa1da1a958136e62bba3212ebf8cef48f1f2dff57e9d90f
4
- data.tar.gz: 8b09971e4ebc897f9df25ef1e32f2d1ff9fb2b3b1ae797b0725ddc2f38d67947
3
+ metadata.gz: f56de7518625c2ed3840b32a1169c2e565d614c987d3197f573238a97f45f24f
4
+ data.tar.gz: afcbab033ed8fd02cc2dfe1068ceb8891ec994ed3fbf803ef3d34ef30c2b41e3
5
5
  SHA512:
6
- metadata.gz: 80779b821deeecdc6bc2fcdcb336ba7c8c8ade016ed49b1b13657f1f5fb609ff777c869cbd2019f0a5be2fd65a330255d7307c17a14f97bf28d7329340fa2c6c
7
- data.tar.gz: bfd182628250547ebe8de45473ceeacbc1656fc4ebceee09e54959659cc67cb0e9d970409916c153b5921febb63e3dc83c8f51dfad9aa2d31bf1ed0b9d0375f7
6
+ metadata.gz: d9939dd05989a49edb1995589363187a44ce3a465d84d0f26b0624e4f8f3dde69d8eefb60e1143c1474bd5c94be3a878554e95074009e1d0385c088c319cd04a
7
+ data.tar.gz: 9306e2f2aef9f7a522829c76cc51e6a5d7d433ccb6f90056603342f8e7c6004886eea32a3dbe485e39e26aac5bf57370868765fe0cc377d2291e67904a98d4c6
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  ignore
2
+ log
2
3
  .DS_Store
3
4
  .rspec_status
4
5
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.1.3)
4
+ rsmp (0.1.5)
5
5
  async (~> 1.23.0)
6
6
  async-io (~> 1.27.0)
7
7
  colorize (~> 0.8.1)
@@ -29,7 +29,7 @@ GEM
29
29
  childprocess (2.0.0)
30
30
  rake (< 13.0)
31
31
  colorize (0.8.1)
32
- console (1.5.0)
32
+ console (1.6.0)
33
33
  contracts (0.16.0)
34
34
  cucumber (3.1.2)
35
35
  builder (>= 2.1.2)
data/lib/rsmp/cli.rb CHANGED
@@ -8,26 +8,45 @@ module RSMP
8
8
  method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
9
9
  method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
10
10
  method_option :supervisors, :type => :string, :aliases => "-s", banner: 'ip:port,... list of supervisor to connect to'
11
+ method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
12
+ method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
11
13
  def site
12
- converted = {
13
- site_settings_path: options[:config],
14
- site_settings: {
15
- site_id: options[:id],
16
- }
17
- }
18
-
19
- if options[:supervisors]
20
- options[:supervisors].split(',').each do |supervisor|
21
- converted[:site_settings][:supervisors] ||= []
14
+ settings = {}
15
+ log_settings = { 'active' => true }
16
+
17
+ if options[:config]
18
+ if File.exist? options[:config]
19
+ settings = YAML.load_file options[:config]
20
+ log_settings = settings.delete 'log'
21
+ else
22
+ puts "Error: Config #{options[:config]} not found"
23
+ exit
24
+ end
25
+ end
26
+
27
+ if options[:id]
28
+ settings['site_id'] = options[:id]
29
+ end
30
+
31
+ if options[:supervisors]
32
+ options[:supervisors].split(',').each do |supervisor|
33
+ setting[:supervisors] ||= []
22
34
  ip, port = supervisor.split ':'
23
35
  ip = '127.0.0.1' if ip.empty?
24
36
  port = '12111' if port.empty?
25
- converted[:site_settings][:supervisors] << {"ip"=>ip, "port"=>port}
37
+ settings[:supervisors] << {"ip"=>ip, "port"=>port}
26
38
  end
27
39
  end
28
40
 
29
- converted[:site_settings].compact!
30
- RSMP::Site.new(converted).start
41
+ if options[:log]
42
+ log_settings['path'] = options[:log]
43
+ end
44
+
45
+ if options[:json]
46
+ log_settings['json'] = options[:json]
47
+ end
48
+
49
+ RSMP::Site.new(site_settings:settings, log_settings: log_settings).start
31
50
  end
32
51
 
33
52
  desc "supervisor", "Run RSMP supervisor"
@@ -35,17 +54,43 @@ module RSMP
35
54
  method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
36
55
  method_option :ip, :type => :numeric, banner: 'IP address to listen on'
37
56
  method_option :port, :type => :string, :aliases => "-p", banner: 'Port to listen on'
57
+ method_option :log, :type => :string, :aliases => "-l", banner: 'Path to log file'
58
+ method_option :json, :type => :boolean, :aliases => "-j", banner: 'Show JSON messages in log'
38
59
  def supervisor
39
- converted = {
40
- supervisor_settings_path: options[:config],
41
- supervisor_settings: {
42
- site_id: options[:id],
43
- ip: options[:ip],
44
- port: options[:port]
45
- }
46
- }
47
- converted[:supervisor_settings].compact!
48
- RSMP::Supervisor.new(converted).start
60
+ settings = {}
61
+ log_settings = { 'active' => true }
62
+
63
+ if options[:config]
64
+ if File.exist? options[:config]
65
+ settings = YAML.load_file options[:config]
66
+ log_settings = settings.delete 'log'
67
+ else
68
+ puts "Error: Config #{options[:config]} not found"
69
+ exit
70
+ end
71
+ end
72
+
73
+ if options[:id]
74
+ settings['site_id'] = options[:id]
75
+ end
76
+
77
+ if options[:ip]
78
+ settings['ip'] = options[:ip]
79
+ end
80
+
81
+ if options[:port]
82
+ settings['port'] = options[:port]
83
+ end
84
+
85
+ if options[:log]
86
+ log_settings['path'] = options[:log]
87
+ end
88
+
89
+ if options[:json]
90
+ log_settings['json'] = options[:json]
91
+ end
92
+
93
+ RSMP::Supervisor.new(supervisor_settings:settings,log_settings:log_settings).start
49
94
  end
50
95
 
51
96
  end
data/lib/rsmp/logger.rb CHANGED
@@ -3,9 +3,10 @@ module RSMP
3
3
 
4
4
  attr_accessor :settings
5
5
 
6
- def initialize settings
6
+ def initialize settings={}
7
7
  defaults = {
8
8
  'active'=>false,
9
+ 'path'=>nil,
9
10
  'author'=>false,
10
11
  'color'=>true,
11
12
  'site_id'=>true,
@@ -16,10 +17,26 @@ module RSMP
16
17
  'timestamp'=>true,
17
18
  'json'=>false,
18
19
  'debug'=>false,
19
- 'statistics'=>false
20
+ 'statistics'=>false,
21
+ 'hide_ip_and_port' => true
20
22
  }
21
- @settings = defaults.merge settings
23
+ if settings
24
+ @settings = defaults.merge settings
25
+ else
26
+ @settings = defaults
27
+ end
28
+
22
29
  @muted = {}
30
+
31
+ setup_output_destination
32
+ end
33
+
34
+ def setup_output_destination
35
+ if @settings['path']
36
+ @stream = File.open(@settings['path'],'a') # appending
37
+ else
38
+ @stream = $stdout
39
+ end
23
40
  end
24
41
 
25
42
  def mute ip, port
@@ -58,12 +75,9 @@ module RSMP
58
75
 
59
76
  def output level, str
60
77
  return if str.empty? || /^\s+$/.match(str)
61
- streams = [$stdout]
62
- #streams << $stderr if level == :error
63
78
  str = colorize level, str
64
- streams.each do |stream|
65
- stream.puts str
66
- end
79
+ @stream.puts str
80
+ @stream.flush
67
81
  end
68
82
 
69
83
  def colorize level, str
data/lib/rsmp/site.rb CHANGED
@@ -11,7 +11,7 @@ module RSMP
11
11
  def initialize options={}
12
12
  initialize_site
13
13
  handle_site_settings options
14
- super options.merge log_settings: @site_settings["log"]
14
+ super options
15
15
  @proxies = []
16
16
  @sleep_condition = Async::Notification.new
17
17
  end
@@ -41,29 +41,8 @@ module RSMP
41
41
  'send_after_connect' => true,
42
42
  'components' => {
43
43
  'C1' => {}
44
- },
45
- 'log' => {
46
- 'active' => true,
47
- 'color' => true,
48
- 'ip' => false,
49
- 'timestamp' => true,
50
- 'site_id' => true,
51
- 'level' => false,
52
- 'acknowledgements' => false,
53
- 'watchdogs' => false,
54
- 'json' => false,
55
- 'statistics' => false
56
44
  }
57
45
  }
58
- if options[:site_settings_path]
59
- if File.exist? options[:site_settings_path]
60
- @site_settings.merge! YAML.load_file(options[:site_settings_path])
61
- else
62
- puts "Error: Config #{options[:site_settings_path]} not found, pwd"
63
- exit
64
- end
65
- end
66
-
67
46
  if options[:site_settings]
68
47
  converted = options[:site_settings].map { |k,v| [k.to_s,v] }.to_h #convert symbol keys to string keys
69
48
  converted.compact!
@@ -71,7 +50,7 @@ module RSMP
71
50
  end
72
51
 
73
52
  required = [:supervisors,:rsmp_versions,:site_id,:watchdog_interval,:watchdog_timeout,
74
- :acknowledgement_timeout,:command_response_timeout,:log]
53
+ :acknowledgement_timeout,:command_response_timeout]
75
54
  check_required_settings @site_settings, required
76
55
 
77
56
  setup_components @site_settings['components']
@@ -8,7 +8,7 @@ module RSMP
8
8
 
9
9
  def initialize options={}
10
10
  handle_supervisor_settings options
11
- super options.merge log_settings: @supervisor_settings["log"]
11
+ super options
12
12
  @proxies = []
13
13
  @site_id_condition = Async::Notification.new
14
14
  end
@@ -30,47 +30,21 @@ module RSMP
30
30
  'status_response_timeout' => 1,
31
31
  'status_update_timeout' => 1,
32
32
  'site_connect_timeout' => 2,
33
- 'site_ready_timeout' => 1,
34
- 'log' => {
35
- 'active' => true,
36
- 'color' => true,
37
- 'ip' => false,
38
- 'timestamp' => true,
39
- 'site_id' => true,
40
- 'level' => false,
41
- 'acknowledgements' => false,
42
- 'watchdogs' => false,
43
- 'json' => false
44
- }
33
+ 'site_ready_timeout' => 1
45
34
  }
46
-
47
- if options[:supervisor_settings_path]
48
- if File.exist? options[:supervisor_settings_path]
49
- @supervisor_settings.merge! YAML.load_file(options[:supervisor_settings_path])
50
- else
51
- puts "Error: Site settings #{options[:supervisor_settings_path]} not found"
52
- exit
53
- end
54
-
55
- end
56
35
 
57
36
  if options[:supervisor_settings]
58
37
  converted = options[:supervisor_settings].map { |k,v| [k.to_s,v] }.to_h #convert symbol keys to string keys
38
+ converted.compact!
59
39
  @supervisor_settings.merge! converted
60
40
  end
61
41
 
62
42
  required = [:port, :rsmp_versions, :site_id, :watchdog_interval, :watchdog_timeout,
63
- :acknowledgement_timeout, :command_response_timeout, :log]
43
+ :acknowledgement_timeout, :command_response_timeout]
64
44
  check_required_settings @supervisor_settings, required
65
45
 
66
46
  @rsmp_versions = @supervisor_settings["rsmp_versions"]
67
-
68
- # randomize site id
69
- #@supervisor_settings["site_id"] = "RN+SU#{rand(9999).to_i}"
70
-
71
- # randomize port
72
- #@supervisor_settings["port"] = @supervisor_settings["port"] + rand(10).to_i
73
- end
47
+ end
74
48
 
75
49
  def start_action
76
50
  @endpoint = Async::IO::Endpoint.tcp('0.0.0.0', @supervisor_settings["port"])
@@ -126,7 +100,7 @@ module RSMP
126
100
  end
127
101
 
128
102
  def connect socket, info
129
- if @supervisor_settings['log']['hide_ip_and_port']
103
+ if @logger.settings['hide_ip_and_port']
130
104
  port_and_port = '********'
131
105
  else
132
106
  port_and_port = "#{info[:ip]}:#{info[:port]}"
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
357
357
  - !ruby/object:Gem::Version
358
358
  version: '0'
359
359
  requirements: []
360
- rubygems_version: 3.0.3
360
+ rubygems_version: 3.0.6
361
361
  signing_key:
362
362
  specification_version: 4
363
363
  summary: RoadSide Message Protocol (RSMP) library.