Class: Synapse::ServiceWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/service_watcher/zookeeper_dns.rb,
lib/synapse/service_watcher.rb,
lib/synapse/service_watcher/dns.rb,
lib/synapse/service_watcher/base.rb,
lib/synapse/service_watcher/docker.rb,
lib/synapse/service_watcher/ec2tag.rb,
lib/synapse/service_watcher/marathon.rb,
lib/synapse/service_watcher/zookeeper.rb

Overview

Watcher for watching Zookeeper for entries containing DNS names that are continuously resolved to IP Addresses. The use case for this watcher is to allow services that are addressed by DNS to be reconfigured via Zookeeper instead of an update of the synapse config.

The implementation builds on top of the existing DNS and Zookeeper watchers. This watcher creates a thread to manage the lifecycle of the DNS and Zookeeper watchers. This thread also publishes messages on a queue to indicate that DNS should be re-resolved (after the check interval) or that the DNS watcher should be shut down. The Zookeeper watcher waits for changes in backends from zookeeper and publishes those changes on an internal queue consumed by the DNS watcher. The DNS watcher blocks on this queue waiting for messages indicating that new servers are available, the check interval has passed (triggering a re-resolve), or that the watcher should shut down. The DNS watcher is responsible for the actual reconfiguring of backends.

Defined Under Namespace

Classes: BaseWatcher, DnsWatcher, DockerWatcher, Ec2tagWatcher, MarathonWatcher, ZookeeperDnsWatcher, ZookeeperWatcher

Class Method Summary collapse

Class Method Details

.create(name, opts, synapse) ⇒ Object

the method which actually dispatches watcher creation requests

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/synapse/service_watcher.rb', line 7

def self.create(name, opts, synapse)
  opts['name'] = name

  raise ArgumentError, "Missing discovery method when trying to create watcher" \
    unless opts.has_key?('discovery') && opts['discovery'].has_key?('method')

  discovery_method = opts['discovery']['method']
  watcher = begin
    method = discovery_method.downcase
    require "synapse/service_watcher/#{method}"
    # zookeeper_dns => ZookeeperDnsWatcher, ec2tag => Ec2tagWatcher, etc ...
    method_class  = method.split('_').map{|x| x.capitalize}.join.concat('Watcher')
    self.const_get("#{method_class}")
  rescue Exception => e
    raise ArgumentError, "Specified a discovery method of #{discovery_method}, which could not be found: #{e}"
  end
  return watcher.new(opts, synapse)
end