elasticsearch-api 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8117b07c3656cd36592dc6a74685015a35a77125
4
- data.tar.gz: f9673514f128f2de7b6e11fbdf456cc890f96122
3
+ metadata.gz: 652b3135a6dcad857e8e846a1336b52d30ed66e9
4
+ data.tar.gz: 7df54d682afb2b0eab4ce19115a5a440fefc5c13
5
5
  SHA512:
6
- metadata.gz: 756a663f49e4f94ddf31c28430f39f1683cbb92da3eeee1cf6d3c9851f064f00328e02de0e37f59e5c95ff1157aab0bc1398a533f24fa6d12d58450e3f6ce5e1
7
- data.tar.gz: 0660cf068a76559597c9d17df4604c2d6855d615c98230ca242c231a35b60b1a0f0da324a3f148c464359072cb4a345becef650e70d43f6f276464541b7719c3
6
+ metadata.gz: 94fd554d9eaabeaea5157e58daed95780e4340688f2f611cb505cc31063cf25c8b950b1532af647c2273188f4e97ec081a12d6789a2dcfffd7dba0338c23f07c
7
+ data.tar.gz: 95a64b45a39de72b1b30f5b701d11f6cd0ad21b54f4918019efa40913ab0ff0b4749e76f4928712618c0900b453fb71520f55d5ff5eb82a5f3f5049cfd043f7b
@@ -51,12 +51,8 @@ module Elasticsearch
51
51
  params = Utils.__validate_and_extract_params arguments, valid_params
52
52
  body = nil
53
53
 
54
- perform_request(method, path, params, body).body
55
-
56
- rescue Exception => e
57
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
58
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
59
- else raise(e)
54
+ Utils.__rescue_from_not_found do
55
+ perform_request(method, path, params, body).body
60
56
  end
61
57
  end
62
58
  end
@@ -40,13 +40,9 @@ module Elasticsearch
40
40
  params = Utils.__validate_and_extract_params arguments, valid_params
41
41
  body = nil
42
42
 
43
- perform_request(method, path, params, body).status == 200 ? true : false
44
- rescue Exception => e
45
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
46
- false
47
- else
48
- raise e
49
- end
43
+ Utils.__rescue_from_not_found do
44
+ perform_request(method, path, params, body).status == 200 ? true : false
45
+ end
50
46
  end
51
47
 
52
48
  alias_method :exists?, :exists
@@ -61,12 +61,8 @@ module Elasticsearch
61
61
 
62
62
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
63
63
 
64
- perform_request(method, path, params, body).body
65
-
66
- rescue Exception => e
67
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
68
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
69
- else raise(e)
64
+ Utils.__rescue_from_not_found do
65
+ perform_request(method, path, params, body).body
70
66
  end
71
67
  end
72
68
  end
@@ -58,12 +58,8 @@ module Elasticsearch
58
58
 
59
59
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
60
60
 
61
- perform_request(method, path, params, body).body
62
-
63
- rescue Exception => e
64
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
65
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
66
- else raise(e)
61
+ Utils.__rescue_from_not_found do
62
+ perform_request(method, path, params, body).body
67
63
  end
68
64
  end
69
65
  end
@@ -16,11 +16,8 @@ module Elasticsearch
16
16
  params = {}
17
17
  body = arguments[:body]
18
18
 
19
- perform_request(method, path, params, body).body
20
- rescue Exception => e
21
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
22
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
23
- else raise(e)
19
+ Utils.__rescue_from_not_found do
20
+ perform_request(method, path, params, body).body
24
21
  end
25
22
  end
26
23
  end
@@ -38,12 +38,8 @@ module Elasticsearch
38
38
  params = Utils.__validate_and_extract_params arguments, valid_params
39
39
  body = nil
40
40
 
41
- perform_request(method, path, params, body).body
42
-
43
- rescue Exception => e
44
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
45
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
46
- else raise(e)
41
+ Utils.__rescue_from_not_found do
42
+ perform_request(method, path, params, body).body
47
43
  end
48
44
  end
49
45
  end
@@ -28,12 +28,8 @@ module Elasticsearch
28
28
  params = Utils.__validate_and_extract_params arguments, valid_params
29
29
  body = nil
30
30
 
31
- perform_request(method, path, params, body).body
32
-
33
- rescue Exception => e
34
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
35
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
36
- else raise(e)
31
+ Utils.__rescue_from_not_found do
32
+ perform_request(method, path, params, body).body
37
33
  end
38
34
  end
39
35
  end
@@ -42,12 +42,8 @@ module Elasticsearch
42
42
  params = Utils.__validate_and_extract_params arguments, valid_params
43
43
  body = nil
44
44
 
45
- perform_request(method, path, params, body).status == 200 ? true : false
46
- rescue Exception => e
47
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
48
- false
49
- else
50
- raise e
45
+ Utils.__rescue_from_not_found do
46
+ perform_request(method, path, params, body).status == 200 ? true : false
51
47
  end
52
48
  end
53
49
 
@@ -40,12 +40,8 @@ module Elasticsearch
40
40
  params = Utils.__validate_and_extract_params arguments, valid_params
41
41
  body = nil
42
42
 
43
- perform_request(method, path, params, body).status == 200 ? true : false
44
- rescue Exception => e
45
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
46
- false
47
- else
48
- raise e
43
+ Utils.__rescue_from_not_found do
44
+ perform_request(method, path, params, body).status == 200 ? true : false
49
45
  end
50
46
  end
51
47
 
@@ -23,12 +23,8 @@ module Elasticsearch
23
23
  params = Utils.__validate_and_extract_params arguments, valid_params
24
24
  body = nil
25
25
 
26
- perform_request(method, path, params, body).status == 200 ? true : false
27
- rescue Exception => e
28
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
29
- false
30
- else
31
- raise e
26
+ Utils.__rescue_from_not_found do
27
+ perform_request(method, path, params, body).status == 200 ? true : false
32
28
  end
33
29
  end
34
30
 
@@ -41,12 +41,8 @@ module Elasticsearch
41
41
  params = Utils.__validate_and_extract_params arguments, valid_params
42
42
  body = nil
43
43
 
44
- perform_request(method, path, params, body).status == 200 ? true : false
45
- rescue Exception => e
46
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
47
- false
48
- else
49
- raise e
44
+ Utils.__rescue_from_not_found do
45
+ perform_request(method, path, params, body).status == 200 ? true : false
50
46
  end
51
47
  end
52
48
 
@@ -0,0 +1,26 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Indices
4
+ module Actions
5
+
6
+ # "Seal" and index or indices for faster recovery
7
+ #
8
+ # @option arguments [List] :index A comma-separated list of index names;
9
+ # use `_all` or empty string for all indices
10
+ #
11
+ # @see http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-seal.html
12
+ #
13
+ def seal(arguments={})
14
+ valid_params = [
15
+ ]
16
+ method = 'POST'
17
+ path = Utils.__pathify Utils.__listify(arguments[:index]), '_seal'
18
+ params = {}
19
+ body = nil
20
+
21
+ perform_request(method, path, params, body).body
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -16,13 +16,9 @@ module Elasticsearch
16
16
  params = {}
17
17
  body = nil
18
18
 
19
- perform_request(method, path, params, body).status == 200 ? true : false
20
- rescue Exception => e
21
- if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
22
- false
23
- else
24
- raise e
25
- end
19
+ Utils.__rescue_from_not_found do
20
+ perform_request(method, path, params, body).status == 200 ? true : false
21
+ end
26
22
  end
27
23
  end
28
24
  end
@@ -94,12 +94,8 @@ module Elasticsearch
94
94
 
95
95
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
96
96
 
97
- perform_request(method, path, params, body).body
98
-
99
- rescue Exception => e
100
- # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
101
- if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
102
- else raise(e)
97
+ Utils.__rescue_from_not_found do
98
+ perform_request(method, path, params, body).body
103
99
  end
104
100
  end
105
101
  end
@@ -178,6 +178,23 @@ module Elasticsearch
178
178
  return parts
179
179
  end
180
180
 
181
+ # Calls given block, rescuing from any exceptions. Returns `false`
182
+ # if exception contains NotFound/404 in its class name or message, else re-raises exception.
183
+ #
184
+ # @yield [block] A block of code to be executed with exception handling.
185
+ #
186
+ # @api private
187
+ #
188
+ def __rescue_from_not_found(&block)
189
+ yield
190
+ rescue Exception => e
191
+ if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
192
+ false
193
+ else
194
+ raise e
195
+ end
196
+ end
197
+
181
198
  extend self
182
199
  end
183
200
  end
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module API
3
- VERSION = "1.0.9"
3
+ VERSION = "1.0.10"
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IndicesSealTest < ::Test::Unit::TestCase
6
+
7
+ context "Indices: Seal" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform correct request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'POST', method
13
+ assert_equal 'foo/_seal', url
14
+ assert_nil body
15
+ true
16
+ end.returns(FakeResponse.new)
17
+
18
+ subject.indices.seal :index => 'foo'
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -200,6 +200,28 @@ module Elasticsearch
200
200
 
201
201
  end
202
202
 
203
+ context "__rescue_from_not_found" do
204
+
205
+ should "return false if exception class name contains 'NotFound'" do
206
+ assert_equal( false, __rescue_from_not_found { raise NotFound })
207
+ end
208
+
209
+ should "return false if exception message contains 'Not Found'" do
210
+ assert_equal( false, __rescue_from_not_found { raise Exception.new "Not Found" })
211
+ end
212
+
213
+ should "return false if exception message contains '404'" do
214
+ assert_equal( false, __rescue_from_not_found { raise Exception.new "404" })
215
+ end
216
+
217
+ should "raise exception if exception class name and message do not contain NotFound/404" do
218
+ assert_raise Exception do
219
+ __rescue_from_not_found { raise Exception.new "Any other exception" }
220
+ end
221
+ end
222
+
223
+ end
224
+
203
225
  end
204
226
  end
205
227
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
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-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -421,6 +421,7 @@ files:
421
421
  - lib/elasticsearch/api/actions/indices/put_warmer.rb
422
422
  - lib/elasticsearch/api/actions/indices/recovery.rb
423
423
  - lib/elasticsearch/api/actions/indices/refresh.rb
424
+ - lib/elasticsearch/api/actions/indices/seal.rb
424
425
  - lib/elasticsearch/api/actions/indices/segments.rb
425
426
  - lib/elasticsearch/api/actions/indices/snapshot_index.rb
426
427
  - lib/elasticsearch/api/actions/indices/stats.rb
@@ -544,6 +545,7 @@ files:
544
545
  - test/unit/indices/put_warmer_test.rb
545
546
  - test/unit/indices/recovery_test.rb
546
547
  - test/unit/indices/refresh_test.rb
548
+ - test/unit/indices/seal_test.rb
547
549
  - test/unit/indices/segments_test.rb
548
550
  - test/unit/indices/snapshot_index_test.rb
549
551
  - test/unit/indices/stats_test.rb
@@ -695,6 +697,7 @@ test_files:
695
697
  - test/unit/indices/put_warmer_test.rb
696
698
  - test/unit/indices/recovery_test.rb
697
699
  - test/unit/indices/refresh_test.rb
700
+ - test/unit/indices/seal_test.rb
698
701
  - test/unit/indices/segments_test.rb
699
702
  - test/unit/indices/snapshot_index_test.rb
700
703
  - test/unit/indices/stats_test.rb