Class: ElasticSearch::Transport::Thrift

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticsearch/transport/thrift.rb

Constant Summary collapse

DEFAULTS =
{
  :timeout => 5,
  :thrift_protocol => ::Thrift::BinaryProtocol,
  :thrift_protocol_extra_params => [],
  :thrift_transport => ::Thrift::Socket,
  :thrift_transport_wrapper => ::Thrift::BufferedTransport,
  :client_class => ElasticSearch::Thrift::Rest::Client
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#options, #server

Instance Method Summary collapse

Methods inherited from Base

#encoder

Methods included from ClusterAdminProtocol

#cluster_health, #cluster_state, #nodes_info, #nodes_stats, #restart_nodes, #shutdown_nodes

Methods included from IndexAdminProtocol

#alias_index, #create_index, #create_river, #delete_index, #delete_mapping, #delete_river, #flush, #get_aliases, #get_river, #get_settings, #index_mapping, #index_status, #optimize, #refresh, #river_status, #snapshot, #update_mapping, #update_settings

Methods included from IndexProtocol

#bulk, #count, #delete, #delete_by_query, #get, #index, #multi_get, #scroll, #search

Constructor Details

#initialize(server, options = {}) ⇒ Thrift

Returns a new instance of Thrift.



23
24
25
26
# File 'lib/elasticsearch/transport/thrift.rb', line 23

def initialize(server, options={})
  super
  @options = DEFAULTS.merge(@options)
end

Instance Method Details

#all_nodesObject



45
46
47
48
49
50
51
52
53
# File 'lib/elasticsearch/transport/thrift.rb', line 45

def all_nodes
  thrift_addresses = nodes_info([])["nodes"].collect { |id, node| node["thrift_address"] }
  thrift_addresses.collect! do |a|
    if a =~ /.*\/([\d.:]+)/
      $1
    end
  end.compact!
  thrift_addresses
end

#closeObject



41
42
43
# File 'lib/elasticsearch/transport/thrift.rb', line 41

def close
  @transport.close rescue nil
end

#connect!Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/elasticsearch/transport/thrift.rb', line 28

def connect!
  host, port = parse_server(@server)

  @transport = @options[:thrift_transport].new(host, port.to_i, @options[:timeout])
  @transport = @transport_wrapper.new(@transport) if @transport_wrapper
  @transport.open

  @client = @options[:client_class].new(@options[:thrift_protocol].new(@transport, *@options[:thrift_protocol_extra_params]))
rescue ::Thrift::TransportException, Errno::ECONNREFUSED
  close
  raise ConnectionFailed
end