Module: RSMP::SiteProxy::Modules::AggregatedStatus

Included in:
RSMP::SiteProxy
Defined in:
lib/rsmp/proxy/site/modules/aggregated_status.rb

Overview

Handles aggregated status requests and responses

Instance Method Summary collapse

Instance Method Details

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



67
68
69
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 67

def aggregated_status_changed(component, _options = {})
  @supervisor.aggregated_status_changed self, component
end

#process_aggregated_status(message) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 50

def process_aggregated_status(message)
  status_elements = message.attribute('se')
  validate_aggregated_status(message, status_elements)
  c_id = message.attributes['cId']
  component = find_component c_id
  unless component
    reason = "component #{c_id} not found"
    dont_acknowledge message, "Ignoring #{message.type}:", reason
    return
  end

  component.aggregated_status_bools = status_elements
  log "Received #{message.type} status for component #{c_id} [#{component.aggregated_status.join(', ')}]",
      message: message
  acknowledge message
end

#request_aggregated_status(component, m_id: nil, validate: true) ⇒ Object

Build and send an AggregatedStatusRequest. Returns Result.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 7

def request_aggregated_status(component, m_id: nil, validate: true)
  readiness = validate_ready 'request aggregated status'
  return readiness if readiness.failure?

  m_id ||= RSMP::Message.make_m_id
  message = RSMP::AggregatedStatusRequest.new({
                                                'cId' => component,
                                                'mId' => m_id
                                              })
  apply_nts_message_attributes message
  send_message(message, validate: validate).map(&:message)
end

#request_aggregated_status!Object



20
21
22
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 20

def request_aggregated_status!(...)
  request_aggregated_status(...).value!
end

#request_aggregated_status_and_collect(component, within:, m_id: nil, validate: true) ⇒ Object

Build, send an AggregatedStatusRequest and collect the response. Returns Result.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 25

def request_aggregated_status_and_collect(component, within:, m_id: nil, validate: true)
  readiness = validate_ready 'request aggregated status'
  return readiness if readiness.failure?

  m_id ||= RSMP::Message.make_m_id
  message = RSMP::AggregatedStatusRequest.new({
                                                'cId' => component,
                                                'mId' => m_id
                                              })
  apply_nts_message_attributes message
  collector = AggregatedStatusCollector.new(self, timeout: within, m_id: m_id, num: 1)
  send_message_and_collect(message, collector, validate: validate)
end

#request_aggregated_status_and_collect!Object



39
40
41
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 39

def request_aggregated_status_and_collect!(...)
  request_aggregated_status_and_collect(...).value!
end

#validate_aggregated_status(message, status_elements) ⇒ Object

Raises:



43
44
45
46
47
48
# File 'lib/rsmp/proxy/site/modules/aggregated_status.rb', line 43

def validate_aggregated_status(message, status_elements)
  return if status_elements.is_a?(Array) && status_elements.size == 8

  dont_acknowledge message, 'Received', reaons
  raise InvalidMessage
end