elasticsearch-transport 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/elasticsearch-transport.gemspec +2 -1
- data/lib/elasticsearch/transport/client.rb +18 -18
- data/lib/elasticsearch/transport/transport/connections/collection.rb +1 -1
- data/lib/elasticsearch/transport/transport/http/curb.rb +0 -1
- data/lib/elasticsearch/transport/transport/http/manticore.rb +24 -19
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/test/integration/transport_test.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/test/unit/client_test.rb +5 -0
- data/test/unit/connection_collection_test.rb +5 -0
- data/test/unit/transport_manticore_test.rb +1 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85aa43e17d7dbb5e43514c2c6c8d61030db7bf0f
|
4
|
+
data.tar.gz: 7220157362dbd60f5f003fbe457cb97d5f03983f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e86b6d6fdd5d38114b5a8ff506c114a0270d6ee8bccade584badb9bb5aac51c59f181afa162cfb8cfb5da01b9967507a513dafa1a3e157eed20874253424fd4d
|
7
|
+
data.tar.gz: 44569f981a390c4ad0f1a4bb5a3cb766bd03f5fd114f384c4a705c5b59bf69d73759b0e75b445ecd5b4ca7e67a0e9239f4ae8faad76d4228ac281626657dff12
|
data/README.md
CHANGED
@@ -27,10 +27,11 @@ Features overview:
|
|
27
27
|
* Request retries and dead connections handling
|
28
28
|
* Node reloading (based on cluster state) on errors or on demand
|
29
29
|
|
30
|
-
For optimal performance,
|
31
|
-
|
32
|
-
Just
|
33
|
-
and it will be automatically used;
|
30
|
+
For optimal performance, use a HTTP library which supports persistent ("keep-alive") connections,
|
31
|
+
such as [Typhoeus](https://github.com/typhoeus/typhoeus).
|
32
|
+
Just require the library (`require 'typhoeus'; require 'typhoeus/adapters/faraday'`) in your code,
|
33
|
+
and it will be automatically used; currently these libraries will be automatically detected and used:
|
34
|
+
[Patron](https://github.com/toland/patron),
|
34
35
|
[HTTPClient](https://rubygems.org/gems/httpclient) and
|
35
36
|
[Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent).
|
36
37
|
|
@@ -170,7 +171,8 @@ on a different host:
|
|
170
171
|
|
171
172
|
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: true
|
172
173
|
|
173
|
-
You can specify how many times should the client retry the request before it raises an exception
|
174
|
+
You can specify how many times should the client retry the request before it raises an exception
|
175
|
+
(the default is 3 times):
|
174
176
|
|
175
177
|
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: 5
|
176
178
|
|
@@ -46,7 +46,8 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_development_dependency "curb" unless defined? JRUBY_VERSION
|
47
47
|
s.add_development_dependency "patron" unless defined? JRUBY_VERSION
|
48
48
|
s.add_development_dependency "typhoeus", '~> 0.6'
|
49
|
-
s.add_development_dependency "manticore" if defined? JRUBY_VERSION
|
49
|
+
s.add_development_dependency "manticore", '~> 0.3.5' if defined? JRUBY_VERSION
|
50
|
+
s.add_development_dependency "hashie"
|
50
51
|
|
51
52
|
# Prevent unit test failures on Ruby 1.8
|
52
53
|
if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
@@ -128,7 +128,7 @@ module Elasticsearch
|
|
128
128
|
# @api private
|
129
129
|
#
|
130
130
|
def __extract_hosts(hosts_config, options={})
|
131
|
-
if hosts_config.
|
131
|
+
if hosts_config.is_a?(Hash)
|
132
132
|
hosts = [ hosts_config ]
|
133
133
|
else
|
134
134
|
if hosts_config.is_a?(String) && hosts_config.include?(',')
|
@@ -136,29 +136,29 @@ module Elasticsearch
|
|
136
136
|
else
|
137
137
|
hosts = Array(hosts_config)
|
138
138
|
end
|
139
|
+
end
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
else
|
147
|
-
host, port = host.split(':')
|
148
|
-
{ :host => host, :port => port }
|
149
|
-
end
|
150
|
-
when URI
|
151
|
-
{ :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
|
152
|
-
when Hash
|
153
|
-
host
|
141
|
+
result = hosts.map do |host|
|
142
|
+
case host
|
143
|
+
when String
|
144
|
+
if host =~ /^[a-z]+\:\/\//
|
145
|
+
uri = URI.parse(host)
|
146
|
+
{ :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
|
154
147
|
else
|
155
|
-
|
148
|
+
host, port = host.split(':')
|
149
|
+
{ :host => host, :port => port }
|
156
150
|
end
|
151
|
+
when URI
|
152
|
+
{ :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
|
153
|
+
when Hash
|
154
|
+
host
|
155
|
+
else
|
156
|
+
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
|
161
|
-
|
160
|
+
result.shuffle! if options[:randomize_hosts]
|
161
|
+
result
|
162
162
|
end
|
163
163
|
|
164
164
|
# Auto-detect the best adapter (HTTP "driver") available, based on libraries
|
@@ -23,7 +23,7 @@ module Elasticsearch
|
|
23
23
|
def initialize(arguments={})
|
24
24
|
selector_class = arguments[:selector_class] || DEFAULT_SELECTOR
|
25
25
|
@connections = arguments[:connections] || []
|
26
|
-
@selector = arguments[:selector] || selector_class.new(arguments)
|
26
|
+
@selector = arguments[:selector] || selector_class.new(arguments.merge(:connections => self))
|
27
27
|
end
|
28
28
|
|
29
29
|
# Returns an Array of hosts information in this collection as Hashes.
|
@@ -7,7 +7,7 @@ module Elasticsearch
|
|
7
7
|
# Alternative HTTP transport implementation for JRuby,
|
8
8
|
# using the [_Manticore_](https://github.com/cheald/manticore) client,
|
9
9
|
#
|
10
|
-
# @example
|
10
|
+
# @example HTTP
|
11
11
|
#
|
12
12
|
# require 'elasticsearch/transport/transport/http/manticore'
|
13
13
|
#
|
@@ -19,6 +19,27 @@ module Elasticsearch
|
|
19
19
|
# client.info['status']
|
20
20
|
# => 200
|
21
21
|
#
|
22
|
+
# @example HTTPS (All SSL settings are optional,
|
23
|
+
# see http://www.rubydoc.info/gems/manticore/Manticore/Client:initialize)
|
24
|
+
#
|
25
|
+
# require 'elasticsearch/transport/transport/http/manticore'
|
26
|
+
#
|
27
|
+
# client = Elasticsearch::Client.new \
|
28
|
+
# url: 'https://elasticsearch.example.com',
|
29
|
+
# transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore,
|
30
|
+
# ssl: {
|
31
|
+
# truststore: '/tmp/truststore.jks',
|
32
|
+
# truststore_password: 'password',
|
33
|
+
# keystore: '/tmp/keystore.jks',
|
34
|
+
# keystore_password: 'secret',
|
35
|
+
# }
|
36
|
+
#
|
37
|
+
# client.transport.connections.first.connection
|
38
|
+
# => #<Manticore::Client:0xdeadbeef ...>
|
39
|
+
#
|
40
|
+
# client.info['status']
|
41
|
+
# => 200
|
42
|
+
#
|
22
43
|
# @see Transport::Base
|
23
44
|
#
|
24
45
|
class Manticore
|
@@ -63,7 +84,7 @@ module Elasticsearch
|
|
63
84
|
@request_options[:headers] = options[:headers]
|
64
85
|
end
|
65
86
|
|
66
|
-
client_options =
|
87
|
+
client_options = {:ssl => options[:ssl] || {}}
|
67
88
|
|
68
89
|
Connections::Collection.new \
|
69
90
|
:connections => hosts.map { |host|
|
@@ -77,7 +98,7 @@ module Elasticsearch
|
|
77
98
|
|
78
99
|
Connections::Connection.new \
|
79
100
|
:host => host,
|
80
|
-
:connection => ::Manticore::Client.new(
|
101
|
+
:connection => ::Manticore::Client.new(client_options)
|
81
102
|
},
|
82
103
|
:selector_class => options[:selector_class],
|
83
104
|
:selector => options[:selector]
|
@@ -95,22 +116,6 @@ module Elasticsearch
|
|
95
116
|
::Manticore::ResolutionFailure
|
96
117
|
]
|
97
118
|
end
|
98
|
-
|
99
|
-
private
|
100
|
-
# TODO: not threadsafe
|
101
|
-
def setup_ssl(ssl_options)
|
102
|
-
if ssl_options[:truststore]
|
103
|
-
java.lang.System.setProperty "javax.net.ssl.trustStore", ssl_options[:truststore]
|
104
|
-
end
|
105
|
-
if ssl_options[:truststore_password]
|
106
|
-
java.lang.System.setProperty "javax.net.ssl.trustStorePassword", ssl_options[:truststore_password]
|
107
|
-
end
|
108
|
-
if ssl_options[:verify] == false then
|
109
|
-
{ :ignore_ssl_validation => true }
|
110
|
-
else
|
111
|
-
{}
|
112
|
-
end
|
113
|
-
end
|
114
119
|
end
|
115
120
|
end
|
116
121
|
end
|
@@ -65,7 +65,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
65
65
|
response = client.perform_request 'GET', ''
|
66
66
|
|
67
67
|
assert_respond_to(response.body, :to_hash)
|
68
|
-
assert_not_nil response.body['
|
68
|
+
assert_not_nil response.body['name']
|
69
69
|
assert_equal 'application/json', response.headers['content-type']
|
70
70
|
end unless JRUBY
|
71
71
|
end
|
data/test/test_helper.rb
CHANGED
data/test/unit/client_test.rb
CHANGED
@@ -115,7 +115,12 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
|
|
115
115
|
|
116
116
|
should "extract from hash" do
|
117
117
|
hosts = @client.__extract_hosts( { :host => 'myhost', :scheme => 'https' } )
|
118
|
+
assert_equal 'myhost', hosts[0][:host]
|
119
|
+
assert_equal 'https', hosts[0][:scheme]
|
120
|
+
end
|
118
121
|
|
122
|
+
should "extract from Hashie::Mash" do
|
123
|
+
hosts = @client.__extract_hosts( Hashie::Mash.new(:host => 'myhost', :scheme => 'https') )
|
119
124
|
assert_equal 'myhost', hosts[0][:host]
|
120
125
|
assert_equal 'https', hosts[0][:scheme]
|
121
126
|
end
|
@@ -60,6 +60,11 @@ class Elasticsearch::Transport::Transport::Connections::CollectionTest < Test::U
|
|
60
60
|
assert_equal ['BAR'], @collection.dead.map { |c| c.host.upcase }
|
61
61
|
end
|
62
62
|
|
63
|
+
should "not return dead connections, when alive connections exist" do
|
64
|
+
assert_equal 1, @collection.size
|
65
|
+
@collection.all.size.times { refute @collection.get_connection.dead? }
|
66
|
+
end
|
67
|
+
|
63
68
|
should "resurrect dead connection with least failures when no alive is available" do
|
64
69
|
c1 = Connection.new(:host => 'foo').dead!.dead!
|
65
70
|
c2 = Connection.new(:host => 'bar').dead!
|
@@ -99,12 +99,8 @@ else
|
|
99
99
|
}
|
100
100
|
}
|
101
101
|
|
102
|
-
::Manticore::Client.expects(:new).with(
|
103
|
-
|
102
|
+
::Manticore::Client.expects(:new).with(options)
|
104
103
|
transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
|
105
|
-
|
106
|
-
assert_equal java.lang.System.getProperty("javax.net.ssl.trustStore"), "test.jks"
|
107
|
-
assert_equal java.lang.System.getProperty("javax.net.ssl.trustStorePassword"), "test"
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
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.9
|
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-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0.6'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: hashie
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: minitest
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|