rsmp 0.19.3 → 0.19.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8702928138cf433b9d0744b92af2d9e535292342ba5e18bd22fcc3985f341a11
4
- data.tar.gz: 27a689a67e585f1da3c40feeda85468f9d7a7306c19437be156d4162b55f7024
3
+ metadata.gz: ece63f3127c2afec9954b9395079a4f6bd755c1edfa1ebd86a5b656e0eb3ae7b
4
+ data.tar.gz: d2649a64d7905095f0c418bc3ad8dcae3e6b5c891a784e7fbdc1841f4b17e2db
5
5
  SHA512:
6
- metadata.gz: 91b20a0cee412984bd269083fd67864175c0c0c1d5627cd9003369cc63e1413c97e9c3b49c135e7328f372fcec9d95cd1f8c0edc54bf692400c4a20109d66137
7
- data.tar.gz: dadfc9ba3cfba8ddd0dc82318299a78ef4f7101ff9708e61d3bbe1b54280aac42f9d5111bf9e102dbf8a0b4f1d0c401dbc4471f55b0a760713ab4374be83e781
6
+ metadata.gz: 70a4b8297b24a0f7d5ffeba0b86ec26bae1d196e01d46d6b06a1cc8ab50b14705f28ecf50ca30f0d4e2487c790781e71e80e6a4c0c4d39dda08ccc98c8e1235c
7
+ data.tar.gz: f5f4071e92f737153bc989787626d09cd96cf24204f13e2aaf91a49383876cc6bb2ae6ee763f82a08f779806e908e7236790b98315076c652078e95670a04a11
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.5)
5
5
  async (~> 1.30.3)
6
6
  async-io (~> 1.34.3)
7
7
  colorize (~> 0.8.1)
@@ -1,33 +1,53 @@
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
18
38
  end
19
39
 
20
40
  def to_hash
21
41
  {
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
42
+ 'cId' => @component_id,
43
+ 'aCId' => @code,
44
+ 'aTs' => Clock.to_s(@timestamp),
45
+ 'ack' => (@acknowledged ? 'Acknowledged' : 'notAcknowledged'),
46
+ 'sS' => (@suspended ? 'suspended' : 'notSuspended'),
47
+ 'aS' => (@active ? 'Active' : 'inActive'),
48
+ 'cat' => @category,
49
+ 'pri' => @priority.to_s,
50
+ 'rvs' => @rvs
31
51
  }
32
52
  end
33
53
 
@@ -65,46 +85,36 @@ module RSMP
65
85
  end
66
86
 
67
87
  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
- )
88
+ @timestamp = @component.now
84
89
  end
85
90
 
86
91
  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')
92
+ return true if RSMP::Clock.to_s(@timestamp) != message.attribute('aTs')
93
+ return true if message.attribute('ack') && @acknowledged != (message.attribute('ack') == 'Acknowledged')
94
+ return true if message.attribute('sS') && @suspended != (message.attribute('sS') == 'suspended')
95
+ return true if message.attribute('aS') && @active != (message.attribute('aS') == 'Active')
91
96
  return true if message.attribute('cat') && @category != message.attribute('cat')
92
97
  return true if message.attribute('pri') && @priority != message.attribute('pri').to_i
93
98
  #return true @rvs = message.attribute('rvs')
94
99
  false
95
100
  end
96
101
 
102
+ def older_message? message
103
+ return false if @timestamp == nil
104
+ RSMP::Clock.parse(message.attribute('aTs')) < @timestamp
105
+ end
106
+
97
107
  # update from rsmp message
98
108
  # component id, alarm code and specialization are not updated
99
109
  def update_from_message message
100
110
  unless differ_from_message? message
101
111
  raise RepeatedAlarmError.new("no changes from previous alarm #{message.m_id_short}")
102
112
  end
103
- if Time.parse(message.attribute('aTs')) < Time.parse(message.attribute('aTs'))
113
+ if older_message? message
104
114
  raise TimestampError.new("timestamp is earlier than previous alarm #{message.m_id_short}")
105
115
  end
106
116
  ensure
107
- @timestamp = message.attribute('aTs')
117
+ @timestamp = RSMP::Clock.parse message.attribute('aTs')
108
118
  @acknowledged = message.attribute('ack') == 'True'
109
119
  @suspended = message.attribute('sS') == 'True'
110
120
  @active = message.attribute('aS') == 'True'
@@ -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/proxy.rb CHANGED
@@ -24,6 +24,11 @@ module RSMP
24
24
  @state = :disconnected
25
25
  end
26
26
 
27
+
28
+ def now
29
+ node.now
30
+ end
31
+
27
32
  def disconnect
28
33
  end
29
34
 
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.5"
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.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: 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