@@ -181,22 +181,15 @@ def join_bulk_responses(bulk_responses)
181
181
182
182
def bulk_send ( body_stream , batch_actions )
183
183
params = compression_level? ? { :headers => { "Content-Encoding" => "gzip" } } : { }
184
-
185
184
response = @pool . post ( @bulk_path , params , body_stream . string )
186
-
187
185
@bulk_response_metrics . increment ( response . code . to_s )
188
186
189
- case response . code
190
- when 200 # OK
187
+ if response . code == 200
191
188
LogStash ::Json . load ( response . body )
192
- when 413 # Payload Too Large
193
- logger . warn ( "Bulk request rejected: `413 Payload Too Large`" , :action_count => batch_actions . size , :content_length => body_stream . size )
194
- emulate_batch_error_response ( batch_actions , response . code , 'payload_too_large' )
195
189
else
190
+ logger . warn ( "Bulk request rejected: `413 Payload Too Large`" , :action_count => batch_actions . size , :content_length => body_stream . size ) if response . code == 413
196
191
url = ::LogStash ::Util ::SafeURI . new ( response . final_url )
197
- raise ::LogStash ::Outputs ::ElasticSearch ::HttpClient ::Pool ::BadResponseCodeError . new (
198
- response . code , url , body_stream . to_s , response . body
199
- )
192
+ raise ::LogStash ::Outputs ::ElasticSearch ::HttpClient ::Pool ::BadResponseCodeError . new ( response . code , url , body_stream . to_s , response . body )
200
193
end
201
194
end
202
195
@@ -414,13 +407,21 @@ def exists?(path, use_get=false)
414
407
end
415
408
416
409
def template_exists? ( template_endpoint , name )
417
- exists? ( "/#{ template_endpoint } /#{ name } " )
410
+ response = @pool . get ( "/#{ template_endpoint } /#{ name } " )
411
+ return true if response . code >= 200 && response . code <= 299
412
+ return false if response . code == 404
413
+ url = ::LogStash ::Util ::SafeURI . new ( response . final_url )
414
+ raise BadResponseCodeError . new ( response . code , url , nil , response . body )
418
415
end
419
416
420
417
def template_put ( template_endpoint , name , template )
421
- path = "#{ template_endpoint } /#{ name } "
422
418
logger . info ( "Installing Elasticsearch template" , name : name )
423
- @pool . put ( path , nil , LogStash ::Json . dump ( template ) )
419
+ path = "#{ template_endpoint } /#{ name } "
420
+ response = @pool . put ( path , nil , LogStash ::Json . dump ( template ) )
421
+ if response . code < 200 || response . code > 299
422
+ url = ::LogStash ::Util ::SafeURI . new ( response . final_url )
423
+ raise BadResponseCodeError . new ( response . code , url , template , response . body )
424
+ end
424
425
end
425
426
426
427
# ILM methods
@@ -432,16 +433,14 @@ def rollover_alias_exists?(name)
432
433
433
434
# Create a new rollover alias
434
435
def rollover_alias_put ( alias_name , alias_definition )
435
- begin
436
- @pool . put ( CGI ::escape ( alias_name ) , nil , LogStash ::Json . dump ( alias_definition ) )
437
- logger . info ( "Created rollover alias" , name : alias_name )
438
- # If the rollover alias already exists, ignore the error that comes back from Elasticsearch
439
- rescue ::LogStash ::Outputs ::ElasticSearch ::HttpClient ::Pool ::BadResponseCodeError => e
440
- if e . response_code == 400
441
- logger . info ( "Rollover alias already exists, skipping" , name : alias_name )
442
- return
443
- end
444
- raise e
436
+ response = @pool . put ( CGI ::escape ( alias_name ) , nil , LogStash ::Json . dump ( alias_definition ) )
437
+ if response . code == 400
438
+ logger . info ( "Rollover alias already exists, skipping" , name : alias_name )
439
+ return
440
+ end
441
+ unless rresponse . code >= 200 && response . code <= 299
442
+ url = ::LogStash ::Util ::SafeURI . new ( response . final_url )
443
+ raise BadResponseCodeError . new ( response . code , url , alias_definition , response . body )
445
444
end
446
445
end
447
446
0 commit comments