rsmp 0.1.29 → 0.1.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c123985ef66b5f1a4b1676a01d07900d1a4ca365b93cc06a113bd0a7605679a9
4
- data.tar.gz: 5df915ef9e4e6143281ab23ffc48127a71502784e4a132691be2463285762b22
3
+ metadata.gz: d0b29c33b11951327d41c6ee7fe019d4c7fff8a9e8b7b82da4919dc2935797b4
4
+ data.tar.gz: 131fbd58b3bff50cfec9d4c90026a5485a2ffb2c84b930429b922555fa7a7037
5
5
  SHA512:
6
- metadata.gz: 8989828fa898324ce2b5dc9b0d0de2bd90ddc0ff5276ac768ae09526e3adf0728de67e87b01554f7374b25aed5884201367e4368efbaf37b3d594e4958c8ce3e
7
- data.tar.gz: 2fd22365257c3f2595fb3329cd047feaa87b9d52aa335232a3126023414bf5859950a11d778d0e8b2a6983644475c95173aa8ec0886b3018850ae156a98c6063
6
+ metadata.gz: 91c4d3d0d68f1aee82f3026ad39a3910dee30d7161fd866a45c22370cd05260bd380f6ab2c249e7aaa6fc8b1513e792c74bb0f7eec4fdd1ba636bc841d8c2a93
7
+ data.tar.gz: d15ff60e2d2df3b8b900b23da741d6eb6dba4a62a2512459caa4dab59f8a20b109131314376fb41c01112d01e6929e70135d25fa406b4a37fb831329d13bc5f0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.1.29)
4
+ rsmp (0.1.34)
5
5
  async (~> 1.28.7)
6
6
  async-io (~> 1.30.2)
7
7
  colorize (~> 0.8.1)
@@ -28,7 +28,7 @@ GEM
28
28
  builder (3.2.4)
29
29
  childprocess (3.0.0)
30
30
  colorize (0.8.1)
31
- console (1.12.0)
31
+ console (1.13.1)
32
32
  fiber-local
33
33
  contracts (0.16.0)
34
34
  cucumber (3.1.2)
data/lib/rsmp/cli.rb CHANGED
@@ -30,8 +30,8 @@ module RSMP
30
30
  end
31
31
 
32
32
  if options[:supervisors]
33
+ settings['supervisors'] = []
33
34
  options[:supervisors].split(',').each do |supervisor|
34
- settings['supervisors'] ||= []
35
35
  ip, port = supervisor.split ':'
36
36
  ip = '127.0.0.1' if ip.empty?
37
37
  port = '12111' if port.empty?
@@ -28,7 +28,7 @@ module RSMP
28
28
  @aggregated_status_bools[5] = true
29
29
  end
30
30
 
31
- def set_aggregated_status status
31
+ def set_aggregated_status status, options={}
32
32
  status = [status] if status.is_a? Symbol
33
33
  raise InvalidArgument unless status.is_a? Array
34
34
  input = status & AGGREGATED_STATUS_KEYS
@@ -36,7 +36,7 @@ module RSMP
36
36
  AGGREGATED_STATUS_KEYS.each_with_index do |key,index|
37
37
  @aggregated_status_bools[index] = status.include?(key)
38
38
  end
39
- aggrated_status_changed
39
+ aggregated_status_changed options
40
40
  end
41
41
  end
42
42
 
@@ -50,12 +50,12 @@ module RSMP
50
50
  @aggregated_status_bools[index] = on
51
51
  @aggregated_status << key if on
52
52
  end
53
- aggrated_status_changed
53
+ aggregated_status_changed
54
54
  end
55
55
  end
56
56
 
57
- def aggrated_status_changed
58
- @node.aggrated_status_changed self
57
+ def aggregated_status_changed options={}
58
+ @node.aggregated_status_changed self, options
59
59
  end
60
60
 
61
61
  def alarm code:, status:
@@ -8,7 +8,7 @@ module RSMP
8
8
  @components = {}
9
9
  end
10
10
 
11
- def aggrated_status_changed component
11
+ def aggregated_status_changed component, options={}
12
12
  end
13
13
 
14
14
  def setup_components settings
@@ -1,4 +1,4 @@
1
- class Hash
1
+ class Hash
2
2
  def deep_merge(other_hash)
3
3
  self.merge(other_hash) do |key, old, fresh|
4
4
  if old.is_a?(Hash) && fresh.is_a?(Hash)
data/lib/rsmp/proxy.rb CHANGED
@@ -528,18 +528,6 @@ module RSMP
528
528
  def version_acknowledged
529
529
  end
530
530
 
531
- def wait_for_acknowledgement original, timeout
532
- raise ArgumentError unless original
533
- wait_for(@acknowledgement_condition,timeout) do |message|
534
- if message.is_a?(MessageNotAck) && message.attributes["oMId"] == original.m_id
535
- raise RSMP::MessageRejected.new(message.attributes['rea'])
536
- end
537
- message.is_a?(MessageAck) && message.attributes["oMId"] == original.m_id
538
- end
539
- rescue Async::TimeoutError
540
- raise RSMP::TimeoutError.new("Acknowledgement for #{original.type} #{original.m_id} not received within #{timeout}s")
541
- end
542
-
543
531
  def node
544
532
  raise 'Must be overridden'
545
533
  end
@@ -547,5 +535,29 @@ module RSMP
547
535
  def author
548
536
  node.site_id
549
537
  end
538
+
539
+ def wait_for_acknowledgement parent_task, options={}, m_id
540
+ collect(parent_task,options.merge({
541
+ type: ['MessageAck','MessageNotAck'],
542
+ num: 1
543
+ })) do |message|
544
+ if message.is_a?(MessageNotAck)
545
+ if message.attribute('oMId') == m_id
546
+ # set result to an exception, but don't raise it.
547
+ # this will be returned by the task and stored as the task result
548
+ # when the parent task call wait() on the task, the exception
549
+ # will be raised in the parent task, and caught by rspec.
550
+ # rspec will then show the error and record the test as failed
551
+ m_id_short = RSMP::Message.shorten_m_id m_id, 8
552
+ result = RSMP::MessageRejected.new "Aggregated status request #{m_id_short} was rejected: #{message.attribute('rea')}"
553
+ next true # done, no more messages wanted
554
+ end
555
+ elsif message.is_a?(MessageAck)
556
+ next true if message.attribute('oMId') == m_id
557
+ end
558
+ false
559
+ end
560
+ end
561
+
550
562
  end
551
563
  end
data/lib/rsmp/site.rb CHANGED
@@ -14,6 +14,7 @@ module RSMP
14
14
  super options
15
15
  @proxies = []
16
16
  @sleep_condition = Async::Notification.new
17
+ @proxies_condition = Async::Notification.new
17
18
  end
18
19
 
19
20
  def site_id
@@ -30,7 +31,7 @@ module RSMP
30
31
  'sxl' => 'tlc',
31
32
  'sxl_version' => '1.0.15',
32
33
  'intervals' => {
33
- 'timer_' => 0.1,
34
+ 'timer' => 0.1,
34
35
  'watchdog' => 1,
35
36
  'reconnect' => 0.1
36
37
  },
@@ -45,7 +46,6 @@ module RSMP
45
46
  }
46
47
 
47
48
  @site_settings = defaults.deep_merge options[:site_settings]
48
- pp @site_settings
49
49
  check_sxl_version
50
50
  setup_components @site_settings['components']
51
51
  end
@@ -75,9 +75,9 @@ module RSMP
75
75
  SupervisorProxy.new settings
76
76
  end
77
77
 
78
- def aggrated_status_changed component
78
+ def aggregated_status_changed component, options={}
79
79
  @proxies.each do |proxy|
80
- proxy.send_aggregated_status component
80
+ proxy.send_aggregated_status component, options
81
81
  end
82
82
  end
83
83
 
@@ -92,9 +92,11 @@ module RSMP
92
92
  archive: @archive
93
93
  })
94
94
  @proxies << proxy
95
+ @proxies_condition.signal
95
96
  run_site_proxy task, proxy
96
97
  ensure
97
98
  @proxies.delete proxy
99
+ @proxies_condition.signal
98
100
  end
99
101
 
100
102
  def run_site_proxy task, proxy
@@ -143,5 +145,19 @@ module RSMP
143
145
  end
144
146
  end
145
147
 
148
+ def wait_for_supervisor ip, timeout
149
+ supervisor = find_supervisor ip
150
+ return supervisor if supervisor
151
+ wait_for(@proxy_condition,timeout) { find_supervisor ip }
152
+ rescue Async::TimeoutError
153
+ raise RSMP::TimeoutError.new "Supervisor '#{ip}' did not connect within #{timeout}s"
154
+ end
155
+
156
+ def find_supervisor ip
157
+ @proxies.each do |supervisor|
158
+ return supervisor if ip == :any || supervisor.ip == ip
159
+ end
160
+ nil
161
+ end
146
162
  end
147
163
  end
@@ -94,7 +94,7 @@ module RSMP
94
94
  if options[:collect]
95
95
  result = nil
96
96
  task = @task.async do |task|
97
- wait_for_aggregated_status task, options[:collect]
97
+ wait_for_aggregated_status task, options[:collect], m_id
98
98
  end
99
99
  send_message message, validate: options[:validate]
100
100
  return message, task.wait
@@ -134,7 +134,7 @@ module RSMP
134
134
  acknowledge message
135
135
  end
136
136
 
137
- def aggrated_status_changed component
137
+ def aggregated_status_changed component, options={}
138
138
  @supervisor.aggregated_status_changed self, component
139
139
  end
140
140
 
@@ -2,24 +2,6 @@
2
2
  module RSMP
3
3
  module SiteProxyWait
4
4
 
5
- def wait_for_status_updates parent_task, options={}, &send_block
6
- send_while_collecting parent_task, send_block do |task, m_id|
7
- collect_status_updates_or_responses task, 'StatusUpdate', options, m_id
8
- end
9
- end
10
-
11
- def wait_for_status_responses parent_task, options={}, &send_block
12
- send_while_collecting parent_task, send_block do |task, m_id|
13
- collect_status_updates_or_responses task, 'StatusResponse', options, m_id
14
- end
15
- end
16
-
17
- def wait_for_command_responses parent_task, options={}, &send_block
18
- send_while_collecting parent_task, send_block do |task, m_id|
19
- collect_command_responses task, options, m_id
20
- end
21
- end
22
-
23
5
  def wait_for_alarm parent_task, options={}
24
6
  matching_alarm = nil
25
7
  message = collect(parent_task,options.merge(type: "Alarm", with_message: true, num: 1)) do |message|
@@ -161,24 +143,7 @@ module RSMP
161
143
  true
162
144
  end
163
145
 
164
- def send_while_collecting parent_task, send_block, &collect_block
165
- m_id = RSMP::Message.make_m_id # make message id so we can start waiting for it
166
-
167
- # wait for command responses in an async task
168
- task = parent_task.async do |task|
169
- collect_block.call task, m_id
170
- rescue StandardError => e
171
- notify_error e, level: :internal
172
- end
173
-
174
- # call block, it should send command request using the given m_id
175
- send_block.call m_id
176
-
177
- # wait for the response and return it, raise exception if NotAck received, it it timed out
178
- task.wait
179
- end
180
-
181
- def wait_for_aggregated_status parent_task, options={}
146
+ def wait_for_aggregated_status parent_task, options, m_id
182
147
  collect(parent_task,options.merge({
183
148
  type: ['AggregatedStatus','MessageNotAck'],
184
149
  num: 1
@@ -110,7 +110,7 @@ module RSMP
110
110
  end
111
111
 
112
112
  def reconnect_delay
113
- interval = @site_settings['intervals']['watchdog']
113
+ interval = @site_settings['intervals']['reconnect']
114
114
  log "Waiting #{interval} seconds before trying to reconnect", level: :info
115
115
  @task.sleep interval
116
116
  end
@@ -123,15 +123,28 @@ module RSMP
123
123
  @version_determined = true
124
124
  end
125
125
 
126
- def send_aggregated_status component
126
+ def send_aggregated_status component, options={}
127
+ m_id = options[:m_id] || RSMP::Message.make_m_id
127
128
  message = AggregatedStatus.new({
128
129
  "aSTS" => clock.to_s,
129
130
  "cId" => component.c_id,
130
131
  "fP" => 'NormalControl',
131
132
  "fS" => nil,
132
- "se" => component.aggregated_status_bools
133
+ "se" => component.aggregated_status_bools,
134
+ "mId" => m_id
133
135
  })
134
- send_message message
136
+
137
+ if options[:collect]
138
+ result = nil
139
+ task = @task.async do |task|
140
+ wait_for_acknowledgement task, options[:collect], m_id
141
+ end
142
+ send_message message, validate: options[:validate]
143
+ return message, task.wait
144
+ else
145
+ send_message message, validate: options[:validate]
146
+ message
147
+ end
135
148
  end
136
149
 
137
150
  def process_aggregated_status message
data/lib/rsmp/tlc.rb CHANGED
@@ -69,7 +69,7 @@ module RSMP
69
69
  group.move pos
70
70
  end
71
71
  if pos == 0
72
- aggrated_status_changed
72
+ aggregated_status_changed
73
73
  end
74
74
  end
75
75
 
@@ -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]['interval'] || 1
801
+ @interval = options[:site_settings]['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
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.1.29"
2
+ VERSION = "0.1.34"
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.29
4
+ version: 0.1.34
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-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async