elasticsearch-transport 1.0.13 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/elasticsearch/transport/transport/http/faraday.rb +6 -2
- data/lib/elasticsearch/transport/transport/sniffer.rb +7 -6
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/test/unit/sniffer_test.rb +27 -0
- data/test/unit/transport_faraday_test.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c41acb9864d25738a29b7ced81856e5eea8660
|
4
|
+
data.tar.gz: 1675e534fedd834b107e51c620767f11e1b9327f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2473aa1f15584614fcf9c96e75030bd37979817ba4ddcce78134781b275deedd35cf1a62a46af649c704d2d84a247751fe680be1c111de8ac8d25e6c33316817
|
7
|
+
data.tar.gz: 18aa296103d2c29b5ae11a3258f7e9c5f97c6787ad061ad4d0713a9e7fb916d920fb0c92604065bbbedf6fd7e15f75d2a253238a7cb26de141e7c48f0727f616
|
data/README.md
CHANGED
@@ -90,6 +90,9 @@ Instead of Strings, you can pass host information as an array of Hashes:
|
|
90
90
|
|
91
91
|
Elasticsearch::Client.new hosts: [ { host: 'myhost1', port: 8080 }, { host: 'myhost2', port: 8080 } ]
|
92
92
|
|
93
|
+
**NOTE:** When specifying multiple hosts, you probably want to enable the `retry_on_failure` option to
|
94
|
+
perform a failed request on another node (see the _Retrying on Failures_ chapter).
|
95
|
+
|
93
96
|
Common URL parts -- scheme, HTTP authentication credentials, URL prefixes, etc -- are handled automatically:
|
94
97
|
|
95
98
|
Elasticsearch::Client.new url: 'https://username:password@api.server.org:4430/search'
|
@@ -34,8 +34,12 @@ module Elasticsearch
|
|
34
34
|
def __build_connections
|
35
35
|
Connections::Collection.new \
|
36
36
|
:connections => hosts.map { |host|
|
37
|
-
host[:protocol]
|
38
|
-
host[:port]
|
37
|
+
host[:protocol] = host[:scheme] || options[:scheme] || DEFAULT_PROTOCOL
|
38
|
+
host[:port] ||= options[:port] || DEFAULT_PORT
|
39
|
+
if options[:user] && !host[:user]
|
40
|
+
host[:user] ||= options[:user]
|
41
|
+
host[:password] ||= options[:password]
|
42
|
+
end
|
39
43
|
url = __full_url(host)
|
40
44
|
|
41
45
|
Connections::Connection.new \
|
@@ -2,16 +2,16 @@ module Elasticsearch
|
|
2
2
|
module Transport
|
3
3
|
module Transport
|
4
4
|
|
5
|
-
# Handles node discovery ("sniffing")
|
5
|
+
# Handles node discovery ("sniffing")
|
6
6
|
#
|
7
7
|
class Sniffer
|
8
|
-
ES1_RE_URL =
|
9
|
-
ES2_RE_URL
|
8
|
+
ES1_RE_URL = /\[([^\/]*)?\/?([^:]*):([0-9]+)\]/
|
9
|
+
ES2_RE_URL = /([^\/]*)?\/?([^:]*):([0-9]+)/
|
10
10
|
|
11
11
|
attr_reader :transport
|
12
12
|
attr_accessor :timeout
|
13
13
|
|
14
|
-
# @param transport [Object] A transport instance
|
14
|
+
# @param transport [Object] A transport instance
|
15
15
|
#
|
16
16
|
def initialize(transport)
|
17
17
|
@transport = transport
|
@@ -34,8 +34,9 @@ module Elasticsearch
|
|
34
34
|
addr_str = info["#{transport.protocol}_address"].to_s
|
35
35
|
matches = addr_str.match(ES1_RE_URL) || addr_str.match(ES2_RE_URL)
|
36
36
|
if matches
|
37
|
-
|
38
|
-
|
37
|
+
host = matches[1].empty? ? matches[2] : matches[1]
|
38
|
+
port = matches[3]
|
39
|
+
info.merge :host => host, :port => port, :id => id
|
39
40
|
end
|
40
41
|
end.compact
|
41
42
|
|
data/test/unit/sniffer_test.rb
CHANGED
@@ -75,6 +75,33 @@ class Elasticsearch::Transport::Transport::SnifferTest < Test::Unit::TestCase
|
|
75
75
|
assert_equal 'Node 1', hosts.first['name']
|
76
76
|
end
|
77
77
|
|
78
|
+
should "return an array of hosts as hostnames when a hostname is returned" do
|
79
|
+
@transport.expects(:perform_request).returns __nodes_info <<-JSON
|
80
|
+
{
|
81
|
+
"ok" : true,
|
82
|
+
"cluster_name" : "elasticsearch_test",
|
83
|
+
"nodes" : {
|
84
|
+
"N1" : {
|
85
|
+
"name" : "Node 1",
|
86
|
+
"transport_address" : "inet[/192.168.1.23:9300]",
|
87
|
+
"hostname" : "testhost1",
|
88
|
+
"version" : "0.20.6",
|
89
|
+
"http_address" : "inet[testhost1.com/192.168.1.23:9200]",
|
90
|
+
"thrift_address" : "/192.168.1.23:9500",
|
91
|
+
"memcached_address" : "inet[/192.168.1.23:11211]"
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
JSON
|
96
|
+
|
97
|
+
hosts = @sniffer.hosts
|
98
|
+
|
99
|
+
assert_equal 1, hosts.size
|
100
|
+
assert_equal 'testhost1.com', hosts.first[:host]
|
101
|
+
assert_equal '9200', hosts.first[:port]
|
102
|
+
assert_equal 'Node 1', hosts.first['name']
|
103
|
+
end
|
104
|
+
|
78
105
|
should "skip hosts without a matching transport protocol" do
|
79
106
|
@transport = DummyTransport.new :options => { :protocol => 'memcached' }
|
80
107
|
@sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
|
@@ -135,6 +135,43 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
135
135
|
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' } ]
|
136
136
|
assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
|
137
137
|
end
|
138
|
+
|
139
|
+
should "set the credentials if they exist in options" do
|
140
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ],
|
141
|
+
:options => { :user => 'foo', :password => 'bar' }
|
142
|
+
assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
|
143
|
+
end
|
144
|
+
|
145
|
+
should "override options credentials if passed explicitly" do
|
146
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' },
|
147
|
+
{ :host => 'foobar2', :port => 1234 } ],
|
148
|
+
:options => { :user => 'foo2', :password => 'bar2' }
|
149
|
+
assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
|
150
|
+
assert_equal 'Basic Zm9vMjpiYXIy', transport.connections[1].connection.headers['Authorization']
|
151
|
+
end
|
152
|
+
|
153
|
+
should "set connection scheme to https if passed" do
|
154
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :scheme => 'https' } ]
|
155
|
+
|
156
|
+
assert_instance_of ::Faraday::Connection, transport.connections.first.connection
|
157
|
+
assert_equal 'https://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
|
158
|
+
end
|
159
|
+
|
160
|
+
should "set connection scheme to https if it exist in options" do
|
161
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234} ],
|
162
|
+
:options => { :scheme => 'https' }
|
163
|
+
|
164
|
+
assert_instance_of ::Faraday::Connection, transport.connections.first.connection
|
165
|
+
assert_equal 'https://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
|
166
|
+
end
|
167
|
+
|
168
|
+
should "override options scheme if passed explicitly" do
|
169
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :scheme => 'http'} ],
|
170
|
+
:options => { :scheme => 'https' }
|
171
|
+
|
172
|
+
assert_instance_of ::Faraday::Connection, transport.connections.first.connection
|
173
|
+
assert_equal 'http://foobar:1234/', transport.connections.first.connection.url_prefix.to_s
|
174
|
+
end
|
138
175
|
end
|
139
176
|
|
140
177
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|