elastomer-client 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/docs/notifications.md +17 -5
- data/lib/elastomer/client.rb +18 -3
- data/lib/elastomer/client/bulk.rb +0 -1
- data/lib/elastomer/client/cluster.rb +97 -33
- data/lib/elastomer/client/docs.rb +0 -1
- data/lib/elastomer/client/errors.rb +50 -20
- data/lib/elastomer/client/index.rb +59 -1
- data/lib/elastomer/client/nodes.rb +43 -12
- data/lib/elastomer/client/repository.rb +127 -0
- data/lib/elastomer/client/snapshot.rb +127 -0
- data/lib/elastomer/version.rb +1 -1
- data/test/client/cluster_test.rb +33 -0
- data/test/client/docs_test.rb +5 -5
- data/test/client/errors_test.rb +48 -0
- data/test/client/index_test.rb +24 -0
- data/test/client/multi_search_test.rb +4 -4
- data/test/client/nodes_test.rb +24 -2
- data/test/client/repository_test.rb +108 -0
- data/test/client/snapshot_test.rb +111 -0
- data/test/client/template_test.rb +6 -0
- data/test/middleware/opaque_id_test.rb +3 -0
- data/test/test_helper.rb +18 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3bb86cf79cf4c35faa602b5b887790916354830
|
4
|
+
data.tar.gz: 0d20d421a0c1c396efaaa01edfc0c7eb621deb37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0043c22c958488f7952e814a05390df0dfb1b3746414b66d33b22ea5951f489155bd2ac820d47c541f9b3146f73a1a7a9c93af0b88769318ff1229bf112a160e
|
7
|
+
data.tar.gz: ca7cf1438d19f70fa2f73bf4b2ff7a22e8ef74453f8914dfa646b83163b4df0a4216fbd6cc5666b153dc2bcebd3af602f7240f28b449b22f07d61808fd27a608
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
## 0.4.0 (2014-10-08)
|
2
|
+
- BREAKING: docs.add alias for docs.index removed
|
3
|
+
- BREAKING: Faraday exceptions are now raised as Elastomer exceptions
|
4
|
+
- Repository and snapshot support
|
5
|
+
- Support cluster state filtering on 1.x
|
6
|
+
- Support node stats filtering on 1.x
|
7
|
+
- New apis: cluster stats, cluster pending\_tasks
|
8
|
+
- Support single-index alias get, add, delete
|
9
|
+
|
1
10
|
## 0.3.3 (2014-08-18)
|
2
11
|
- Allow symbols as parameter values #67
|
12
|
+
|
3
13
|
## 0.3.2 (2014-07-02)
|
4
14
|
- Make underscore optional in bulk params #66
|
15
|
+
|
5
16
|
## 0.3.1 (2014-06-24)
|
6
17
|
- First rubygems release
|
7
18
|
- Make `update_aliases` more flexible
|
data/docs/notifications.md
CHANGED
@@ -20,16 +20,16 @@ The event namespace is `request.client.elastomer`.
|
|
20
20
|
|
21
21
|
## Valid actions
|
22
22
|
- bulk
|
23
|
-
- cluster.get_settings
|
24
|
-
- cluster.health
|
25
|
-
- cluster.reroute
|
26
|
-
- cluster.state
|
27
|
-
- cluster.update_settings
|
28
23
|
- cluster.available
|
29
24
|
- cluster.get_aliases
|
25
|
+
- cluster.get_settings
|
26
|
+
- cluster.health
|
30
27
|
- cluster.info
|
28
|
+
- cluster.reroute
|
31
29
|
- cluster.shutdown
|
30
|
+
- cluster.state
|
32
31
|
- cluster.update_aliases
|
32
|
+
- cluster.update_settings
|
33
33
|
- docs.delete
|
34
34
|
- docs.delete_by_query
|
35
35
|
- docs.explain
|
@@ -65,7 +65,19 @@ The event namespace is `request.client.elastomer`.
|
|
65
65
|
- nodes.info
|
66
66
|
- nodes.shutdown
|
67
67
|
- nodes.stats
|
68
|
+
- repository.create
|
69
|
+
- repository.delete
|
70
|
+
- repository.exists
|
71
|
+
- repository.get
|
72
|
+
- repository.status
|
73
|
+
- repository.update
|
68
74
|
- search.scan
|
69
75
|
- search.scroll
|
76
|
+
- snapshot.create
|
77
|
+
- snapshot.delete
|
78
|
+
- snapshot.exists
|
79
|
+
- snapshot.get
|
80
|
+
- snapshot.restore
|
81
|
+
- snapshot.status
|
70
82
|
- template.create
|
71
83
|
- template.get
|
data/lib/elastomer/client.rb
CHANGED
@@ -188,7 +188,22 @@ module Elastomer
|
|
188
188
|
handle_errors response
|
189
189
|
|
190
190
|
rescue Faraday::Error::TimeoutError => boom
|
191
|
-
raise
|
191
|
+
raise TimeoutError.new(boom, method.upcase, path)
|
192
|
+
|
193
|
+
rescue Faraday::Error::ConnectionFailed => boom
|
194
|
+
raise ConnectionFailed.new(boom, method.upcase, path)
|
195
|
+
|
196
|
+
rescue Faraday::Error::ResourceNotFound => boom
|
197
|
+
raise ResourceNotFound.new(boom, method.upcase, path)
|
198
|
+
|
199
|
+
rescue Faraday::Error::ParsingError => boom
|
200
|
+
raise ParsingError.new(boom, method.upcase, path)
|
201
|
+
|
202
|
+
rescue Faraday::Error::SSLError => boom
|
203
|
+
raise SSLError.new(boom, method.upcase, path)
|
204
|
+
|
205
|
+
rescue Faraday::Error::ClientError => boom
|
206
|
+
raise Error.new(boom, method.upcase, path)
|
192
207
|
|
193
208
|
# ensure
|
194
209
|
# # FIXME: this is here until we get a real logger in place
|
@@ -259,8 +274,8 @@ module Elastomer
|
|
259
274
|
# Raises an Elastomer::Client::Error on 500 responses or responses
|
260
275
|
# containing and 'error' field.
|
261
276
|
def handle_errors( response )
|
262
|
-
raise
|
263
|
-
raise
|
277
|
+
raise ServerError, response if response.status >= 500
|
278
|
+
raise RequestError, response if Hash === response.body && response.body['error']
|
264
279
|
|
265
280
|
response
|
266
281
|
end
|
@@ -135,7 +135,6 @@ module Elastomer
|
|
135
135
|
params = prepare_params(document, params)
|
136
136
|
add_to_actions({:index => params}, document)
|
137
137
|
end
|
138
|
-
alias :add :index
|
139
138
|
|
140
139
|
# Add a create action to the list of bulk actions to be performed when
|
141
140
|
# the bulk API call is made. Parameters can be provided in the
|
@@ -19,10 +19,18 @@ module Elastomer
|
|
19
19
|
|
20
20
|
attr_reader :client
|
21
21
|
|
22
|
-
# Simple status on the health of the cluster.
|
23
|
-
#
|
22
|
+
# Simple status on the health of the cluster. The API can also be executed
|
23
|
+
# against one or more indices to get just the specified indices health.
|
24
24
|
#
|
25
25
|
# params - Parameters Hash
|
26
|
+
# :index - a single index name or an Array of index names
|
27
|
+
# :level - one of "cluster", "indices", or "shards"
|
28
|
+
# :wait_for_status - one of "green", "yellow", or "red"
|
29
|
+
# :wait_for_relocating_shards - a number controlling to how many relocating shards to wait for
|
30
|
+
# :wait_for_nodes - the request waits until the specified number N of nodes is available
|
31
|
+
# :timeout - how long to wait [default is "30s"]
|
32
|
+
#
|
33
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html
|
26
34
|
#
|
27
35
|
# Returns the response as a Hash
|
28
36
|
def health( params = {} )
|
@@ -30,22 +38,58 @@ module Elastomer
|
|
30
38
|
response.body
|
31
39
|
end
|
32
40
|
|
33
|
-
# Comprehensive state information of the whole cluster.
|
34
|
-
#
|
41
|
+
# Comprehensive state information of the whole cluster. For 1.x metric
|
42
|
+
# and index filtering, use the :metrics and :indices parameter keys.
|
43
|
+
#
|
44
|
+
# The list of available metrics are:
|
45
|
+
# version, master_node, nodes, routing_table, metadata, blocks
|
35
46
|
#
|
36
47
|
# params - Parameters Hash
|
48
|
+
# :metrics - list of metrics to select as an Array
|
49
|
+
# :indices - a single index name or an Array of index names
|
50
|
+
#
|
51
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html
|
37
52
|
#
|
38
53
|
# Returns the response as a Hash
|
39
54
|
def state( params = {} )
|
40
|
-
response = client.get '/_cluster/state', params.merge(:action => 'cluster.state')
|
55
|
+
response = client.get '/_cluster/state{/metrics}{/indices}', params.merge(:action => 'cluster.state')
|
56
|
+
response.body
|
57
|
+
end
|
58
|
+
|
59
|
+
# Retrieve statistics from a cluster wide perspective. The API returns
|
60
|
+
# basic index metrics (shard numbers, store size, memory usage) and
|
61
|
+
# information about the current nodes that form the cluster (number,
|
62
|
+
# roles, os, jvm versions, memory usage, cpu and installed plugins).
|
63
|
+
#
|
64
|
+
# params - Parameters Hash
|
65
|
+
#
|
66
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-stats.html
|
67
|
+
#
|
68
|
+
# Returns the response as a Hash
|
69
|
+
def stats( params = {} )
|
70
|
+
response = client.get '/_cluster/stats', params.merge(:action => 'cluster.stats')
|
71
|
+
response.body
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns a list of any cluster-level changes (e.g. create index, update
|
75
|
+
# mapping, allocate or fail shard) which have not yet been executed.
|
76
|
+
#
|
77
|
+
# params - Parameters Hash
|
78
|
+
#
|
79
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-pending.html
|
80
|
+
#
|
81
|
+
# Returns the response as a Hash
|
82
|
+
def pending_tasks( params = {} )
|
83
|
+
response = client.get '/_cluster/pending_tasks', params.merge(:action => 'cluster.pending_tasks')
|
41
84
|
response.body
|
42
85
|
end
|
43
86
|
|
44
87
|
# Cluster wide settings that have been modified via the update API.
|
45
|
-
# See http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
|
46
88
|
#
|
47
89
|
# params - Parameters Hash
|
48
90
|
#
|
91
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html
|
92
|
+
#
|
49
93
|
# Returns the response as a Hash
|
50
94
|
def get_settings( params = {} )
|
51
95
|
response = client.get '/_cluster/settings', params.merge(:action => 'cluster.get_settings')
|
@@ -57,11 +101,11 @@ module Elastomer
|
|
57
101
|
# persistent (applied cross restarts) or transient (will not survive a
|
58
102
|
# full cluster restart).
|
59
103
|
#
|
60
|
-
# See http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
|
61
|
-
#
|
62
104
|
# body - The new settings as a Hash or a JSON encoded String
|
63
105
|
# params - Parameters Hash
|
64
106
|
#
|
107
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html
|
108
|
+
#
|
65
109
|
# Returns the response as a Hash
|
66
110
|
def update_settings( body, params = {} )
|
67
111
|
response = client.put '/_cluster/settings', params.merge(:body => body, :action => 'cluster.update_settings')
|
@@ -73,8 +117,6 @@ module Elastomer
|
|
73
117
|
# allocation can be canceled, or an unassigned shard can be explicitly
|
74
118
|
# allocated on a specific node.
|
75
119
|
#
|
76
|
-
# See http://www.elasticsearch.org/guide/reference/api/admin-cluster-reroute/
|
77
|
-
#
|
78
120
|
# commands - A command Hash or an Array of command Hashes
|
79
121
|
# params - Parameters Hash
|
80
122
|
#
|
@@ -87,20 +129,23 @@ module Elastomer
|
|
87
129
|
# { :allocate => { :index => 'test', :shard => 1, :node => 'node3' }}
|
88
130
|
# ])
|
89
131
|
#
|
132
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-reroute.html
|
133
|
+
#
|
90
134
|
# Returns the response as a Hash
|
91
135
|
def reroute( commands, params = {} )
|
92
|
-
|
93
|
-
body = {:commands => commands}
|
136
|
+
body = {:commands => Array(commands)}
|
94
137
|
|
95
138
|
response = client.post '/_cluster/reroute', params.merge(:body => body, :action => 'cluster.reroute')
|
96
139
|
response.body
|
97
140
|
end
|
98
141
|
|
99
|
-
# Shutdown the entire cluster.
|
100
|
-
#
|
142
|
+
# Shutdown the entire cluster. There is also a Nodes#shutdown method for
|
143
|
+
# shutting down individual nodes.
|
101
144
|
#
|
102
145
|
# params - Parameters Hash
|
103
146
|
#
|
147
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html
|
148
|
+
#
|
104
149
|
# Returns the response as a Hash
|
105
150
|
def shutdown( params = {} )
|
106
151
|
response = client.post '/_shutdown', params.merge(:action => 'cluster.shutdown')
|
@@ -112,15 +157,16 @@ module Elastomer
|
|
112
157
|
# can also use the alias name here since it is acting the part of an
|
113
158
|
# index.
|
114
159
|
#
|
115
|
-
# See http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
|
116
|
-
#
|
117
160
|
# params - Parameters Hash
|
161
|
+
# :index - an index name or Array of index names
|
118
162
|
#
|
119
163
|
# Examples
|
120
164
|
#
|
121
165
|
# get_aliases
|
122
166
|
# get_aliases( :index => 'users' )
|
123
167
|
#
|
168
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
|
169
|
+
#
|
124
170
|
# Returns the response body as a Hash
|
125
171
|
def get_aliases( params = {} )
|
126
172
|
response = client.get '{/index}/_aliases', params.merge(:action => 'cluster.get_aliases')
|
@@ -133,8 +179,6 @@ module Elastomer
|
|
133
179
|
# actions. This API method will wrap the request in the appropriate
|
134
180
|
# {:actions => [...]} body construct.
|
135
181
|
#
|
136
|
-
# See http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
|
137
|
-
#
|
138
182
|
# actions - An action Hash or an Array of action Hashes
|
139
183
|
# params - Parameters Hash
|
140
184
|
#
|
@@ -147,6 +191,8 @@ module Elastomer
|
|
147
191
|
# { :add => { :index => 'users-2', :alias => 'users' }}
|
148
192
|
# ])
|
149
193
|
#
|
194
|
+
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
|
195
|
+
#
|
150
196
|
# Returns the response body as a Hash
|
151
197
|
def update_aliases( actions, params = {} )
|
152
198
|
if actions.is_a?(Hash) && actions.key?(:actions)
|
@@ -168,11 +214,17 @@ module Elastomer
|
|
168
214
|
#
|
169
215
|
# Returns the template definitions as a Hash
|
170
216
|
def templates
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
:
|
175
|
-
|
217
|
+
# ES 1.x supports state filtering via a path segment called metrics.
|
218
|
+
# ES 0.90 uses query parameters instead.
|
219
|
+
if client.semantic_version >= '1.0.0'
|
220
|
+
h = state(:metrics => 'metadata')
|
221
|
+
else
|
222
|
+
h = state(
|
223
|
+
:filter_blocks => true,
|
224
|
+
:filter_nodes => true,
|
225
|
+
:filter_routing_table => true,
|
226
|
+
)
|
227
|
+
end
|
176
228
|
h['metadata']['templates']
|
177
229
|
end
|
178
230
|
|
@@ -181,11 +233,17 @@ module Elastomer
|
|
181
233
|
#
|
182
234
|
# Returns the indices definitions as a Hash
|
183
235
|
def indices
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
:
|
188
|
-
|
236
|
+
# ES 1.x supports state filtering via a path segment called metrics.
|
237
|
+
# ES 0.90 uses query parameters instead.
|
238
|
+
if client.semantic_version >= '1.0.0'
|
239
|
+
h = state(:metrics => 'metadata')
|
240
|
+
else
|
241
|
+
h = state(
|
242
|
+
:filter_blocks => true,
|
243
|
+
:filter_nodes => true,
|
244
|
+
:filter_routing_table => true,
|
245
|
+
)
|
246
|
+
end
|
189
247
|
h['metadata']['indices']
|
190
248
|
end
|
191
249
|
|
@@ -195,11 +253,17 @@ module Elastomer
|
|
195
253
|
#
|
196
254
|
# Returns the nodes definitions as a Hash
|
197
255
|
def nodes
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
:
|
202
|
-
|
256
|
+
# ES 1.x supports state filtering via a path segment called metrics.
|
257
|
+
# ES 0.90 uses query parameters instead.
|
258
|
+
if client.semantic_version >= '1.0.0'
|
259
|
+
h = state(:metrics => 'nodes')
|
260
|
+
else
|
261
|
+
h = state(
|
262
|
+
:filter_blocks => true,
|
263
|
+
:filter_metadata => true,
|
264
|
+
:filter_routing_table => true,
|
265
|
+
)
|
266
|
+
end
|
203
267
|
h['nodes']
|
204
268
|
end
|
205
269
|
|
@@ -14,38 +14,68 @@ module Elastomer
|
|
14
14
|
# extracted from the response body.
|
15
15
|
#
|
16
16
|
# response - Faraday::Response object or a simple error message String
|
17
|
-
|
18
|
-
|
17
|
+
#
|
18
|
+
def initialize( *args )
|
19
|
+
@status = nil
|
20
|
+
|
21
|
+
case args.first
|
22
|
+
when Exception
|
23
|
+
exception = args.shift
|
24
|
+
super("#{exception.message} :: #{args.join(' ')}")
|
25
|
+
set_backtrace exception.backtrace
|
26
|
+
|
27
|
+
when Faraday::Response
|
28
|
+
response = args.shift
|
19
29
|
message = Hash === response.body && response.body['error'] || response.body.to_s
|
30
|
+
@status = response.status
|
31
|
+
super message
|
32
|
+
|
20
33
|
else
|
21
|
-
|
34
|
+
super args.join(' ')
|
22
35
|
end
|
23
|
-
|
24
|
-
@status = response.nil? ? nil : response.status
|
25
|
-
|
26
|
-
super message
|
27
36
|
end
|
28
37
|
|
29
38
|
# Returns the status code from the `response` or nil if the Error was not
|
30
39
|
# created with a response.
|
31
40
|
attr_reader :status
|
32
41
|
|
33
|
-
|
42
|
+
# Indicates that the error is fatal. The request should not be tried
|
43
|
+
# again.
|
44
|
+
def fatal?
|
45
|
+
self.class.fatal?
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
48
|
+
# The inverse of the `fatal?` method. A request can be retried if this
|
49
|
+
# method returns `true`.
|
50
|
+
def retry?
|
51
|
+
!fatal?
|
52
|
+
end
|
37
53
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
54
|
+
class << self
|
55
|
+
# By default all client errors are fatal and indicate that a request
|
56
|
+
# should not be retried. Only a few errors are retryable.
|
57
|
+
def fatal
|
58
|
+
return @fatal if defined? @fatal
|
59
|
+
@fatal = true
|
60
|
+
end
|
61
|
+
attr_writer :fatal
|
62
|
+
alias :fatal? :fatal
|
47
63
|
end
|
48
|
-
|
64
|
+
|
65
|
+
end # Error
|
66
|
+
|
67
|
+
# Wrapper classes for specific Faraday errors.
|
68
|
+
TimeoutError = Class.new Error
|
69
|
+
ConnectionFailed = Class.new Error
|
70
|
+
ResourceNotFound = Class.new Error
|
71
|
+
ParsingError = Class.new Error
|
72
|
+
SSLError = Class.new Error
|
73
|
+
ServerError = Class.new Error
|
74
|
+
RequestError = Class.new Error
|
75
|
+
|
76
|
+
ServerError.fatal = false
|
77
|
+
TimeoutError.fatal = false
|
78
|
+
ConnectionFailed.fatal = false
|
49
79
|
|
50
80
|
end # Client
|
51
81
|
end # Elastomer
|