Sha256: 304614da510c9b0db3969e02297e98acf8441b5820c48efc7075372743dad365

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module Shatter
  module Service
    class Discovery
      class << self

        def deregister_service(service_url)
          zk = ZK.new (Shatter::Config.zookeeper_host)
          if zk.exists?("/shater_service_instances/#{service_url}")
            zk.delete("/shater_service_instances/#{service_url}")
          end
          zk.close
        end

        def register_service(service_url)
          Shatter.logger.info "Registering #{service_url} to zookeeper"
          zk = ZK.new (Shatter::Config.zookeeper_host)
          unless zk.exists?("/shater_service_instances/#{service_url}")
            created = zk.create("/shater_service_instances/#{service_url}")
            Shatter.logger.info "Registered #{created}"
          end
          puts zk.children("/shater_service_instances")
          zk.close
        end

        def service_instance_url
          service_instance_urls.sample
        end

        def service_instance_urls
          zk = ZK.new (Shatter::Config.zookeeper_host)
          urls = zk.children("/shater_service_instances")
          zk.close
          urls
        end

        def service_instance_url_for_uuid(uuid)
          druby_instance_url = nil
          key = Util.zookeeper_response_key(uuid)
          zk = ZK.new(Shatter::Config.zookeeper_host)
          druby_instance_url = zk.get(key)[0] if zk.exists?(key)
          zk.close
          Shatter.logger.debug "Service instance url for #{uuid} - #{druby_instance_url}"

          druby_instance_url
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shatter-rb-0.0.2 lib/shatter/service/discovery.rb
shatter-rb-0.0.1 lib/shatter/service/discovery.rb