Class: RSMP::Site
Overview
RSMP site implementation that manages proxies and components.
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
Attributes included from Components
#components, #main
Attributes inherited from Node
#archive, #clock, #collector, #deferred, #error_queue, #task
Attributes included from Task
#task
Attributes included from Logging
#archive
Class Method Summary
collapse
Instance Method Summary
collapse
#accept_supervisor_connection, #accept_supervisor_connections, #build_proxies, #connect_to_supervisor, #listen_for_supervisors
Methods included from Components
#add_component, #check_main_component, #clear_alarm_timestamps, #component_list, #find_component, #infer_component_type, #initialize_components, #natural_sort_key, #setup_components
Methods inherited from Node
#author, #check_required_settings, #clear_deferred, #defer, #distribute_error, #do_deferred, #ignore_errors, #inspect, #now, #process_deferred
Methods included from Task
#initialize_task, #restart, #start, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
#initialize(options = {}) ⇒ Site
Returns a new instance of Site.
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/rsmp/node/site/site.rb', line 13
def initialize(options = {})
super
initialize_components
handle_site_settings options
@proxies = []
@sleep_condition = Async::Notification.new
@proxies_condition = Async::Notification.new
@ready_condition = Async::Notification.new
build_proxies
end
|
Instance Attribute Details
#core_version ⇒ Object
Returns the value of attribute core_version.
7
8
9
|
# File 'lib/rsmp/node/site/site.rb', line 7
def core_version
@core_version
end
|
#logger ⇒ Object
Returns the value of attribute logger.
7
8
9
|
# File 'lib/rsmp/node/site/site.rb', line 7
def logger
@logger
end
|
#proxies ⇒ Object
Returns the value of attribute proxies.
7
8
9
|
# File 'lib/rsmp/node/site/site.rb', line 7
def proxies
@proxies
end
|
#ready_condition ⇒ Object
Returns the value of attribute ready_condition.
7
8
9
|
# File 'lib/rsmp/node/site/site.rb', line 7
def ready_condition
@ready_condition
end
|
#site_settings ⇒ Object
Returns the value of attribute site_settings.
7
8
9
|
# File 'lib/rsmp/node/site/site.rb', line 7
def site_settings
@site_settings
end
|
Class Method Details
.options_class ⇒ Object
9
10
11
|
# File 'lib/rsmp/node/site/site.rb', line 9
def self.options_class
RSMP::Site::Options
end
|
Instance Method Details
#aggregated_status_changed(component, _options = {}) ⇒ Object
118
119
120
121
122
|
# File 'lib/rsmp/node/site/site.rb', line 118
def aggregated_status_changed(component, _options = {})
@proxies.each do |proxy|
proxy.send_aggregated_status component
end
end
|
#alarm_acknowledged(alarm_state) ⇒ Object
124
125
126
|
# File 'lib/rsmp/node/site/site.rb', line 124
def alarm_acknowledged(alarm_state)
send_alarm AlarmAcknowledged.new(alarm_state.to_hash)
end
|
#alarm_activated_or_deactivated(alarm_state) ⇒ Object
132
133
134
|
# File 'lib/rsmp/node/site/site.rb', line 132
def alarm_activated_or_deactivated(alarm_state)
send_alarm AlarmIssue.new(alarm_state.to_hash)
end
|
#alarm_suspended_or_resumed(alarm_state) ⇒ Object
128
129
130
|
# File 'lib/rsmp/node/site/site.rb', line 128
def alarm_suspended_or_resumed(alarm_state)
send_alarm AlarmSuspended.new(alarm_state.to_hash)
end
|
#build_component(id:, type:, settings:) ⇒ Object
207
208
209
210
211
212
213
214
215
|
# File 'lib/rsmp/node/site/site.rb', line 207
def build_component(id:, type:, settings:)
settings ||= {}
if type == 'main'
Component.new id: id, node: self, type: type, name: settings['name'], grouped: true,
ntsoid: settings['ntsOId'], xnid: settings['xNId']
else
Component.new id: id, node: self, type: type, name: settings['name'], grouped: false
end
end
|
#check_core_versions ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/rsmp/node/site/site.rb', line 81
def check_core_versions
version = @site_settings['core_version']
return unless version
return if RSMP::Schema.core_versions.include? version
error_str = "Unknown core version: #{version}"
raise RSMP::ConfigurationError, error_str
end
|
#check_sxls ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rsmp/node/site/site.rb', line 69
def check_sxls
raise RSMP::ConfigurationError, 'No SXLs specified' unless sxls
sxls.each do |sxl|
name = sxl['name']
version = sxl['version'].to_s
raise RSMP::ConfigurationError, 'SXL name cannot be core' if name.to_s == 'core'
RSMP::Schema.find_schema! name, version, lenient: true
end
end
|
#client_role? ⇒ Boolean
40
41
42
|
# File 'lib/rsmp/node/site/site.rb', line 40
def client_role?
@site_settings['connection_role'] != 'server'
end
|
#denormalize_sxls(settings) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/rsmp/node/site/site.rb', line 60
def denormalize_sxls(settings)
sxls = settings['sxls']
return settings unless sxls.is_a?(Array)
settings.merge(
'sxls' => sxls.to_h { |sxl| [sxl['name'], sxl['version']] }
)
end
|
#find_supervisor(ip) ⇒ Object
200
201
202
203
204
205
|
# File 'lib/rsmp/node/site/site.rb', line 200
def find_supervisor(ip)
@proxies.each do |supervisor|
return supervisor if ip == :any || supervisor.ip == ip
end
nil
end
|
#handle_site_settings(options = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rsmp/node/site/site.rb', line 48
def handle_site_settings(options = {})
options_class = self.class.options_class
settings = options[:site_settings] || {}
settings = denormalize_sxls(settings)
@site_options = options_class.new(settings)
@site_settings = @site_options.to_h
check_sxls
check_core_versions
setup_components @site_settings['components']
end
|
#log_site_starting ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/rsmp/node/site/site.rb', line 95
def log_site_starting
log "Starting #{site_type_name} #{@site_settings['site_id']}", level: :info, timestamp: @clock.now
sxl = "Using SXLs #{sxls.map { |item| "#{item['name']} #{item['version']}" }.join(', ')}"
version = @site_settings['core_version']
core = if version
"accepting only core version #{version}"
else
"accepting all core versions [#{RSMP::Schema.core_versions.join(', ')}]"
end
log "#{sxl}, #{core}", level: :info, timestamp: @clock.now
end
|
#primary_sxl ⇒ Object
28
29
30
|
# File 'lib/rsmp/node/site/site.rb', line 28
def primary_sxl
sxls.first
end
|
#run ⇒ Object
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/rsmp/node/site/site.rb', line 107
def run
log_site_starting
start_status_timer
if server_role?
listen_for_supervisors
else
@proxies.each(&:start)
@proxies.each(&:wait)
end
end
|
#run_status_timer(task, interval) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/rsmp/node/site/site.rb', line 153
def run_status_timer(task, interval)
next_time = Time.now.to_f
loop do
now = Clock.now
tick_status_subscriptions now
rescue StandardError => e
distribute_error e, level: :internal
ensure
next_time += interval
duration = next_time - Time.now.to_f
task.sleep duration
end
end
|
#send_alarm(alarm) ⇒ Object
136
137
138
139
140
|
# File 'lib/rsmp/node/site/site.rb', line 136
def send_alarm(alarm)
@proxies.each do |proxy|
proxy.send_message alarm if proxy.receive_alarms?
end
end
|
#server_role? ⇒ Boolean
44
45
46
|
# File 'lib/rsmp/node/site/site.rb', line 44
def server_role?
@site_settings['connection_role'] == 'server'
end
|
#site_id ⇒ Object
36
37
38
|
# File 'lib/rsmp/node/site/site.rb', line 36
def site_id
@site_settings['site_id']
end
|
#site_type_name ⇒ Object
91
92
93
|
# File 'lib/rsmp/node/site/site.rb', line 91
def site_type_name
'site'
end
|
#start_status_timer ⇒ Object
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/rsmp/node/site/site.rb', line 142
def start_status_timer
return if @status_timer
interval = @site_settings['intervals']['timer'] || 1
log "Starting site status timer with interval #{interval} seconds", level: :debug
@status_timer = @task.async do |task|
task.annotate 'site status timer'
run_status_timer task, interval
end
end
|
#stop ⇒ Object
186
187
188
189
|
# File 'lib/rsmp/node/site/site.rb', line 186
def stop
log "Stopping site #{@site_settings['site_id']}", level: :info
super
end
|
#stop_status_timer ⇒ Object
171
172
173
174
175
|
# File 'lib/rsmp/node/site/site.rb', line 171
def stop_status_timer
@status_timer&.stop
ensure
@status_timer = nil
end
|
#stop_subtasks ⇒ Object
177
178
179
180
181
182
183
|
# File 'lib/rsmp/node/site/site.rb', line 177
def stop_subtasks
stop_status_timer
@accept_task&.stop
@accept_task = nil
@endpoint = nil
super
end
|
#sxl_version ⇒ Object
32
33
34
|
# File 'lib/rsmp/node/site/site.rb', line 32
def sxl_version
primary_sxl && primary_sxl['version']
end
|
#sxls ⇒ Object
24
25
26
|
# File 'lib/rsmp/node/site/site.rb', line 24
def sxls
@site_settings['sxls']
end
|
#tick_status_subscriptions(now) ⇒ Object
167
168
169
|
# File 'lib/rsmp/node/site/site.rb', line 167
def tick_status_subscriptions(now)
@proxies.each { |proxy| proxy.status_update_timer now }
end
|
#wait_for_supervisor(ip, timeout:) ⇒ Object
191
192
193
194
195
196
197
198
|
# File 'lib/rsmp/node/site/site.rb', line 191
def wait_for_supervisor(ip, timeout:)
supervisor = find_supervisor ip
return supervisor if supervisor
wait_for_condition(@proxies_condition, timeout: timeout) { find_supervisor ip }
rescue Async::TimeoutError
raise RSMP::TimeoutError, "Supervisor '#{ip}' did not connect within #{timeout}s"
end
|