lib/elasticsearch/transport/transport/sniffer.rb in elasticsearch-transport-1.0.12 vs lib/elasticsearch/transport/transport/sniffer.rb in elasticsearch-transport-1.0.13
- old
+ new
@@ -3,11 +3,12 @@
module Transport
# Handles node discovery ("sniffing").
#
class Sniffer
- RE_URL = /\/([^:]*):([0-9]+)\]/ # Use named groups on Ruby 1.9: /\/(?<host>[^:]*):(?<port>[0-9]+)\]/
+ ES1_RE_URL = /\/([^:]*):([0-9]+)\]/ # Use named groups on Ruby 1.9: /\/(?<host>[^:]*):(?<port>[0-9]+)\]/
+ ES2_RE_URL = /([^:]*):([0-9]+)/
attr_reader :transport
attr_accessor :timeout
# @param transport [Object] A transport instance.
@@ -28,10 +29,12 @@
#
def hosts
Timeout::timeout(timeout, SnifferTimeoutError) do
nodes = transport.perform_request('GET', '_nodes/http').body
hosts = nodes['nodes'].map do |id,info|
- if matches = info["#{transport.protocol}_address"].to_s.match(RE_URL)
+ addr_str = info["#{transport.protocol}_address"].to_s
+ matches = addr_str.match(ES1_RE_URL) || addr_str.match(ES2_RE_URL)
+ if matches
# TODO: Implement lightweight "indifferent access" here
info.merge :host => matches[1], :port => matches[2], :id => id
end
end.compact