rsmp 0.2.1 → 0.2.2
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.lock +5 -5
- data/lib/rsmp/logger.rb +2 -1
- data/lib/rsmp/proxy.rb +17 -7
- data/lib/rsmp/site_proxy.rb +16 -5
- data/lib/rsmp/supervisor.rb +35 -9
- data/lib/rsmp/tlc.rb +1 -1
- data/lib/rsmp/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55265e42f3956b7af530055680da60f82c84d34d7febd19286bf7c78bd2048f8
|
4
|
+
data.tar.gz: 445498a67e24c6b63cbfceca009ad736e962717eb89e92239bdd7ad4870cf72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0854ca1835fc15e8ccd10059c3f6f30638daf54677d215799eabae0f87fa4de11c9f825319f10ba92f9d25052fc90927fb54eb9f5df19cb714ba9ead236effbf'
|
7
|
+
data.tar.gz: 5d60090a4de455ca03fcb0fc182977ff938d0c8df9ea0bfb69d1dc985546c6de6ece83296bb25a64cc5f9e3b67d94e7694ec9702e08877bd6d9e05853d700ebd
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rsmp (0.2.
|
4
|
+
rsmp (0.2.2)
|
5
5
|
async (~> 1.29.1)
|
6
6
|
async-io (~> 1.32.1)
|
7
7
|
colorize (~> 0.8.1)
|
@@ -24,12 +24,12 @@ GEM
|
|
24
24
|
cucumber (>= 2.4, < 7.0)
|
25
25
|
rspec-expectations (~> 3.4)
|
26
26
|
thor (~> 1.0)
|
27
|
-
async (1.29.
|
27
|
+
async (1.29.2)
|
28
28
|
console (~> 1.10)
|
29
29
|
nio4r (~> 2.3)
|
30
30
|
timers (~> 4.1)
|
31
|
-
async-io (1.32.
|
32
|
-
async
|
31
|
+
async-io (1.32.2)
|
32
|
+
async
|
33
33
|
builder (3.2.4)
|
34
34
|
childprocess (4.1.0)
|
35
35
|
colorize (0.8.1)
|
@@ -88,7 +88,7 @@ GEM
|
|
88
88
|
mime-types-data (3.2021.0225)
|
89
89
|
minitest (5.14.4)
|
90
90
|
multi_test (0.1.2)
|
91
|
-
nio4r (2.5.
|
91
|
+
nio4r (2.5.8)
|
92
92
|
protobuf-cucumber (3.10.8)
|
93
93
|
activesupport (>= 3.2)
|
94
94
|
middleware
|
data/lib/rsmp/logger.rb
CHANGED
@@ -96,7 +96,8 @@ module RSMP
|
|
96
96
|
'statistics' => 'light_black',
|
97
97
|
'not_acknowledged' => 'cyan',
|
98
98
|
'warning' => 'light_yellow',
|
99
|
-
'error' => 'red'
|
99
|
+
'error' => 'red',
|
100
|
+
'debug' => 'light_black'
|
100
101
|
}
|
101
102
|
colors.merge! @settings["color"] if @settings["color"].is_a?(Hash)
|
102
103
|
if colors[level.to_s]
|
data/lib/rsmp/proxy.rb
CHANGED
@@ -11,22 +11,32 @@ module RSMP
|
|
11
11
|
include Notifier
|
12
12
|
include Inspect
|
13
13
|
|
14
|
-
attr_reader :state, :archive, :connection_info, :sxl, :task, :collector
|
14
|
+
attr_reader :state, :archive, :connection_info, :sxl, :task, :collector, :ip, :port
|
15
15
|
|
16
16
|
def initialize options
|
17
17
|
initialize_logging options
|
18
|
+
setup options
|
19
|
+
initialize_distributor
|
20
|
+
prepare_collection @settings['collect']
|
21
|
+
clear
|
22
|
+
end
|
23
|
+
|
24
|
+
def revive options
|
25
|
+
setup options
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup options
|
18
29
|
@settings = options[:settings]
|
19
30
|
@task = options[:task]
|
20
31
|
@socket = options[:socket]
|
32
|
+
@stream = options[:stream]
|
33
|
+
@protocol = options[:protocol]
|
21
34
|
@ip = options[:ip]
|
22
35
|
@port = options[:port]
|
23
36
|
@connection_info = options[:info]
|
24
37
|
@sxl = nil
|
25
38
|
@site_settings = nil # can't pick until we know the site id
|
26
|
-
|
27
|
-
|
28
|
-
prepare_collection @settings['collect']
|
29
|
-
clear
|
39
|
+
@state = :stopped
|
30
40
|
end
|
31
41
|
|
32
42
|
def inspect
|
@@ -105,8 +115,8 @@ module RSMP
|
|
105
115
|
def start_reader
|
106
116
|
@reader = @task.async do |task|
|
107
117
|
task.annotate "reader"
|
108
|
-
@stream
|
109
|
-
@protocol
|
118
|
+
@stream ||= Async::IO::Stream.new(@socket)
|
119
|
+
@protocol ||= Async::IO::Protocol::Line.new(@stream,WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
|
110
120
|
|
111
121
|
while json = @protocol.read_line
|
112
122
|
beginning = Time.now
|
data/lib/rsmp/site_proxy.rb
CHANGED
@@ -15,6 +15,13 @@ module RSMP
|
|
15
15
|
@site_id = nil
|
16
16
|
end
|
17
17
|
|
18
|
+
def revive options
|
19
|
+
super options
|
20
|
+
@supervisor = options[:supervisor]
|
21
|
+
@settings = @supervisor.supervisor_settings.clone
|
22
|
+
end
|
23
|
+
|
24
|
+
|
18
25
|
def inspect
|
19
26
|
"#<#{self.class.name}:#{self.object_id}, #{inspector(
|
20
27
|
:@acknowledgements,:@settings,:@site_settings,:@components
|
@@ -82,8 +89,12 @@ module RSMP
|
|
82
89
|
|
83
90
|
end
|
84
91
|
|
92
|
+
def validate_ready action
|
93
|
+
raise NotReady.new("Can't #{action} because connection is not ready. (Currently #{@state})") unless ready?
|
94
|
+
end
|
95
|
+
|
85
96
|
def request_aggregated_status component, options={}
|
86
|
-
|
97
|
+
validate_ready 'request aggregated status'
|
87
98
|
m_id = options[:m_id] || RSMP::Message.make_m_id
|
88
99
|
|
89
100
|
message = RSMP::AggregatedStatusRequest.new({
|
@@ -163,7 +174,7 @@ module RSMP
|
|
163
174
|
end
|
164
175
|
|
165
176
|
def request_status component, status_list, options={}
|
166
|
-
|
177
|
+
validate_ready 'request status'
|
167
178
|
m_id = options[:m_id] || RSMP::Message.make_m_id
|
168
179
|
|
169
180
|
# additional items can be used when verifying the response,
|
@@ -203,7 +214,7 @@ module RSMP
|
|
203
214
|
end
|
204
215
|
|
205
216
|
def subscribe_to_status component, status_list, options={}
|
206
|
-
|
217
|
+
validate_ready 'subscribe to status'
|
207
218
|
m_id = options[:m_id] || RSMP::Message.make_m_id
|
208
219
|
|
209
220
|
# additional items can be used when verifying the response,
|
@@ -238,7 +249,7 @@ module RSMP
|
|
238
249
|
end
|
239
250
|
|
240
251
|
def unsubscribe_to_status component, status_list, options={}
|
241
|
-
|
252
|
+
validate_ready 'unsubscribe to status'
|
242
253
|
message = RSMP::StatusUnsubscribe.new({
|
243
254
|
"ntsOId" => '',
|
244
255
|
"xNId" => '',
|
@@ -269,7 +280,7 @@ module RSMP
|
|
269
280
|
end
|
270
281
|
|
271
282
|
def send_command component, command_list, options={}
|
272
|
-
|
283
|
+
validate_ready 'send command'
|
273
284
|
m_id = options[:m_id] || RSMP::Message.make_m_id
|
274
285
|
message = RSMP::CommandRequest.new({
|
275
286
|
"ntsOId" => '',
|
data/lib/rsmp/supervisor.rb
CHANGED
@@ -136,6 +136,13 @@ module RSMP
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
def peek_version_message protocol
|
140
|
+
json = protocol.peek_line
|
141
|
+
attributes = Message.parse_attributes json
|
142
|
+
message = Message.build attributes, json
|
143
|
+
message.attribute('siteId').first['sId']
|
144
|
+
end
|
145
|
+
|
139
146
|
def connect socket, info
|
140
147
|
log "Site connected from #{format_ip_and_port(info)}",
|
141
148
|
ip: info[:ip],
|
@@ -144,25 +151,36 @@ module RSMP
|
|
144
151
|
timestamp: Clock.now
|
145
152
|
|
146
153
|
authorize_ip info[:ip]
|
147
|
-
check_max_sites
|
148
154
|
|
149
|
-
|
155
|
+
stream = Async::IO::Stream.new socket
|
156
|
+
protocol = Async::IO::Protocol::Line.new stream, Proxy::WRAPPING_DELIMITER
|
157
|
+
|
158
|
+
settings = {
|
150
159
|
supervisor: self,
|
151
160
|
ip: info[:ip],
|
152
161
|
port: info[:port],
|
153
162
|
task: @task,
|
154
163
|
settings: {'collect'=>@supervisor_settings['collect']},
|
155
164
|
socket: socket,
|
165
|
+
stream: stream,
|
166
|
+
protocol: protocol,
|
156
167
|
info: info,
|
157
168
|
logger: @logger,
|
158
169
|
archive: @archive
|
159
|
-
}
|
160
|
-
|
170
|
+
}
|
171
|
+
|
172
|
+
id = peek_version_message protocol
|
173
|
+
proxy = find_site id
|
174
|
+
if proxy
|
175
|
+
proxy.revive settings
|
176
|
+
else
|
177
|
+
check_max_sites
|
178
|
+
proxy = build_proxy settings
|
179
|
+
@proxies.push proxy
|
180
|
+
end
|
161
181
|
proxy.run # will run until the site disconnects
|
162
182
|
ensure
|
163
|
-
@proxies.delete proxy
|
164
183
|
site_ids_changed
|
165
|
-
|
166
184
|
stop if @supervisor_settings['one_shot']
|
167
185
|
end
|
168
186
|
|
@@ -188,7 +206,14 @@ module RSMP
|
|
188
206
|
return find_site(site_id) != nil
|
189
207
|
end
|
190
208
|
|
191
|
-
def
|
209
|
+
def find_site_from_ip_port ip, port
|
210
|
+
@proxies.each do |site|
|
211
|
+
return site if site.ip == ip && site.port == port
|
212
|
+
end
|
213
|
+
nil
|
214
|
+
end
|
215
|
+
|
216
|
+
def find_site site_id
|
192
217
|
@proxies.each do |site|
|
193
218
|
return site if site_id == :any || site.site_id == site_id
|
194
219
|
end
|
@@ -210,12 +235,13 @@ module RSMP
|
|
210
235
|
end
|
211
236
|
|
212
237
|
def check_site_id site_id
|
213
|
-
check_site_already_connected site_id
|
238
|
+
#check_site_already_connected site_id
|
214
239
|
return site_id_to_site_setting site_id
|
215
240
|
end
|
216
241
|
|
217
242
|
def check_site_already_connected site_id
|
218
|
-
|
243
|
+
site = find_site(site_id)
|
244
|
+
raise FatalError.new "Site '#{site_id}' already connected" if site != nil && site != self
|
219
245
|
end
|
220
246
|
|
221
247
|
def site_id_to_site_setting site_id
|
data/lib/rsmp/tlc.rb
CHANGED
@@ -798,7 +798,7 @@ module RSMP
|
|
798
798
|
super options
|
799
799
|
@sxl = 'traffic_light_controller'
|
800
800
|
@security_codes = options[:site_settings]['security_codes']
|
801
|
-
@interval = options[:site_settings]
|
801
|
+
@interval = options[:site_settings].dig('intervals','timer') || 1
|
802
802
|
unless @main
|
803
803
|
raise ConfigurationError.new "TLC must have a main component"
|
804
804
|
end
|
data/lib/rsmp/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Tin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
- !ruby/object:Gem::Version
|
255
255
|
version: '0'
|
256
256
|
requirements: []
|
257
|
-
rubygems_version: 3.2.
|
257
|
+
rubygems_version: 3.2.26
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: RoadSide Message Protocol (RSMP) library.
|