class Roma::Watch::Main

Attributes

conf[R]
errors[R]
log[R]
mailer[R]
nodelist_inf[R]

Public Class Methods

new(config) click to toggle source
   # File lib/roma/tools/roma_watcher.rb
54 def initialize config
55   @conf = config
56   @log = Logger.new @conf['log']['path'], @conf['log']['rotate']
57   @nodelist_inf = {}
58   @errors = {}
59   @subject_prefix = @conf['mail']['subject_prefix']
60   @mailer = Mailer.new @conf['mail']['from'], @conf['mail']['to'], @conf['mail']['mailer']
61 end

Public Instance Methods

check_nodes() click to toggle source
    # File lib/roma/tools/roma_watcher.rb
107 def check_nodes
108   check_vital
109   check_splitbrain
110 end
check_splitbrain() click to toggle source
    # File lib/roma/tools/roma_watcher.rb
120 def check_splitbrain
121   @log.debug "start checking a splitbrain"
122   all_ring = []
123   @nodelist_inf.each { |node, ring|
124     all_ring << ring unless all_ring.include? ring
125   }
126 
127   if all_ring.size != 1
128     emsg = ""
129     all_ring.each { |ring|
130       emsg += "#{ring.join(',')}\r\n"
131     }
132     @mailer.send_mail(@subject_prefix + Message::ERROR_SPLIT_BRAIN, emsg)
133   end
134   @log.debug "end checking a splitbrain"
135 end
check_vital() click to toggle source
    # File lib/roma/tools/roma_watcher.rb
112 def check_vital
113   @log.debug "start checking the vital"
114   @errors.each { |node, emsg|
115     @mailer.send_mail(@subject_prefix + Message::ERROR_NODE_DOWN, emsg)
116   }
117   @log.debug "end checking the vital"
118 end
watch() click to toggle source
   # File lib/roma/tools/roma_watcher.rb
63 def watch
64   @log.info "start watching a ROMA"
65   watch_nodes
66   @log.info "end watching"
67   @log.info "start checking a ROMA"
68   check_nodes
69   @log.info "end checking"
70 end
watch_node(node) click to toggle source
    # File lib/roma/tools/roma_watcher.rb
 79 def watch_node node
 80   @log.debug "start watching a node: #{node}"
 81   host, port = node.split(':')
 82   sock = nil
 83   begin
 84     timeout(@conf['timeout'].to_i) {
 85       line = nil
 86       TCPSocket.open(host, port) do |sock|
 87         sock.puts Message::COMMAND_NODELIST
 88         line = sock.gets.chomp!
 89         sock.puts Message::COMMAND_QUIT
 90       end
 91       @log.debug "end watching a node: #{node}"
 92       line.split(' ')
 93     }
 94   rescue Exception => e
 95     emsg = "Catch an error when checking a node #{node}: #{e.to_s}"
 96     @log.error emsg
 97     if (cnt ||= 0; cnt += 1) < @conf['retry']['count'].to_i
 98       @log.info "retry: #{cnt} times"
 99       sleep @conf['retry']['period'].to_i
100       retry
101     end
102     @errors[node] = emsg
103     nil
104   end
105 end
watch_nodes() click to toggle source
   # File lib/roma/tools/roma_watcher.rb
72 def watch_nodes
73   @conf['roma'].each { |node|
74     nodes = watch_node node
75     @nodelist_inf[node] = nodes if nodes
76   }
77 end