Class: Cloudmaster::StatusParserLifeguard

Inherits:
Object
  • Object
show all
Defined in:
app/status_parser_lifeguard.rb

Instance Method Summary collapse

Instance Method Details

#parse_message(body) ⇒ Object

Parse a lifeguard message.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/status_parser_lifeguard.rb', line 13

def parse_message(body)
  msg = { :type => 'status'}
  doc = REXML::Document.new(body)
  doc.root.each_element do |elem|
    val = elem.get_text.to_s.lstrip.rstrip
    case elem.name
    when 'InstanceId'
      msg[:instance_id] = val
    when 'State'
    case val
    when 'busy'
 # Lifeguard's busy maps into active
 msg[:state] = 'active'
 msg[:load_estimate] = 1
    else
 # all else maps to idle
 msg[:state] = 'idle'
 msg[:load_estimate] = 0
    end    
    when 'Timestamp'
    if ! val.include?('-')
 # This is a mock time
 msg[:timestamp] = Clock.at(val.to_i)
    elsif val.include?('T')
 # This is a time in xmlschema form
 msg[:timestamp] = Clock.xmlschema(val)
    else
 # OK, let's try plain parse (don't expect this to happen)
 msg[:timestamp] = Clock.parse(val)
    end
    end
  end
  msg
end