rsmp 0.19.3 → 0.19.4

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: 8702928138cf433b9d0744b92af2d9e535292342ba5e18bd22fcc3985f341a11
4
- data.tar.gz: 27a689a67e585f1da3c40feeda85468f9d7a7306c19437be156d4162b55f7024
3
+ metadata.gz: 8f188c0b34f0877ae12b9948d0784b5e1f3f2a44e52e11995ba2adf12e299f4a
4
+ data.tar.gz: a2b8097b5d73897840d093ce8fbf1690bd7c8bee1e1a2102a605565d12c22ddb
5
5
  SHA512:
6
- metadata.gz: 91b20a0cee412984bd269083fd67864175c0c0c1d5627cd9003369cc63e1413c97e9c3b49c135e7328f372fcec9d95cd1f8c0edc54bf692400c4a20109d66137
7
- data.tar.gz: dadfc9ba3cfba8ddd0dc82318299a78ef4f7101ff9708e61d3bbe1b54280aac42f9d5111bf9e102dbf8a0b4f1d0c401dbc4471f55b0a760713ab4374be83e781
6
+ metadata.gz: '04258e76affbf8e3def87f12edaed2bde5ccf6bf36dfba175c47488082bfaa1e4e8e9c0c8c749295b098e73a39b0ca28bcb0ed4d0e0c90c054486f29a8e0d02d'
7
+ data.tar.gz: 516d8818dc1737648afdb7cb1496d3c96ea2e9870dc61d185d3bb5a40897ea85ecb930cfece5e5f8dbd1bf8abaf6a62244c5f6188498b082e4c896c02551b190
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.19.3)
4
+ rsmp (0.19.4)
5
5
  async (~> 1.30.3)
6
6
  async-io (~> 1.34.3)
7
7
  colorize (~> 0.8.1)
@@ -1,33 +1,55 @@
1
1
  module RSMP
2
- # class that tracks the state of an alarm
2
+
3
+ # The state of an alarm on a component.
4
+ # The alarm state is for a particular alarm code,
5
+ # a component typically have an alarm state for each
6
+ # alarm code that is defined for the component type.
7
+
3
8
  class AlarmState
4
9
  attr_reader :component_id, :code, :acknowledged, :suspended, :active, :timestamp, :category, :priority, :rvs
5
10
 
6
- def initialize component:, code:
11
+ def self.create_from_message component, message
12
+ self.new(
13
+ component: component,
14
+ code: message.attribute("aCId"),
15
+ timestamp: RSMP::Clock.parse(message.attribute('aTs')),
16
+ acknowledged: message.attribute('ack') == 'Acknowledged',
17
+ suspended: message.attribute('aS') == 'suspended',
18
+ active: message.attribute('sS') == 'Active',
19
+ category: message.attribute('cat'),
20
+ priority: message.attribute('pri').to_i,
21
+ rvs: message.attribute('rvs')
22
+ )
23
+ end
24
+
25
+ def initialize component:, code:,
26
+ suspended: false, acknowledged: false, active: false, timestamp: nil,
27
+ category: 'D', priority: 2, rvs: []
7
28
  @component = component
8
29
  @component_id = component.c_id
9
30
  @code = code
10
- @suspended = false
11
- @acknowledged = false
12
- @suspended = false
13
- @active = false
14
- @timestamp = nil
15
- @category = 'D'
16
- @priority = 2
17
- @rvs = []
31
+ @suspended = !!suspended
32
+ @acknowledged = !!acknowledged
33
+ @active = !!active
34
+ @timestamp = timestamp
35
+ @category = category || 'D'
36
+ @priority = priority || 2
37
+ @rvs = rvs
38
+
39
+ update_timestamp unless @timestamp
18
40
  end
19
41
 
20
42
  def to_hash
21
43
  {
22
- 'cId' => component_id,
23
- 'aCId' => code,
24
- 'aTs' => Clock.to_s(timestamp),
25
- 'ack' => (acknowledged ? 'Acknowledged' : 'notAcknowledged'),
26
- 'sS' => (suspended ? 'suspended' : 'notSuspended'),
27
- 'aS' => (active ? 'Active' : 'inActive'),
28
- 'cat' => category,
29
- 'pri' => priority.to_s,
30
- 'rvs' => rvs
44
+ 'cId' => @component_id,
45
+ 'aCId' => @code,
46
+ 'aTs' => Clock.to_s(@timestamp),
47
+ 'ack' => (@acknowledged ? 'Acknowledged' : 'notAcknowledged'),
48
+ 'sS' => (@suspended ? 'suspended' : 'notSuspended'),
49
+ 'aS' => (@active ? 'Active' : 'inActive'),
50
+ 'cat' => @category,
51
+ 'pri' => @priority.to_s,
52
+ 'rvs' => @rvs
31
53
  }
32
54
  end
33
55
 
@@ -65,42 +87,31 @@ module RSMP
65
87
  end
66
88
 
67
89
  def update_timestamp
68
- @timestamp = @component.node.clock.now
69
- end
70
-
71
- def to_message specialization:
72
- Alarm.new(
73
- 'cId' => @component_id,
74
- 'aSp' => specialization,
75
- 'aCId' => @code,
76
- 'aTs' => Clock.to_s(@timestamp),
77
- 'ack' => (@acknowledged ? 'Acknowledged' : 'notAcknowledged'),
78
- 'sS' => (@suspended ? 'suspended' : 'notSuspended'),
79
- 'aS' => (@active ? 'Active' : 'inActive'),
80
- 'cat' => @category,
81
- 'pri' => @priority.to_s,
82
- 'rvs' => @rvs
83
- )
90
+ @timestamp = @component.now
84
91
  end
85
92
 
86
93
  def differ_from_message? message
87
- return true if @timestamp != message.attribute('aTs')
88
- return true if message.attribute('ack') && @acknowledged != (message.attribute('ack') == 'True')
89
- return true if message.attribute('sS') && @suspended != (message.attribute('sS') == 'True')
90
- return true if message.attribute('aS') && @active != (message.attribute('aS') == 'True')
94
+ return true if RSMP::Clock.to_s(@timestamp) != message.attribute('aTs')
95
+ return true if message.attribute('ack') && @acknowledged != (message.attribute('ack') == 'Acknowledged')
96
+ return true if message.attribute('sS') && @suspended != (message.attribute('sS') == 'suspended')
97
+ return true if message.attribute('aS') && @active != (message.attribute('aS') == 'Active')
91
98
  return true if message.attribute('cat') && @category != message.attribute('cat')
92
99
  return true if message.attribute('pri') && @priority != message.attribute('pri').to_i
93
100
  #return true @rvs = message.attribute('rvs')
94
101
  false
95
102
  end
96
103
 
104
+ def message_is_older? message
105
+ Time.parse(message.attribute('aTs')) < @timestamp
106
+ end
107
+
97
108
  # update from rsmp message
98
109
  # component id, alarm code and specialization are not updated
99
110
  def update_from_message message
100
111
  unless differ_from_message? message
101
112
  raise RepeatedAlarmError.new("no changes from previous alarm #{message.m_id_short}")
102
113
  end
103
- if Time.parse(message.attribute('aTs')) < Time.parse(message.attribute('aTs'))
114
+ if message_is_older? message
104
115
  raise TimestampError.new("timestamp is earlier than previous alarm #{message.m_id_short}")
105
116
  end
106
117
  ensure
@@ -30,6 +30,10 @@ module RSMP
30
30
  @alarms = {}
31
31
  end
32
32
 
33
+ def now
34
+ node.now
35
+ end
36
+
33
37
  def get_alarm_state alarm_code
34
38
  alarm = @alarms[alarm_code] ||= RSMP::AlarmState.new component: self, code: alarm_code
35
39
  end
data/lib/rsmp/message.rb CHANGED
@@ -233,7 +233,7 @@ module RSMP
233
233
  class AlarmIssue < Alarm
234
234
  def initialize attributes = {}
235
235
  super({
236
- "aSp" => "Issue",
236
+ "aSp" => "Issue"
237
237
  }.merge attributes)
238
238
  end
239
239
  end
data/lib/rsmp/node.rb CHANGED
@@ -8,7 +8,7 @@ module RSMP
8
8
 
9
9
  attr_reader :archive, :logger, :task, :deferred, :error_queue, :clock, :collector
10
10
 
11
- def initialize options
11
+ def initialize options={}
12
12
  initialize_logging options
13
13
  initialize_task
14
14
  @deferred = []
@@ -18,6 +18,10 @@ module RSMP
18
18
  @collect = options[:collect]
19
19
  end
20
20
 
21
+ def now
22
+ clock.now
23
+ end
24
+
21
25
  # stop proxies, then call super
22
26
  def stop_subtasks
23
27
  @proxies.each { |proxy| proxy.stop }
data/lib/rsmp/rsmp.rb CHANGED
@@ -38,5 +38,8 @@ module RSMP
38
38
  (time || now).strftime("%FT%T.%3NZ")
39
39
  end
40
40
 
41
+ def self.parse str
42
+ Time.parse(str)
43
+ end
41
44
  end
42
45
  end
data/lib/rsmp/site.rb CHANGED
@@ -97,18 +97,15 @@ module RSMP
97
97
  end
98
98
 
99
99
  def alarm_acknowledged alarm_state
100
- alarm = AlarmAcknowledged.new( alarm_state.to_hash )
101
- send_alarm alarm
100
+ send_alarm AlarmAcknowledged.new( alarm_state.to_hash )
102
101
  end
103
102
 
104
103
  def alarm_suspended_or_resumed alarm_state
105
- alarm = AlarmSuspended.new( alarm_state.to_hash.merge('aSp' => 'Suspend') )
106
- send_alarm alarm
104
+ send_alarm AlarmSuspended.new( alarm_state.to_hash )
107
105
  end
108
106
 
109
107
  def alarm_activated_or_deactivated alarm_state
110
- alarm = AlarmIssue.new( alarm_state.to_hash.merge('aSp' => 'Issue') )
111
- send_alarm alarm
108
+ send_alarm AlarmIssue.new( alarm_state.to_hash )
112
109
  end
113
110
 
114
111
  def send_alarm alarm
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.19.3"
2
+ VERSION = "0.19.4"
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.19.3
4
+ version: 0.19.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2023-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async