diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/aclog/exceptions.rb | 2 | ||||
-rw-r--r-- | lib/collector/control_server.rb | 16 | ||||
-rw-r--r-- | lib/collector/daemon.rb | 5 | ||||
-rw-r--r-- | lib/collector/node_connection.rb | 3 | ||||
-rw-r--r-- | lib/collector/node_manager.rb | 39 |
5 files changed, 44 insertions, 21 deletions
diff --git a/lib/aclog/exceptions.rb b/lib/aclog/exceptions.rb index 1a58755..5ffe609 100644 --- a/lib/aclog/exceptions.rb +++ b/lib/aclog/exceptions.rb @@ -16,5 +16,7 @@ module Aclog class OAuthEchoError < Unauthorized; end class OAuthEchoUnauthorized < OAuthEchoError; end + + class WorkerConnectionError < AclogError; end end end diff --git a/lib/collector/control_server.rb b/lib/collector/control_server.rb index 413345e..5a22d08 100644 --- a/lib/collector/control_server.rb +++ b/lib/collector/control_server.rb @@ -7,5 +7,21 @@ module Collector def deactivate_account(account) NodeManager.unregister_account(Marshal.load(account)) end + + def status + active_node_statuses = Settings.collector.nodes_count.times.map do |number| + node = NodeManager.active_connections[number] + if node + { start_time: node.start_time } + else + nil + end + end + + res = { start_time: Daemon.start_time, + active_node_statuses: active_node_statuses, + inactive_nodes_count: NodeManager.inactive_connections.size } + Marshal.dump(res) + end end end diff --git a/lib/collector/daemon.rb b/lib/collector/daemon.rb index 8c7194f..f77c6eb 100644 --- a/lib/collector/daemon.rb +++ b/lib/collector/daemon.rb @@ -1,9 +1,12 @@ require "msgpack/rpc/transport/unix" module Collector - class Daemon + module Daemon class << self + attr_reader :start_time + def start + @start_time = Time.now set_loggers EM.run do diff --git a/lib/collector/node_connection.rb b/lib/collector/node_connection.rb index 06fbf3f..9b9134b 100644 --- a/lib/collector/node_connection.rb +++ b/lib/collector/node_connection.rb @@ -1,6 +1,6 @@ module Collector class NodeConnection < EM::Connection - attr_reader :connection_id + attr_reader :connection_id, :start_time @@_id = 0 @@ -9,6 +9,7 @@ module Collector @connection_id = (@@_id += 1) @authenticated = false @closing = false + @start_time = Time.now end def unbind diff --git a/lib/collector/node_manager.rb b/lib/collector/node_manager.rb index 8136fe8..f47c7cf 100644 --- a/lib/collector/node_manager.rb +++ b/lib/collector/node_manager.rb @@ -1,58 +1,59 @@ module Collector - class NodeManager - @@node_connections = [] - @@active_connections = Array.new(Settings.collector.nodes_count) - @@inactive_connections = [] + module NodeManager + @node_connections = [] + @active_connections = Array.new(Settings.collector.nodes_count) + @inactive_connections = [] class << self + attr_reader :node_connections, :active_connections, :inactive_connections + def register(node_connection) - @@node_connections << node_connection - @@inactive_connections << node_connection + self.node_connections << node_connection + self.inactive_connections << node_connection bind end def unregister(node_connection) - @@node_connections.delete(node_connection) - i = @@active_connections.find_index(node_connection) + self.node_connections.delete(node_connection) + i = self.active_connections.find_index(node_connection) if i - @@active_connections[i] = nil + self.active_connections[i] = nil else - @@inactive_connections.delete(node_connection) + self.inactive_connections.delete(node_connection) end bind end def register_account(account) n = account.id % Settings.collector.nodes_count - if @@active_connections[n] - @@active_connections[n].register_account(account) + if self.active_connections[n] + self.active_connections[n].register_account(account) end end def unregister_account(account) n = account.id % Settings.collector.nodes_count - if @@active_connections[n] - @@active_connections[n].unregister_account(account) + if self.active_connections[n] + self.active_connections[n].unregister_account(account) end end private def bind - first_inactive_id = @@active_connections.find_index(nil) + first_inactive_id = self.active_connections.find_index(nil) if first_inactive_id - con = @@inactive_connections.shift + con = self.inactive_connections.shift if con - @@active_connections[first_inactive_id] = con + self.active_connections[first_inactive_id] = con Rails.logger.warn("[NodeManager] Registered node ##{con.connection_id} as group ##{first_inactive_id}") Account.for_node(first_inactive_id).each do |a| con.register_account(a) end else - Rails.logger.warn("[NodeManager] Not enough nodes: (#{@@active_connections.count {|c| c }}/#{Settings.collector.nodes_count})") + Rails.logger.warn("[NodeManager] Not enough nodes: (#{self.active_connections.count {|c| c }}/#{Settings.collector.nodes_count})") end end end - end end end |