class Solr::Cloud::ZookeeperConnection

Attributes

zookeeper_auth_password[R]
zookeeper_auth_user[R]
zookeeper_url[R]

Public Class Methods

new(zookeeper_url:, zookeeper_auth_user: nil, zookeeper_auth_password: nil) click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 8
def initialize(zookeeper_url:, zookeeper_auth_user: nil, zookeeper_auth_password: nil)
  @zookeeper_url = zookeeper_url
  @zookeeper_auth_user = zookeeper_auth_user
  @zookeeper_auth_password = zookeeper_auth_password
end

Public Instance Methods

collection_state_znode_path(collection_name) click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 31
def collection_state_znode_path(collection_name)
  "/collections/#{collection_name}/state.json"
end
get_collection_state(collection_name, watch: true) click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 24
def get_collection_state(collection_name, watch: true)
  collection_state_znode = collection_state_znode_path(collection_name)
  znode_data = zookeeper_connection.get(collection_state_znode, watch: watch)
  return unless znode_data
  JSON.parse(znode_data.first)[collection_name.to_s]
end
watch_collection_state(collection_name, &block) click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 14
def watch_collection_state(collection_name, &block)
  collection_state_znode = collection_state_znode_path(collection_name)
  zookeeper_connection.register(collection_state_znode) do |event|
    state = get_collection_state(collection_name, watch: true)
    block.call(state)
  end
  state = get_collection_state(collection_name, watch: true)
  block.call(state)
end

Private Instance Methods

build_zookeeper_connection() click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 41
def build_zookeeper_connection
  raise 'You must provide a ZooKeeper URL to enable solr cloud mode' unless zookeeper_url
  raise Solr::Errors::ZookeeperRequired unless require_zk

  zk = ZK.new(zookeeper_url)
  zk.add_auth(scheme: 'digest', cert: zookeeper_auth) if zookeeper_auth
  zk
end
require_zk() click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 56
def require_zk
  require 'zk'
  true
rescue LoadError
  false
end
zookeeper_auth() click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 50
def zookeeper_auth
  if zookeeper_auth_user && zookeeper_auth_password
    "#{zookeeper_auth_user}:#{zookeeper_auth_password}"
  end
end
zookeeper_connection() click to toggle source
# File lib/solr/cloud/zookeeper_connection.rb, line 37
def zookeeper_connection
  @zookeeper_connection ||= build_zookeeper_connection
end