rsmp 0.10.1 → 0.11.3
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/lib/rsmp/collect/alarm_collector.rb +15 -1
- data/lib/rsmp/collect/collector.rb +73 -6
- data/lib/rsmp/collect/state_collector.rb +95 -4
- data/lib/rsmp/logger.rb +2 -3
- data/lib/rsmp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 429ca780c80b9fd2e2a320256f76a8d1ed37bc6f2ca2045cbebb40c537c6888a
|
4
|
+
data.tar.gz: 9cdb92a02f59e8ee2dd82a60e64e9b097dd6039ef2ca0e331bfe43a8e63a44e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e87d762b71abb1e108b5045c05d97d024b193d683882444851e34af6dc34facffff91b6017fca83309a6f46eeec301f22530d0fd907526f417ce9b3d3b7eef
|
7
|
+
data.tar.gz: fde8b4459dc7cb15a08d2fa2a19584f0a47303f4591c76b390957f7b018f5704205be125d567b7648865a011a239fa52a460a9663b7b03b1daf7f5b0648eb24f
|
data/Gemfile.lock
CHANGED
@@ -9,12 +9,20 @@ module RSMP
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
+
# match alarm attributes
|
12
13
|
def type_match? message
|
13
14
|
return false if super(message) == false
|
14
15
|
|
15
16
|
# match fixed attributes
|
16
17
|
%w{aCId aSp ack aS sS cat pri}.each do |key|
|
17
|
-
|
18
|
+
want = @query[key]
|
19
|
+
got = message.attribute(key)
|
20
|
+
case want
|
21
|
+
when Regexp
|
22
|
+
return false if got !~ want
|
23
|
+
when String
|
24
|
+
return false if got != want
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
# match rvs items
|
@@ -31,5 +39,11 @@ module RSMP
|
|
31
39
|
end
|
32
40
|
true
|
33
41
|
end
|
42
|
+
|
43
|
+
# return a string that describes what we're collecting
|
44
|
+
def describe_query
|
45
|
+
"#{describe_num_and_type} #{ {component: @options[:component]}.merge(@query).compact }"
|
46
|
+
end
|
47
|
+
|
34
48
|
end
|
35
49
|
end
|
@@ -134,17 +134,18 @@ module RSMP
|
|
134
134
|
# Start collection and return immediately
|
135
135
|
# You can later use wait() to wait for completion
|
136
136
|
def start &block
|
137
|
-
raise RuntimeError.new("Can't
|
137
|
+
raise RuntimeError.new("Can't start collectimng unless ready (currently #{@status})") unless ready?
|
138
138
|
@block = block
|
139
139
|
raise ArgumentError.new("Num, timeout or block must be provided") unless @options[:num] || @options[:timeout] || @block
|
140
140
|
reset
|
141
141
|
@status = :collecting
|
142
|
+
log_start
|
142
143
|
@notifier.add_listener self if @notifier
|
143
144
|
end
|
144
145
|
|
145
146
|
# Build a string describing how how progress reached before timeout
|
146
147
|
def describe_progress
|
147
|
-
str = "#{@title.capitalize} collection "
|
148
|
+
str = "#{identifier}: #{@title.capitalize} collection "
|
148
149
|
str << "in response to #{@options[:m_id]} " if @options[:m_id]
|
149
150
|
str << "didn't complete within #{@options[:timeout]}s, "
|
150
151
|
str << "reached #{@messages.size}/#{@options[:num]}"
|
@@ -167,7 +168,13 @@ module RSMP
|
|
167
168
|
def notify message
|
168
169
|
raise ArgumentError unless message
|
169
170
|
raise RuntimeError.new("can't process message when status is :#{@status}, title: #{@title}, desc: #{describe}") unless ready? || collecting?
|
170
|
-
perform_match message
|
171
|
+
if perform_match message
|
172
|
+
if done?
|
173
|
+
complete
|
174
|
+
else
|
175
|
+
incomplete
|
176
|
+
end
|
177
|
+
end
|
171
178
|
@status
|
172
179
|
end
|
173
180
|
|
@@ -178,6 +185,7 @@ module RSMP
|
|
178
185
|
def perform_match message
|
179
186
|
return false if reject_not_ack(message)
|
180
187
|
return false unless type_match?(message)
|
188
|
+
#@notifier.log "#{identifier}: Looking at #{message.type} #{message.m_id_short}", level: :collect
|
181
189
|
if @block
|
182
190
|
status = [@block.call(message)].flatten
|
183
191
|
return unless collecting?
|
@@ -185,7 +193,6 @@ module RSMP
|
|
185
193
|
else
|
186
194
|
keep message
|
187
195
|
end
|
188
|
-
complete if done?
|
189
196
|
end
|
190
197
|
|
191
198
|
# Have we collected the required number of messages?
|
@@ -198,6 +205,12 @@ module RSMP
|
|
198
205
|
def complete
|
199
206
|
@status = :ok
|
200
207
|
do_stop
|
208
|
+
log_complete
|
209
|
+
end
|
210
|
+
|
211
|
+
# called when we received a message, but are not done yet
|
212
|
+
def incomplete
|
213
|
+
log_incomplete
|
201
214
|
end
|
202
215
|
|
203
216
|
# Remove ourself as a listener, so we don't receive message notifications anymore,
|
@@ -225,14 +238,14 @@ module RSMP
|
|
225
238
|
return unless message
|
226
239
|
klass = message.class.name.split('::').last
|
227
240
|
return unless @options[:type] == nil || [@options[:type]].flatten.include?(klass)
|
228
|
-
@notifier.log "
|
241
|
+
@notifier.log "#{identifier}: cancelled due to schema error in #{klass} #{message.m_id_short}", level: :debug
|
229
242
|
cancel error
|
230
243
|
end
|
231
244
|
|
232
245
|
# Cancel if we received e notificaiton about a disconnect
|
233
246
|
def notify_disconnect error, options
|
234
247
|
return unless @options.dig(:cancel,:disconnect)
|
235
|
-
@notifier.log "
|
248
|
+
@notifier.log "#{identifier}: cancelled due to a connection error: #{error.to_s}", level: :debug
|
236
249
|
cancel error
|
237
250
|
end
|
238
251
|
|
@@ -265,5 +278,59 @@ module RSMP
|
|
265
278
|
end
|
266
279
|
true
|
267
280
|
end
|
281
|
+
|
282
|
+
# return a string describing the types of messages we're collecting
|
283
|
+
def describe_types
|
284
|
+
[@options[:type]].flatten.join('/')
|
285
|
+
end
|
286
|
+
|
287
|
+
# return a string that describes whe number of messages, and type of message we're collecting
|
288
|
+
def describe_num_and_type
|
289
|
+
if @options[:num] && @options[:num] > 1
|
290
|
+
"#{@options[:num]} #{describe_types}s"
|
291
|
+
else
|
292
|
+
describe_types
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
# return a string that describes the attributes that we're looking for
|
297
|
+
def describe_query
|
298
|
+
h = {component: @options[:component]}.compact
|
299
|
+
if h.empty?
|
300
|
+
describe_num_and_type
|
301
|
+
else
|
302
|
+
"#{describe_num_and_type} #{h}"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
# return a string that describe how many many messages have been collected
|
307
|
+
def describe_progress
|
308
|
+
if @options[:num]
|
309
|
+
"#{@messages.size} of #{@options[:num]} message#{'s' if @messages.size!=1} collected"
|
310
|
+
else
|
311
|
+
"#{@messages.size} message#{'s' if @messages.size!=1} collected"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# log when we start collecting
|
316
|
+
def log_start
|
317
|
+
@notifier.log "#{identifier}: Waiting for #{describe_query}".strip, level: :collect
|
318
|
+
end
|
319
|
+
|
320
|
+
# log current progress
|
321
|
+
def log_incomplete
|
322
|
+
@notifier.log "#{identifier}: #{describe_progress}", level: :collect
|
323
|
+
end
|
324
|
+
|
325
|
+
# log when we end collecting
|
326
|
+
def log_complete
|
327
|
+
@notifier.log "#{identifier}: Done", level: :collect
|
328
|
+
end
|
329
|
+
|
330
|
+
# get a short id in hex format, identifying ourself
|
331
|
+
def identifier
|
332
|
+
"Collect #{self.object_id.to_s(16)}"
|
333
|
+
end
|
334
|
+
|
268
335
|
end
|
269
336
|
end
|
@@ -97,8 +97,8 @@ module RSMP
|
|
97
97
|
matched = query.perform_match(item,message,@block)
|
98
98
|
return unless collecting?
|
99
99
|
if matched != nil
|
100
|
-
type = {true=>'match',false=>'mismatch'}[matched]
|
101
|
-
|
100
|
+
#type = {true=>'match',false=>'mismatch'}[matched]
|
101
|
+
#@notifier.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
|
102
102
|
if matched == true
|
103
103
|
query.keep message, item
|
104
104
|
elsif matched == false
|
@@ -107,8 +107,6 @@ module RSMP
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
|
-
complete if done?
|
111
|
-
@notifier.log "#{@title.capitalize} collect reached #{summary}", level: :debug
|
112
110
|
end
|
113
111
|
|
114
112
|
# don't collect anything. Query will collect them instead
|
@@ -118,5 +116,98 @@ module RSMP
|
|
118
116
|
def describe
|
119
117
|
@queries.map {|q| q.want.to_s }
|
120
118
|
end
|
119
|
+
|
120
|
+
# return a string that describes the attributes that we're looking for
|
121
|
+
def describe_query
|
122
|
+
"#{super} matching #{query_want_hash.to_s}"
|
123
|
+
end
|
124
|
+
|
125
|
+
# return a hash that describe the status of all queries
|
126
|
+
def progress_hash
|
127
|
+
h = {}
|
128
|
+
@queries.each do |query|
|
129
|
+
want = query.want
|
130
|
+
if want['cCI']
|
131
|
+
cCI = want['cCI']
|
132
|
+
h[cCI] ||= {}
|
133
|
+
cO = h['cO']
|
134
|
+
n = h['n']
|
135
|
+
v = h['v']
|
136
|
+
h[cCI][cO] ||= {}
|
137
|
+
h[cCI][cO][n] = v
|
138
|
+
elsif want['sCI']
|
139
|
+
sCI = want['sCI']
|
140
|
+
h[sCI] ||= {}
|
141
|
+
n = want['n']
|
142
|
+
s = want['s']
|
143
|
+
if query.got && query.got['s']
|
144
|
+
h[sCI][n] = { {s=>query.got['s']} => query.done? }
|
145
|
+
else
|
146
|
+
h[sCI][n] = {s=>:anything}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
h
|
151
|
+
end
|
152
|
+
|
153
|
+
# return a string that describe how many many messages have been collected
|
154
|
+
def describe_progress
|
155
|
+
num_queries = @queries.size
|
156
|
+
num_matched = @queries.count { |query| query.done? }
|
157
|
+
".. Matched #{num_matched}/#{num_queries} with #{progress_hash.to_s}"
|
158
|
+
end
|
159
|
+
|
160
|
+
def query_want_hash
|
161
|
+
h = {}
|
162
|
+
@queries.each do |query|
|
163
|
+
item = query.want
|
164
|
+
if item['cCI']
|
165
|
+
cCI = item['cCI']
|
166
|
+
h[cCI] ||= {}
|
167
|
+
cO = item['cO']
|
168
|
+
h[cCI][cO] ||= {}
|
169
|
+
n = item['n']
|
170
|
+
v = item['v']
|
171
|
+
h[cCI][cO][n] = v || :any
|
172
|
+
elsif item['sCI']
|
173
|
+
sCI = item['sCI']
|
174
|
+
h[sCI] ||= {}
|
175
|
+
n = item['n']
|
176
|
+
s = item['s']
|
177
|
+
h[sCI][n] = s || :any
|
178
|
+
end
|
179
|
+
end
|
180
|
+
h
|
181
|
+
end
|
182
|
+
|
183
|
+
# return a hash that describe the end result
|
184
|
+
def query_got_hash
|
185
|
+
h = {}
|
186
|
+
@queries.each do |query|
|
187
|
+
want = query.want
|
188
|
+
got = query.got
|
189
|
+
if got['cCI']
|
190
|
+
cCI = want['cCI']
|
191
|
+
h[cCI] ||= {}
|
192
|
+
cO = want['cO']
|
193
|
+
h[cCI][cO] ||= {}
|
194
|
+
n = want['n']
|
195
|
+
v = got['v']
|
196
|
+
h[cCI][cO][n] = v
|
197
|
+
elsif want['sCI']
|
198
|
+
sCI = want['sCI']
|
199
|
+
h[sCI] ||= {}
|
200
|
+
n = want['n']
|
201
|
+
s = got['s']
|
202
|
+
h[sCI][n] = s
|
203
|
+
end
|
204
|
+
end
|
205
|
+
h
|
206
|
+
end
|
207
|
+
|
208
|
+
# log when we end collecting
|
209
|
+
def log_complete
|
210
|
+
@notifier.log "#{identifier}: Completed with #{query_got_hash.to_s}", level: :collect
|
211
|
+
end
|
121
212
|
end
|
122
213
|
end
|
data/lib/rsmp/logger.rb
CHANGED
@@ -135,12 +135,11 @@ module RSMP
|
|
135
135
|
colors = {
|
136
136
|
'info' => 'white',
|
137
137
|
'log' => 'light_blue',
|
138
|
-
'test' => 'light_magenta',
|
139
138
|
'statistics' => 'light_black',
|
140
|
-
'not_acknowledged' => 'cyan',
|
141
139
|
'warning' => 'light_yellow',
|
142
140
|
'error' => 'red',
|
143
|
-
'debug' => 'light_black'
|
141
|
+
'debug' => 'light_black',
|
142
|
+
'collect' => 'light_black'
|
144
143
|
}
|
145
144
|
colors.merge! @settings["color"] if @settings["color"].is_a?(Hash)
|
146
145
|
if colors[level.to_s]
|
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.
|
4
|
+
version: 0.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Tin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|