Class: Nerve::Reporter::Zookeeper

Inherits:
Base
  • Object
show all
Defined in:
lib/nerve/reporter/zookeeper.rb

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #log, logger_for

Methods included from Utils

#safe_run

Constructor Details

#initialize(service) ⇒ Zookeeper

Returns a new instance of Zookeeper.



6
7
8
9
10
11
12
13
14
15
# File 'lib/nerve/reporter/zookeeper.rb', line 6

def initialize(service)
  %w{zk_hosts zk_path instance_id host port}.each do |required|
    raise ArgumentError, "missing required argument #{required} for new service watcher" unless service[required]
  end
  @path = service['zk_hosts'].shuffle.join(',') + service['zk_path']
  @data = parse_data({'host' => service['host'], 'port' => service['port'], 'name' => service['instance_id']})

  @key = "/#{service['instance_id']}_"
  @full_key = nil
end

Instance Method Details

#ping?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/nerve/reporter/zookeeper.rb', line 37

def ping?
  return @zk.ping?
end

#report_downObject



28
29
30
# File 'lib/nerve/reporter/zookeeper.rb', line 28

def report_down
  zk_delete
end

#report_upObject



24
25
26
# File 'lib/nerve/reporter/zookeeper.rb', line 24

def report_up()
  zk_save
end

#startObject



17
18
19
20
21
22
# File 'lib/nerve/reporter/zookeeper.rb', line 17

def start()
  log.info "nerve: waiting to connect to zookeeper at #{@path}"
  @zk = ZK.new(@path)

  log.info "nerve: successfully created zk connection to #{@path}"
end

#update_data(new_data = '') ⇒ Object



32
33
34
35
# File 'lib/nerve/reporter/zookeeper.rb', line 32

def update_data(new_data='')
  @data = parse_data(new_data)
  zk_save
end