aws 2.3.4 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/awsbase/right_awsbase.rb +90 -80
- metadata +2 -2
@@ -410,12 +410,26 @@ module Aws
|
|
410
410
|
:protocol => lib_params[:protocol] }
|
411
411
|
end
|
412
412
|
|
413
|
-
|
413
|
+
def get_conn(connection_name, lib_params, logger)
|
414
414
|
# thread = lib_params[:multi_thread] ? Thread.current : Thread.main
|
415
415
|
# thread[connection_name] ||= Rightscale::HttpConnection.new(:exception => Aws::AwsError, :logger => logger)
|
416
416
|
# conn = thread[connection_name]
|
417
417
|
# return conn
|
418
|
-
|
418
|
+
http_conn = nil
|
419
|
+
conn_mode = lib_params[:connection_mode]
|
420
|
+
if conn_mode == :per_request
|
421
|
+
http_conn = Rightscale::HttpConnection.new(:exception => AwsError, :logger => logger)
|
422
|
+
|
423
|
+
elsif conn_mode == :per_thread || conn_mode == :single
|
424
|
+
thread = conn_mode == :per_thread ? Thread.current : Thread.main
|
425
|
+
thread[connection_name] ||= Rightscale::HttpConnection.new(:exception => AwsError, :logger => logger)
|
426
|
+
http_conn = thread[connection_name]
|
427
|
+
# ret = request_info_impl(http_conn, bench, request, parser, &block)
|
428
|
+
end
|
429
|
+
return http_conn
|
430
|
+
|
431
|
+
end
|
432
|
+
|
419
433
|
#
|
420
434
|
# def request_info2(request, parser, lib_params, connection_name, logger, bench)
|
421
435
|
# t = get_conn(connection_name, lib_params, logger)
|
@@ -426,32 +440,24 @@ module Aws
|
|
426
440
|
# Raises AwsError if any banana happened
|
427
441
|
def request_info2(request, parser, lib_params, connection_name, logger, bench, &block) #:nodoc:
|
428
442
|
ret = nil
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
count
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
if !ex.include?(/QueryTimeout/)
|
442
|
-
raise ex
|
443
|
-
end
|
443
|
+
http_conn = get_conn(connection_name, lib_params, logger)
|
444
|
+
begin
|
445
|
+
retry_count = 1
|
446
|
+
count = 0
|
447
|
+
while count <= retry_count
|
448
|
+
puts 'RETRYING QUERY due to QueryTimeout...' if count > 0
|
449
|
+
begin
|
450
|
+
ret = request_info_impl(http_conn, bench, request, parser, &block)
|
451
|
+
break
|
452
|
+
rescue Aws::AwsError => ex
|
453
|
+
if !ex.include?(/QueryTimeout/) || count == retry_count
|
454
|
+
raise ex
|
444
455
|
end
|
445
|
-
count += 1
|
446
456
|
end
|
447
|
-
|
448
|
-
http_conn.finish if http_conn
|
457
|
+
count += 1
|
449
458
|
end
|
450
|
-
|
451
|
-
|
452
|
-
thread[connection_name] ||= Rightscale::HttpConnection.new(:exception => AwsError, :logger => logger)
|
453
|
-
http_conn = thread[connection_name]
|
454
|
-
ret = request_info_impl(http_conn, bench, request, parser, &block)
|
459
|
+
ensure
|
460
|
+
http_conn.finish if http_conn && lib_params[:connection_mode] == :per_request
|
455
461
|
end
|
456
462
|
ret
|
457
463
|
end
|
@@ -465,73 +471,77 @@ module Aws
|
|
465
471
|
def request_info_xml_simple(connection_name, lib_params, request, logger, params = {})
|
466
472
|
|
467
473
|
@connection = get_conn(connection_name, lib_params, logger)
|
468
|
-
|
469
|
-
|
474
|
+
begin
|
475
|
+
@last_request = request[:request]
|
476
|
+
@last_response = nil
|
470
477
|
|
471
|
-
|
472
|
-
|
478
|
+
response = @connection.request(request)
|
479
|
+
# puts "response=" + response.body
|
473
480
|
# benchblock.service.add!{ response = @connection.request(request) }
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
481
|
+
# check response for errors...
|
482
|
+
@last_response = response
|
483
|
+
if response.is_a?(Net::HTTPSuccess)
|
484
|
+
@error_handler = nil
|
478
485
|
# benchblock.xml.add! { parser.parse(response) }
|
479
486
|
# return parser.result
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
487
|
+
force_array = params[:force_array] || false
|
488
|
+
# Force_array and group_tags don't work nice together so going to force array manually
|
489
|
+
xml_simple_options = {"KeyToSymbol"=>false, 'ForceArray' => false}
|
490
|
+
xml_simple_options["GroupTags"] = params[:group_tags] if params[:group_tags]
|
484
491
|
|
485
492
|
# { 'GroupTags' => { 'searchpath' => 'dir' }
|
486
493
|
# 'ForceArray' => %r(_list$)
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
end
|
498
|
-
parsed = symbolize(parsed, force_array)
|
499
|
-
# puts 'parsed=' + parsed.inspect
|
500
|
-
if params[:pull_out_array]
|
501
|
-
ret = Aws::AwsResponseArray.new(parsed[:response_metadata])
|
502
|
-
level_hash = parsed
|
503
|
-
params[:pull_out_array].each do |x|
|
504
|
-
level_hash = level_hash[x]
|
494
|
+
parsed = XmlSimple.xml_in(response.body, xml_simple_options)
|
495
|
+
# todo: we may want to consider stripping off a couple of layers when doing this, for instance:
|
496
|
+
# <DescribeDBInstancesResponse xmlns="http://rds.amazonaws.com/admin/2009-10-16/">
|
497
|
+
# <DescribeDBInstancesResult>
|
498
|
+
# <DBInstances>
|
499
|
+
# <DBInstance>....
|
500
|
+
# Strip it off and only return an array or hash of <DBInstance>'s (hash by identifier).
|
501
|
+
# would have to be able to make the RequestId available somehow though, perhaps some special array subclass which included that?
|
502
|
+
unless force_array.is_a? Array
|
503
|
+
force_array = []
|
505
504
|
end
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
505
|
+
parsed = symbolize(parsed, force_array)
|
506
|
+
# puts 'parsed=' + parsed.inspect
|
507
|
+
if params[:pull_out_array]
|
508
|
+
ret = Aws::AwsResponseArray.new(parsed[:response_metadata])
|
509
|
+
level_hash = parsed
|
510
|
+
params[:pull_out_array].each do |x|
|
511
|
+
level_hash = level_hash[x]
|
511
512
|
end
|
513
|
+
if level_hash.is_a? Hash # When there's only one
|
514
|
+
ret << level_hash
|
515
|
+
else # should be array
|
516
|
+
level_hash.each do |x|
|
517
|
+
ret << x
|
518
|
+
end
|
519
|
+
end
|
520
|
+
elsif params[:pull_out_single]
|
521
|
+
# returns a single object
|
522
|
+
ret = AwsResponseObjectHash.new(parsed[:response_metadata])
|
523
|
+
level_hash = parsed
|
524
|
+
params[:pull_out_single].each do |x|
|
525
|
+
level_hash = level_hash[x]
|
526
|
+
end
|
527
|
+
ret.merge!(level_hash)
|
528
|
+
else
|
529
|
+
ret = parsed
|
512
530
|
end
|
513
|
-
|
514
|
-
# returns a single object
|
515
|
-
ret = AwsResponseObjectHash.new(parsed[:response_metadata])
|
516
|
-
level_hash = parsed
|
517
|
-
params[:pull_out_single].each do |x|
|
518
|
-
level_hash = level_hash[x]
|
519
|
-
end
|
520
|
-
ret.merge!(level_hash)
|
521
|
-
else
|
522
|
-
ret = parsed
|
523
|
-
end
|
524
|
-
return ret
|
531
|
+
return ret
|
525
532
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
533
|
+
else
|
534
|
+
@error_handler = AWSErrorHandler.new(self, nil, :errors_list => self.class.amazon_problems) unless @error_handler
|
535
|
+
check_result = @error_handler.check(request)
|
536
|
+
if check_result
|
537
|
+
@error_handler = nil
|
538
|
+
return check_result
|
539
|
+
end
|
540
|
+
request_text_data = "#{request[:server]}:#{request[:port]}#{request[:request].path}"
|
541
|
+
raise AwsError2.new(@last_response.code, @last_request_id, request_text_data, @last_response.body)
|
532
542
|
end
|
533
|
-
|
534
|
-
|
543
|
+
ensure
|
544
|
+
@connection.finish if @connection && lib_params[:connection_mode] == :per_request
|
535
545
|
end
|
536
546
|
|
537
547
|
end
|