lib/elasticsearch/transport/transport/sniffer.rb in elasticsearch-transport-2.0.2 vs lib/elasticsearch/transport/transport/sniffer.rb in elasticsearch-transport-5.0.0.pre

- old
+ new

@@ -3,12 +3,11 @@ module Transport # Handles node discovery ("sniffing") # class Sniffer - ES1_RE_URL = /\[([^\/]*)?\/?([^:]*):([0-9]+)\]/ - ES2_RE_URL = /([^\/]*)?\/?([^:]*):([0-9]+)/ + PROTOCOL = 'http' attr_reader :transport attr_accessor :timeout # @param transport [Object] A transport instance @@ -28,16 +27,21 @@ # @raise [SnifferTimeoutError] # def hosts Timeout::timeout(timeout, SnifferTimeoutError) do nodes = transport.perform_request('GET', '_nodes/http').body + hosts = nodes['nodes'].map do |id,info| - addr_str = info["#{transport.protocol}_address"].to_s - matches = addr_str.match(ES1_RE_URL) || addr_str.match(ES2_RE_URL) - if matches - host = matches[1].empty? ? matches[2] : matches[1] - port = matches[3] - info.merge :host => host, :port => port, :id => id + if info[PROTOCOL] + host, port = info[PROTOCOL]['publish_address'].split(':') + + { :id => id, + :name => info['name'], + :version => info['version'], + :host => host, + :port => port, + :roles => info['roles'], + :attributes => info['attributes'] } end end.compact hosts.shuffle! if transport.options[:randomize_hosts] hosts