rsmp 0.1.17 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.1.17"
2
+ VERSION = "0.1.19"
3
3
  end
@@ -1,10 +1,11 @@
1
1
  # Helper for waiting for an Async condition using a block
2
2
 
3
3
  module RSMP
4
- class Wait
4
+ module Wait
5
5
 
6
- def self.wait_for task, condition, timeout, &block
7
- task.with_timeout(timeout) do
6
+ def wait_for condition, timeout, &block
7
+ raise RuntimeError.new("Can't wait for state because task is stopped") unless @task.running?
8
+ @task.with_timeout(timeout) do
8
9
  while task.running? do
9
10
  value = condition.wait
10
11
  result = yield value
@@ -13,5 +14,150 @@ module RSMP
13
14
  end
14
15
  end
15
16
 
17
+ def capture_status_updates_or_responses task, type, options, m_id
18
+ task.annotate "wait for status update/response"
19
+ want = convert_status_list options[:status_list]
20
+ result = {}
21
+ # wait for a status update
22
+ item = @archive.capture(task,options.merge({
23
+ type: [type,'MessageNotAck'],
24
+ num: 1
25
+ })) do |item|
26
+ message = item[:message]
27
+ if message.is_a?(MessageNotAck) && message.attribute('oMId') == m_id
28
+ # set result to an exception, but don't raise it.
29
+ # this will be returned by the task and stored as the task result
30
+ # when the parent task call wait() on the task, the exception
31
+ # will be raised in the parent task, and caught by rspec.
32
+ # rspec will then show the error and record the test as failed
33
+ m_id_short = RSMP::Message.shorten_m_id m_id, 8
34
+ result = RSMP::MessageRejected.new "Status request #{m_id_short} was rejected: #{message.attribute('rea')}"
35
+ next true # done, no more messages wanted
36
+ end
37
+ found = []
38
+ # look through querues
39
+ want.each_with_index do |query,i|
40
+ # look through status items in message
41
+ item[:message].attributes['sS'].each do |input|
42
+ ok = status_match? query, input
43
+ if ok
44
+ result[query] = input
45
+ found << i # record which queries where matched succesfully
46
+ end
47
+ end
48
+ end
49
+ # remove queries that where matched
50
+ found.sort.reverse.each do |i|
51
+ want.delete_at i
52
+ end
53
+ want.empty? # any queries left to match?
54
+ end
55
+ result
56
+ rescue Async::TimeoutError
57
+ type_str = {'StatusUpdate'=>'update', 'StatusResponse'=>'response'}[type]
58
+ raise RSMP::TimeoutError.new "Did not received status #{type_str} in reply to #{m_id} within #{options[:timeout]}s"
59
+ end
60
+
61
+ def wait_for_status_updates_or_responses parent_task, type, options={}, &block
62
+ raise ArgumentError.new("component argument is missing") unless options[:component]
63
+ raise ArgumentError.new("status_list argument is missing") unless options[:status_list]
64
+ m_id = RSMP::Message.make_m_id # make message id so we can start waiting for it
65
+
66
+ # wait for command responses in an async task
67
+ task = parent_task.async do |task|
68
+ capture_status_updates_or_responses task, type, options, m_id
69
+ end
70
+
71
+ # call block, it should send command request using the given m_id
72
+ yield m_id
73
+
74
+ # wait for the response and return it, raise exception if NotAck received, it it timed out
75
+ task.wait
76
+ end
77
+
78
+ def wait_for_status_updates parent_task, options={}, &block
79
+ wait_for_status_updates_or_responses parent_task, 'StatusUpdate', options, &block
80
+ end
81
+
82
+ def wait_for_status_responses parent_task, options={}, &block
83
+ wait_for_status_updates_or_responses parent_task, 'StatusResponse', options, &block
84
+ end
85
+
86
+ def process_command_response message
87
+ log "Received #{message.type}", message: message, level: :log
88
+ acknowledge message
89
+ end
90
+
91
+ def command_match? query, item
92
+ return false if query[:sCI] && query[:sCI] != item['sCI']
93
+ return false if query[:n] && query[:n] != item['n']
94
+ if query[:s].is_a? Regexp
95
+ return false if query[:v] && item['v'] !~ query[:v]
96
+ else
97
+ return false if query[:v] && item['v'] != query[:v]
98
+ end
99
+ true
100
+ end
101
+
102
+ def capture_command_responses parent_task, type, options, m_id
103
+ task.annotate "wait for command response"
104
+ want = options[:command_list].clone
105
+ result = {}
106
+ item = @archive.capture(parent_task,options.merge({
107
+ type: [type,'MessageNotAck'],
108
+ num: 1
109
+ })) do |item|
110
+ message = item[:message]
111
+ if message.is_a?(MessageNotAck) && message.attribute('oMId') == m_id
112
+ # and message.attribute('oMId')==m_id
113
+ # set result to an exception, but don't raise it.
114
+ # this will be returned by the task and stored as the task result
115
+ # when the parent task call wait() on the task, the exception
116
+ # will be raised in the parent task, and caught by rspec.
117
+ # rspec will then show the error and record the test as failed
118
+ m_id_short = RSMP::Message.shorten_m_id m_id, 8
119
+ result = RSMP::MessageRejected.new "Command request #{m_id_short} was rejected: #{message.attribute('rea')}"
120
+ next true # done, no more messages wanted
121
+ end
122
+
123
+ found = []
124
+ # look through querues
125
+ want.each_with_index do |query,i|
126
+ # look through items in message
127
+ item[:message].attributes['rvs'].each do |input|
128
+ ok = command_match? query, input
129
+ if ok
130
+ result[query] = input
131
+ found << i # record which queries where matched succesfully
132
+ end
133
+ end
134
+ end
135
+ # remove queries that where matched
136
+ found.sort.reverse.each do |i|
137
+ want.delete_at i
138
+ end
139
+ want.empty? # any queries left to match?
140
+ end
141
+ result
142
+ rescue Async::TimeoutError
143
+ raise RSMP::TimeoutError.new "Did not receive command response to #{m_id} within #{options[:timeout]}s"
144
+ end
145
+
146
+ def wait_for_command_responses parent_task, options={}, &block
147
+ raise ArgumentError.new("component argument is missing") unless options[:component]
148
+ raise ArgumentError.new("command_list argument is missing") unless options[:command_list]
149
+ m_id = RSMP::Message.make_m_id # make message id so we can start waiting for it
150
+
151
+ # wait for command responses in an async task
152
+ task = parent_task.async do |task|
153
+ capture_command_responses task, 'CommandResponse', options, m_id
154
+ end
155
+
156
+ # call block, it should send command request using the given m_id
157
+ yield m_id
158
+
159
+ # wait for the response and return it, raise exception if NotAck received, it it timed out
160
+ task.wait
161
+ end
16
162
  end
17
163
  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.17
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -200,6 +200,7 @@ files:
200
200
  - config/site.yaml
201
201
  - config/supervisor.yaml
202
202
  - config/tlc.yaml
203
+ - documentation/classes.md
203
204
  - exe/rsmp
204
205
  - lib/rsmp.rb
205
206
  - lib/rsmp/alarm.rb
@@ -219,7 +220,6 @@ files:
219
220
  - lib/rsmp/site_base.rb
220
221
  - lib/rsmp/site_proxy.rb
221
222
  - lib/rsmp/supervisor.rb
222
- - lib/rsmp/supervisor_base.rb
223
223
  - lib/rsmp/supervisor_proxy.rb
224
224
  - lib/rsmp/tlc.rb
225
225
  - lib/rsmp/version.rb
@@ -274,7 +274,10 @@ files:
274
274
  - lib/rsmp_schema/schema/tlc/commands/M0017.json
275
275
  - lib/rsmp_schema/schema/tlc/commands/M0018.json
276
276
  - lib/rsmp_schema/schema/tlc/commands/M0019.json
277
+ - lib/rsmp_schema/schema/tlc/commands/M0020.json
278
+ - lib/rsmp_schema/schema/tlc/commands/M0021.json
277
279
  - lib/rsmp_schema/schema/tlc/commands/M0103.json
280
+ - lib/rsmp_schema/schema/tlc/commands/M0104.json
278
281
  - lib/rsmp_schema/schema/tlc/commands/command_requests.json
279
282
  - lib/rsmp_schema/schema/tlc/commands/command_responses.json
280
283
  - lib/rsmp_schema/schema/tlc/commands/commands.json
@@ -307,10 +310,13 @@ files:
307
310
  - lib/rsmp_schema/schema/tlc/statuses/S0027.json
308
311
  - lib/rsmp_schema/schema/tlc/statuses/S0028.json
309
312
  - lib/rsmp_schema/schema/tlc/statuses/S0029.json
313
+ - lib/rsmp_schema/schema/tlc/statuses/S0030.json
314
+ - lib/rsmp_schema/schema/tlc/statuses/S0031.json
310
315
  - lib/rsmp_schema/schema/tlc/statuses/S0091.json
311
316
  - lib/rsmp_schema/schema/tlc/statuses/S0092.json
312
317
  - lib/rsmp_schema/schema/tlc/statuses/S0095.json
313
318
  - lib/rsmp_schema/schema/tlc/statuses/S0096.json
319
+ - lib/rsmp_schema/schema/tlc/statuses/S0097.json
314
320
  - lib/rsmp_schema/schema/tlc/statuses/S0201.json
315
321
  - lib/rsmp_schema/schema/tlc/statuses/S0202.json
316
322
  - lib/rsmp_schema/schema/tlc/statuses/S0203.json
@@ -1,10 +0,0 @@
1
- # Things shared between sites and site proxies
2
-
3
- module RSMP
4
- module SupervisorBase
5
-
6
- def initialize_supervisor
7
- end
8
-
9
- end
10
- end