Class: RSMP::Site
Instance Attribute Summary collapse
Attributes included from Components
#components
Attributes inherited from Node
#archive, #clock, #collector, #deferred, #error_queue, #task
Attributes included from Task
#task
Attributes included from Logging
#archive
Instance Method Summary
collapse
Methods included from Components
#add_component, #check_main_component, #find_component, #infer_component_type, #initialize_components, #setup_components
Methods inherited from Node
#author, #check_required_settings, #clear_deferred, #defer, #do_deferred, #ignore_errors, #notify_error, #process_deferred, #stop_subtasks
Methods included from Task
#initialize_task, #restart, #start, #stop_subtasks, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Inspect
#inspect, #inspector
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
#initialize(options = {}) ⇒ Site
Returns a new instance of Site.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/rsmp/site.rb', line 11
def initialize options={}
super options
initialize_components
handle_site_settings options
@proxies = []
@sleep_condition = Async::Notification.new
@proxies_condition = Async::Notification.new
build_proxies
end
|
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
9
10
11
|
# File 'lib/rsmp/site.rb', line 9
def logger
@logger
end
|
#proxies ⇒ Object
Returns the value of attribute proxies.
9
10
11
|
# File 'lib/rsmp/site.rb', line 9
def proxies
@proxies
end
|
#rsmp_versions ⇒ Object
Returns the value of attribute rsmp_versions.
9
10
11
|
# File 'lib/rsmp/site.rb', line 9
def rsmp_versions
@rsmp_versions
end
|
#site_settings ⇒ Object
Returns the value of attribute site_settings.
9
10
11
|
# File 'lib/rsmp/site.rb', line 9
def site_settings
@site_settings
end
|
Instance Method Details
#aggregated_status_changed(component, options = {}) ⇒ Object
90
91
92
93
94
|
# File 'lib/rsmp/site.rb', line 90
def aggregated_status_changed component, options={}
@proxies.each do |proxy|
proxy.send_aggregated_status component, options if proxy.ready?
end
end
|
#alarm_changed(alarm_state) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/rsmp/site.rb', line 111
def alarm_changed alarm_state
alarm = alarm_state_to_message alarm_state
@proxies.each do |proxy|
proxy.send_message alarm if proxy.ready?
end
end
|
#alarm_state_to_message(alarm_state) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rsmp/site.rb', line 96
def alarm_state_to_message alarm_state
Alarm.new(
'cId' => alarm_state.component_id,
'aTs' => clock.to_s,
'aCId' => alarm_state.code,
'aSp' => (alarm_state.suspended ? 'Suspend' : 'Issue'),
'ack' => (alarm_state.acknowledged ? 'Acknowledged' : 'notAcknowledged'),
'sS' => (alarm_state.suspended ? 'suspended' : 'notSuspended'),
'aS' => (alarm_state.active ? 'Active' : 'inActive'),
'cat' => (alarm_state.category || 'D'),
'pri' => (alarm_state.priority || '2'),
'rvs' => []
)
end
|
#build_component(id:, type:, settings: {}) ⇒ Object
155
156
157
|
# File 'lib/rsmp/site.rb', line 155
def build_component id:, type:, settings:{}
Component.new id:id, node: self, grouped: type=='main'
end
|
#build_proxies ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/rsmp/site.rb', line 75
def build_proxies
@site_settings["supervisors"].each do |supervisor_settings|
@proxies << SupervisorProxy.new({
site: self,
task: @task,
settings: @site_settings,
ip: supervisor_settings['ip'],
port: supervisor_settings['port'],
logger: @logger,
archive: @archive,
collect: @collect
})
end
end
|
#check_sxl_version ⇒ Object
61
62
63
64
65
|
# File 'lib/rsmp/site.rb', line 61
def check_sxl_version
sxl = @site_settings['sxl']
version = @site_settings['sxl_version']
RSMP::Schemer::find_schema! sxl, version, lenient: true
end
|
#connect_to_supervisor(task, supervisor_settings) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/rsmp/site.rb', line 118
def connect_to_supervisor task, supervisor_settings
proxy = build_proxy({
site: self,
task: @task,
settings: @site_settings,
ip: supervisor_settings['ip'],
port: supervisor_settings['port'],
logger: @logger,
archive: @archive,
collect: @collect
})
@proxies << proxy
proxy.start
@proxies_condition.signal
end
|
#find_supervisor(ip) ⇒ Object
148
149
150
151
152
153
|
# File 'lib/rsmp/site.rb', line 148
def find_supervisor ip
@proxies.each do |supervisor|
return supervisor if ip == :any || supervisor.ip == ip
end
nil
end
|
#handle_site_settings(options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rsmp/site.rb', line 26
def handle_site_settings options={}
defaults = {
'site_id' => 'RN+SI0001',
'supervisors' => [
{ 'ip' => '127.0.0.1', 'port' => 12111 }
],
'rsmp_versions' => 'all',
'sxl' => 'tlc',
'sxl_version' => '1.0.15',
'intervals' => {
'timer' => 0.1,
'watchdog' => 1,
'reconnect' => 0.1
},
'timeouts' => {
'watchdog' => 2,
'acknowledgement' => 2
},
'send_after_connect' => true,
'components' => {
'main' => {
'C1' => {}
}
}
}
if options.dig(:site_settings,'components','main')
defaults['components']['main'] = options[:site_settings]['components']['main']
end
@site_settings = defaults.deep_merge options[:site_settings]
check_sxl_version
setup_components @site_settings['components']
end
|
#run ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/rsmp/site.rb', line 67
def run
log "Starting site #{@site_settings["site_id"]}",
level: :info,
timestamp: @clock.now
@proxies.each { |proxy| proxy.start }
@proxies.each { |proxy| proxy.wait }
end
|
#site_id ⇒ Object
22
23
24
|
# File 'lib/rsmp/site.rb', line 22
def site_id
@site_settings['site_id']
end
|
#stop ⇒ Object
135
136
137
138
|
# File 'lib/rsmp/site.rb', line 135
def stop
log "Stopping site #{@site_settings["site_id"]}", level: :info
super
end
|
#wait_for_supervisor(ip, timeout) ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/rsmp/site.rb', line 140
def wait_for_supervisor ip, timeout
supervisor = find_supervisor ip
return supervisor if supervisor
wait_for_condition(@proxy_condition,timeout:timeout) { find_supervisor ip }
rescue Async::TimeoutError
raise RSMP::TimeoutError.new "Supervisor '#{ip}' did not connect within #{timeout}s"
end
|