Class: RSMP::Site

Inherits:
Node
  • Object
show all
Includes:
Components
Defined in:
lib/rsmp/node/site/site.rb

Direct Known Subclasses

TLC::TrafficControllerSite

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

Instance Method Summary collapse

Methods included from Components

#add_component, #check_main_component, #clear_alarm_timestamps, #find_component, #infer_component_type, #initialize_components, #setup_components

Methods inherited from Node

#author, #check_required_settings, #clear_deferred, #defer, #distribute_error, #do_deferred, #ignore_errors, #now, #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
# File 'lib/rsmp/node/site/site.rb', line 11

def initialize(options = {})
  super
  initialize_components
  handle_site_settings options
  @proxies = []
  @sleep_condition = Async::Notification.new
  @proxies_condition = Async::Notification.new
  build_proxies
end

Instance Attribute Details

#core_versionObject (readonly)

Returns the value of attribute core_version.



9
10
11
# File 'lib/rsmp/node/site/site.rb', line 9

def core_version
  @core_version
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/rsmp/node/site/site.rb', line 9

def logger
  @logger
end

#proxiesObject (readonly)

Returns the value of attribute proxies.



9
10
11
# File 'lib/rsmp/node/site/site.rb', line 9

def proxies
  @proxies
end

#site_settingsObject (readonly)

Returns the value of attribute site_settings.



9
10
11
# File 'lib/rsmp/node/site/site.rb', line 9

def site_settings
  @site_settings
end

Instance Method Details

#aggregated_status_changed(component, options = {}) ⇒ Object



123
124
125
126
127
# File 'lib/rsmp/node/site/site.rb', line 123

def aggregated_status_changed(component, options = {})
  @proxies.each do |proxy|
    proxy.send_aggregated_status component, options if proxy.ready?
  end
end

#alarm_acknowledged(alarm_state) ⇒ Object



129
130
131
# File 'lib/rsmp/node/site/site.rb', line 129

def alarm_acknowledged(alarm_state)
  send_alarm AlarmAcknowledged.new(alarm_state.to_hash)
end

#alarm_activated_or_deactivated(alarm_state) ⇒ Object



137
138
139
# File 'lib/rsmp/node/site/site.rb', line 137

def alarm_activated_or_deactivated(alarm_state)
  send_alarm AlarmIssue.new(alarm_state.to_hash)
end

#alarm_suspended_or_resumed(alarm_state) ⇒ Object



133
134
135
# File 'lib/rsmp/node/site/site.rb', line 133

def alarm_suspended_or_resumed(alarm_state)
  send_alarm AlarmSuspended.new(alarm_state.to_hash)
end

#build_component(id:, type:, settings:) ⇒ Object



185
186
187
188
189
190
191
192
193
# File 'lib/rsmp/node/site/site.rb', line 185

def build_component(id:, type:, settings:)
  settings ||= {}
  if type == 'main'
    Component.new id: id, node: self, grouped: true,
                  ntsoid: settings['ntsOId'], xnid: settings['xNId']
  else
    Component.new id: id, node: self, grouped: false
  end
end

#build_proxiesObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rsmp/node/site/site.rb', line 108

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_core_versionsObject



74
75
76
77
78
79
80
81
82
# File 'lib/rsmp/node/site/site.rb', line 74

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_sxl_versionObject



68
69
70
71
72
# File 'lib/rsmp/node/site/site.rb', line 68

def check_sxl_version
  sxl = @site_settings['sxl']
  version = @site_settings['sxl_version'].to_s
  RSMP::Schema.find_schema! sxl, version, lenient: true
end

#connect_to_supervisor(_task, supervisor_settings) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rsmp/node/site/site.rb', line 147

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

#default_site_settingsObject



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
# File 'lib/rsmp/node/site/site.rb', line 29

def default_site_settings
  {
    'site_id' => 'RN+SI0001',
    'supervisors' => [
      { 'ip' => '127.0.0.1', 'port' => 12_111 }
    ],
    'sxl' => 'tlc',
    'sxl_version' => RSMP::Schema.latest_version(:tlc),
    'intervals' => {
      'timer' => 0.1,
      'watchdog' => 1,
      'reconnect' => 0.1
    },
    'timeouts' => {
      'watchdog' => 2,
      'acknowledgement' => 2
    },
    'send_after_connect' => true,
    'components' => {
      'main' => {
        'C1' => {}
      }
    }
  }
end

#find_supervisor(ip) ⇒ Object



178
179
180
181
182
183
# File 'lib/rsmp/node/site/site.rb', line 178

def find_supervisor(ip)
  @proxies.each do |supervisor|
    return supervisor if ip == :any || supervisor.ip == ip
  end
  nil
end

#handle_site_settings(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rsmp/node/site/site.rb', line 55

def handle_site_settings(options = {})
  defaults = default_site_settings
  defaults['components']['main'] = options[:site_settings]['components']['main'] if options.dig(
    :site_settings, 'components', 'main'
  )

  @site_settings = defaults.deep_merge options[:site_settings]

  check_sxl_version
  check_core_versions
  setup_components @site_settings['components']
end

#log_site_startingObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rsmp/node/site/site.rb', line 88

def log_site_starting
  log "Starting #{site_type_name} #{@site_settings['site_id']}", level: :info, timestamp: @clock.now
  sxl = "Using #{@site_settings['sxl']} sxl #{@site_settings['sxl_version']}"
  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

#runObject



100
101
102
103
104
105
106
# File 'lib/rsmp/node/site/site.rb', line 100

def run
  log_site_starting
  @proxies.each do |proxy|
    proxy.start
    proxy.wait
  end
end

#send_alarm(alarm) ⇒ Object



141
142
143
144
145
# File 'lib/rsmp/node/site/site.rb', line 141

def send_alarm(alarm)
  @proxies.each do |proxy|
    proxy.send_message alarm if proxy.ready?
  end
end

#site_idObject



25
26
27
# File 'lib/rsmp/node/site/site.rb', line 25

def site_id
  @site_settings['site_id']
end

#site_type_nameObject



84
85
86
# File 'lib/rsmp/node/site/site.rb', line 84

def site_type_name
  'site'
end

#stopObject

stop



164
165
166
167
# File 'lib/rsmp/node/site/site.rb', line 164

def stop
  log "Stopping site #{@site_settings['site_id']}", level: :info
  super
end

#sxl_versionObject



21
22
23
# File 'lib/rsmp/node/site/site.rb', line 21

def sxl_version
  @site_settings['sxl_version']
end

#wait_for_supervisor(ip, timeout) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/rsmp/node/site/site.rb', line 169

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, "Supervisor '#{ip}' did not connect within #{timeout}s"
end