rsmp 0.5.1 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/supervisor.yaml +1 -1
- data/config/tlc.yaml +1 -1
- data/lib/rsmp/collect/collector.rb +9 -0
- data/lib/rsmp/collect/matcher.rb +7 -0
- data/lib/rsmp/collect/notifier.rb +5 -0
- data/lib/rsmp/component.rb +75 -0
- data/lib/rsmp/error.rb +3 -0
- data/lib/rsmp/logger.rb +6 -4
- data/lib/rsmp/node.rb +4 -0
- data/lib/rsmp/proxy.rb +4 -2
- data/lib/rsmp/site_proxy.rb +18 -8
- data/lib/rsmp/supervisor.rb +0 -1
- data/lib/rsmp/supervisor_proxy.rb +9 -13
- 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: a436495b7890003c9c745d9539326867be2604dc31308042d6f9fa982d8a1595
|
4
|
+
data.tar.gz: '083589d05fe1fcff4ffcdd79e92ae4c34b9d8383257005ef316fb265ab5a24af'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f443511ee9ea01faa4189f84182208362ad25f7a7d483198126b00b78de5454cd1a092ccd8348664553c31502497c4ec3f1df295d7daa7eaa53e22bd8298521b
|
7
|
+
data.tar.gz: 49436d1f1e79fec40b5a0a6f4482e4af29edac9b097380b0cf3359f1a35174a89234a3ea227a99767adb8931640383f5cca81e18105a9f00a44f7edaa11bc5c5
|
data/Gemfile.lock
CHANGED
data/config/supervisor.yaml
CHANGED
data/config/tlc.yaml
CHANGED
@@ -61,9 +61,18 @@ module RSMP
|
|
61
61
|
str = "#{@title.capitalize} collection"
|
62
62
|
str << " in response to #{options[:m_id]}" if options[:m_id]
|
63
63
|
str << " didn't complete within #{@options[:timeout]}s"
|
64
|
+
reached = progress
|
65
|
+
str << ", reached #{progress[:reached]}/#{progress[:need]}"
|
64
66
|
raise RSMP::TimeoutError.new str
|
65
67
|
end
|
66
68
|
|
69
|
+
# Return progress as collected vs. number requested
|
70
|
+
def progress
|
71
|
+
need = @options[:num]
|
72
|
+
reached = @messages.size
|
73
|
+
{ need: need, got: reached }
|
74
|
+
end
|
75
|
+
|
67
76
|
# Get the collected message.
|
68
77
|
def message
|
69
78
|
@messages.first
|
data/lib/rsmp/collect/matcher.rb
CHANGED
@@ -70,6 +70,13 @@ module RSMP
|
|
70
70
|
@queries.map { |query| query.message }.uniq
|
71
71
|
end
|
72
72
|
|
73
|
+
# Return progress as completes queries vs. total number of queries
|
74
|
+
def progress
|
75
|
+
need = @queries.size
|
76
|
+
reached = @queries.count { |query| query.done? }
|
77
|
+
{ need: need, reached: reached }
|
78
|
+
end
|
79
|
+
|
73
80
|
# Are there queries left to match?
|
74
81
|
def done?
|
75
82
|
@queries.all? { |query| query.done? }
|
@@ -16,12 +16,17 @@ module RSMP
|
|
16
16
|
@notify_queue = []
|
17
17
|
end
|
18
18
|
|
19
|
+
def clear_deferred_notify &block
|
20
|
+
@notify_queue = []
|
21
|
+
end
|
22
|
+
|
19
23
|
def deferred_notify &block
|
20
24
|
was, @defer_notify = @defer_notify, true
|
21
25
|
yield
|
22
26
|
dequeue_notify
|
23
27
|
ensure
|
24
28
|
@defer_notify = was
|
29
|
+
@notify_queue = []
|
25
30
|
end
|
26
31
|
|
27
32
|
def dequeue_notify
|
data/lib/rsmp/component.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module RSMP
|
2
|
+
|
3
|
+
# Class that represents an RMSP component.
|
4
|
+
# Currently this class is used by both SiteProxy and SupervisorProxy, and can
|
5
|
+
# therefore represent either a local or remote (proxy) component.
|
6
|
+
|
2
7
|
class Component
|
3
8
|
include Inspect
|
4
9
|
|
@@ -19,6 +24,7 @@ module RSMP
|
|
19
24
|
@grouped = grouped
|
20
25
|
@alarms = {}
|
21
26
|
@statuses = {}
|
27
|
+
@subscribes = {}
|
22
28
|
clear_aggregated_status
|
23
29
|
end
|
24
30
|
|
@@ -83,5 +89,74 @@ module RSMP
|
|
83
89
|
@alarms[code] = message
|
84
90
|
end
|
85
91
|
end
|
92
|
+
|
93
|
+
# Handle an incoming status respone, by storing the values
|
94
|
+
def handle_status_response message
|
95
|
+
store_status message, check_repeated: false
|
96
|
+
end
|
97
|
+
|
98
|
+
# Handle an incoming status update, by storing the values
|
99
|
+
def handle_status_update message
|
100
|
+
store_status message, check_repeated: true
|
101
|
+
end
|
102
|
+
|
103
|
+
# Our proxy subscribed to status updates
|
104
|
+
# Store update rates, so we can check for repeated alarm if we asked for updates only
|
105
|
+
# when there's a change, not on a regular interval.
|
106
|
+
# After subscribing, an update status us send regarless of whether values changes,
|
107
|
+
# and we store that.
|
108
|
+
def handle_status_subscribe status_list
|
109
|
+
status_list.each do |item|
|
110
|
+
sCI, n, uRt = item['sCI'], item['n'], item['uRt']
|
111
|
+
|
112
|
+
# record the update rate, so we can check for repeated status values if rate is zero
|
113
|
+
@subscribes[sCI] ||= {}
|
114
|
+
@subscribes[sCI][n] = {'uRt'=>uRt}
|
115
|
+
|
116
|
+
# record that we expect an upeate, even though the value might not change
|
117
|
+
@statuses[sCI] ||= {}
|
118
|
+
@statuses[sCI][n] ||= {}
|
119
|
+
@statuses[sCI][n][:initial] = true
|
120
|
+
end
|
121
|
+
#pp @subscribes
|
122
|
+
end
|
123
|
+
|
124
|
+
# Our proxy unsubscribed to status updates.
|
125
|
+
# Update our list of update rates.
|
126
|
+
def handle_status_unsubscribe status_list
|
127
|
+
status_list.each do |item|
|
128
|
+
sCI, n = item['sCI'], item['n']
|
129
|
+
if @subscribes[sCI]
|
130
|
+
@subscribes[sCI].delete n
|
131
|
+
end
|
132
|
+
if @subscribes[sCI].empty?
|
133
|
+
@subscribes.delete sCI
|
134
|
+
end
|
135
|
+
|
136
|
+
# remove any mark that would allow the next update to be a repeat
|
137
|
+
item = @statuses.dig sCI, n
|
138
|
+
item.delete(:initial) if item
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Store the latest status update values, optionally
|
143
|
+
# checking that we're not receiving unchanged values if we're subscribed
|
144
|
+
# wit updates only on change
|
145
|
+
def store_status message, check_repeated:
|
146
|
+
message.attribute('sS').each do |item|
|
147
|
+
sCI, n, s, q = item['sCI'], item['n'], item['s'], item['q']
|
148
|
+
uRt = @subscribes.dig(sCI,n,'uRt')
|
149
|
+
new_values = {'s'=>s,'q'=>q}
|
150
|
+
old_values = @statuses.dig(sCI,n)
|
151
|
+
if check_repeated && uRt.to_i == 0
|
152
|
+
if new_values == old_values
|
153
|
+
raise RSMP::RepeatedStatusError.new "no change for #{sCI} '#{n}'"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
@statuses[sCI] ||= {}
|
157
|
+
@statuses[sCI][n] = new_values
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
86
161
|
end
|
87
162
|
end
|
data/lib/rsmp/error.rb
CHANGED
data/lib/rsmp/logger.rb
CHANGED
@@ -159,9 +159,9 @@ module RSMP
|
|
159
159
|
unless @settings["id"] == false
|
160
160
|
length = 4
|
161
161
|
if item[:message]
|
162
|
-
parts << Logger.shorten_message_id(item[:message].m_id,length)
|
162
|
+
parts << Logger.shorten_message_id(item[:message].m_id,length).ljust(length)
|
163
163
|
else
|
164
|
-
parts <<
|
164
|
+
parts << ''.ljust(length)
|
165
165
|
end
|
166
166
|
end
|
167
167
|
parts << item[:str].to_s.strip unless @settings["text"] == false
|
@@ -172,8 +172,10 @@ module RSMP
|
|
172
172
|
parts << item[:exception].backtrace.join("\n")
|
173
173
|
end
|
174
174
|
|
175
|
-
|
176
|
-
|
175
|
+
parts.map do |s|
|
176
|
+
next '-'.ljust(s.length) if s !~ /\S/ # replace the first char with a dash if string is all whitespace
|
177
|
+
s
|
178
|
+
end.join(' ').rstrip
|
177
179
|
end
|
178
180
|
|
179
181
|
end
|
data/lib/rsmp/node.rb
CHANGED
data/lib/rsmp/proxy.rb
CHANGED
@@ -350,7 +350,7 @@ module RSMP
|
|
350
350
|
rescue SchemaError, RSMP::Schemer::Error => e
|
351
351
|
str = "Received invalid #{message.type}, schema errors: #{e.message}"
|
352
352
|
log str, message: message, level: :warning
|
353
|
-
notify_error e.exception(
|
353
|
+
notify_error e.exception(str), message: message
|
354
354
|
dont_acknowledge message, str
|
355
355
|
message
|
356
356
|
rescue InvalidMessage => e
|
@@ -360,10 +360,12 @@ module RSMP
|
|
360
360
|
message
|
361
361
|
rescue FatalError => e
|
362
362
|
str = "Rejected #{message.type},"
|
363
|
-
notify_error e.exception(
|
363
|
+
notify_error e.exception(str), message: message
|
364
364
|
dont_acknowledge message, str, "#{e.message}"
|
365
365
|
stop
|
366
366
|
message
|
367
|
+
ensure
|
368
|
+
node.clear_deferred
|
367
369
|
end
|
368
370
|
|
369
371
|
def process_message message
|
data/lib/rsmp/site_proxy.rb
CHANGED
@@ -68,6 +68,10 @@ module RSMP
|
|
68
68
|
else
|
69
69
|
super message
|
70
70
|
end
|
71
|
+
rescue RSMP::RepeatedAlarmError, RSMP::RepeatedStatusError => e
|
72
|
+
str = "Rejected #{message.type} message,"
|
73
|
+
dont_acknowledge message, str, "#{e}"
|
74
|
+
notify_error e.exception("#{str}#{e.message} #{message.json}")
|
71
75
|
end
|
72
76
|
|
73
77
|
def process_command_response message
|
@@ -145,10 +149,6 @@ module RSMP
|
|
145
149
|
asp = message.attribute("aSp")
|
146
150
|
log "Received #{message.type}, #{alarm_code} #{asp} [#{status}]", message: message, level: :log
|
147
151
|
acknowledge message
|
148
|
-
rescue RSMP::RepeatedAlarmError => e
|
149
|
-
str = "Rejected #{message.type} message, "
|
150
|
-
dont_acknowledge message, str, "#{e}"
|
151
|
-
notify_error e.exception("#{str}#{e.message} #{message.json}")
|
152
152
|
end
|
153
153
|
|
154
154
|
def version_acknowledged
|
@@ -187,6 +187,8 @@ module RSMP
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def process_status_response message
|
190
|
+
component = find_component message.attribute("cId")
|
191
|
+
component.handle_status_response message
|
190
192
|
log "Received #{message.type}", message: message, level: :log
|
191
193
|
acknowledge message
|
192
194
|
end
|
@@ -198,7 +200,7 @@ module RSMP
|
|
198
200
|
message
|
199
201
|
end
|
200
202
|
|
201
|
-
def subscribe_to_status
|
203
|
+
def subscribe_to_status component_id, status_list, options={}
|
202
204
|
validate_ready 'subscribe to status'
|
203
205
|
m_id = options[:m_id] || RSMP::Message.make_m_id
|
204
206
|
|
@@ -206,10 +208,13 @@ module RSMP
|
|
206
208
|
# but must to remove from the subscribe message
|
207
209
|
subscribe_list = status_list.map { |item| item.slice('sCI','n','uRt') }
|
208
210
|
|
211
|
+
component = find_component component_id
|
212
|
+
component.handle_status_subscribe subscribe_list
|
213
|
+
|
209
214
|
message = RSMP::StatusSubscribe.new({
|
210
215
|
"ntsOId" => '',
|
211
216
|
"xNId" => '',
|
212
|
-
"cId" =>
|
217
|
+
"cId" => component_id,
|
213
218
|
"sS" => subscribe_list,
|
214
219
|
'mId' => m_id
|
215
220
|
})
|
@@ -218,12 +223,15 @@ module RSMP
|
|
218
223
|
end
|
219
224
|
end
|
220
225
|
|
221
|
-
def unsubscribe_to_status
|
226
|
+
def unsubscribe_to_status component_id, status_list, options={}
|
227
|
+
component = find_component component_id
|
228
|
+
component.handle_status_subscribe status_list
|
229
|
+
|
222
230
|
validate_ready 'unsubscribe to status'
|
223
231
|
message = RSMP::StatusUnsubscribe.new({
|
224
232
|
"ntsOId" => '',
|
225
233
|
"xNId" => '',
|
226
|
-
"cId" =>
|
234
|
+
"cId" => component_id,
|
227
235
|
"sS" => status_list
|
228
236
|
})
|
229
237
|
send_message message, validate: options[:validate]
|
@@ -231,6 +239,8 @@ module RSMP
|
|
231
239
|
end
|
232
240
|
|
233
241
|
def process_status_update message
|
242
|
+
component = find_component message.attribute("cId")
|
243
|
+
component.handle_status_update message
|
234
244
|
log "Received #{message.type}", message: message, level: :log
|
235
245
|
acknowledge message
|
236
246
|
end
|
data/lib/rsmp/supervisor.rb
CHANGED
@@ -225,7 +225,6 @@ module RSMP
|
|
225
225
|
def process_status_subcribe message
|
226
226
|
log "Received #{message.type}", message: message, level: :log
|
227
227
|
|
228
|
-
|
229
228
|
# @status_subscriptions is organized by component/code/name, for example:
|
230
229
|
#
|
231
230
|
# {"AA+BBCCC=DDDEE002"=>{"S001"=>["number"]}}
|
@@ -234,21 +233,14 @@ module RSMP
|
|
234
233
|
# for each component, containing all the requested statuses
|
235
234
|
|
236
235
|
update_list = {}
|
237
|
-
|
238
236
|
component = message.attributes["cId"]
|
239
|
-
|
240
237
|
@status_subscriptions[component] ||= {}
|
241
238
|
update_list[component] ||= {}
|
242
|
-
|
243
|
-
subs = @status_subscriptions[component]
|
244
239
|
now = Time.now # internal timestamp
|
245
240
|
|
246
241
|
message.attributes["sS"].each do |arg|
|
247
242
|
sCI = arg["sCI"]
|
248
243
|
subcription = {interval: arg["uRt"].to_i, last_sent_at: now}
|
249
|
-
subs[sCI] ||= {}
|
250
|
-
subs[sCI][arg["n"]] = subcription
|
251
|
-
|
252
244
|
update_list[component][sCI] ||= []
|
253
245
|
update_list[component][sCI] << arg["n"]
|
254
246
|
end
|
@@ -287,11 +279,15 @@ module RSMP
|
|
287
279
|
end
|
288
280
|
end
|
289
281
|
|
290
|
-
def store_last_sent_status
|
282
|
+
def store_last_sent_status message
|
283
|
+
component_id = message.attribute('cId')
|
291
284
|
@last_status_sent ||= {}
|
292
|
-
@last_status_sent[
|
293
|
-
|
294
|
-
|
285
|
+
@last_status_sent[component_id] ||= {}
|
286
|
+
message.attribute('sS').each do |item|
|
287
|
+
sCI, n, s = item['sCI'], item['n'], item['s']
|
288
|
+
@last_status_sent[component_id][sCI] ||= {}
|
289
|
+
@last_status_sent[component_id][sCI][n] = s
|
290
|
+
end
|
295
291
|
end
|
296
292
|
|
297
293
|
def status_update_timer now
|
@@ -312,7 +308,6 @@ module RSMP
|
|
312
308
|
last_sent = fetch_last_sent_status component, code, name
|
313
309
|
if current != last_sent
|
314
310
|
should_send = true
|
315
|
-
store_last_sent_status component, code, name, current
|
316
311
|
end
|
317
312
|
else
|
318
313
|
# send at regular intervals
|
@@ -356,6 +351,7 @@ module RSMP
|
|
356
351
|
"sS"=>sS
|
357
352
|
})
|
358
353
|
send_message update
|
354
|
+
store_last_sent_status update
|
359
355
|
end
|
360
356
|
end
|
361
357
|
|
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.5.
|
4
|
+
version: 0.5.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: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
258
|
- !ruby/object:Gem::Version
|
259
259
|
version: '0'
|
260
260
|
requirements: []
|
261
|
-
rubygems_version: 3.2.
|
261
|
+
rubygems_version: 3.2.26
|
262
262
|
signing_key:
|
263
263
|
specification_version: 4
|
264
264
|
summary: RoadSide Message Protocol (RSMP) library.
|