class ElasticSearch::Transport::Thrift
Constants
- DEFAULTS
Public Class Methods
new(server, options={})
click to toggle source
Calls superclass method
ElasticSearch::Transport::Base::new
# File lib/elasticsearch/transport/thrift.rb, line 23 def initialize(server, options={}) super @options = DEFAULTS.merge(@options) end
Public Instance Methods
all_nodes()
click to toggle source
# 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
close()
click to toggle source
# File lib/elasticsearch/transport/thrift.rb, line 41 def close @transport.close rescue nil end
connect!()
click to toggle source
# 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
Private Instance Methods
parse_server(server)
click to toggle source
# File lib/elasticsearch/transport/thrift.rb, line 57 def parse_server(server) host, port = server.to_s.split(":") raise ArgumentError, 'Servers must be in the form "host:port"' unless host and port [host, port] end
request(method, operation, params={}, body=nil, headers={})
click to toggle source
# File lib/elasticsearch/transport/thrift.rb, line 70 def request(method, operation, params={}, body=nil, headers={}) begin uri = generate_uri(operation) #puts "request: #{@server} #{method} #{uri} #{params.inspect} #{body}" request = ElasticSearch::Thrift::RestRequest.new case method when :get request.method = ElasticSearch::Thrift::Method::GET when :put request.method = ElasticSearch::Thrift::Method::PUT when :post request.method = ElasticSearch::Thrift::Method::POST when :delete request.method = ElasticSearch::Thrift::Method::DELETE end request.uri = uri request.parameters = stringify!(params) request.body = body request.headers = stringify!(headers) response = @client.execute(request) handle_error(response) if response.status >= 500 response rescue Exception => e case e when ::Thrift::TransportException case e.type when ::Thrift::TransportException::TIMED_OUT raise TimeoutError else raise ConnectionFailed end #TODO Thrift::ApplicationException, Thrift::ProtocolException, IOError.. retryable or fatal? else raise e end end end
stringify!(hash)
click to toggle source
# File lib/elasticsearch/transport/thrift.rb, line 63 def stringify!(hash) hash.keys.each do |k| hash[k.to_s] = hash.delete(k).to_s end hash end