right_agent 2.1.4-x86-mingw32 → 2.1.5-x86-mingw32

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.
@@ -124,7 +124,8 @@ module RightScale
124
124
  fiber = Fiber.current
125
125
  connection = EM::HttpRequest.new(uri.to_s, connect_options)
126
126
  http = connection.send(verb, request_options)
127
- http.errback { fiber.resume(http.error.to_s == "Errno::ETIMEDOUT" ? 504 : 500, http.error && http.error.to_s) }
127
+ http.errback { fiber.resume(http.error.to_s == "Errno::ETIMEDOUT" ? 504 : 500,
128
+ (http.error && http.error.to_s) || "HTTP connection failure for #{verb.to_s.upcase}") }
128
129
  http.callback { fiber.resume(http.response_header.status, http.response, http.response_header) }
129
130
  response_code, response_body, response_headers = Fiber.yield
130
131
  response_headers = beautify_headers(response_headers) if response_headers
@@ -172,7 +173,8 @@ module RightScale
172
173
  # @raise [HttpException] HTTP failure with associated status code
173
174
  def poll_again(fiber, connection, request_options, stop_at)
174
175
  http = connection.send(:get, request_options)
175
- http.errback { fiber.resume(http.error.to_s == "Errno::ETIMEDOUT" ? 504 : 500, http.error && http.error.to_s) }
176
+ http.errback { fiber.resume(http.error.to_s == "Errno::ETIMEDOUT" ? 504 : 500,
177
+ (http.error && http.error.to_s) || "HTTP connection failure for POLL") }
176
178
  http.callback do
177
179
  code, body, headers = http.response_header.status, http.response, http.response_header
178
180
  if code == 200 && (body.nil? || body == "null") && Time.now < stop_at
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  #
2
3
  # Copyright (c) 2009-2011 RightScale Inc
3
4
  #
@@ -36,6 +37,12 @@ module RightScale
36
37
  # === Return
37
38
  # data(String):: Corresponding serialized data
38
39
  def self.dump(command)
40
+ # Set the encoding before serialization otherwise YAML will serialize
41
+ # UTF8 characters as binary data. This can cause some quirks we'd rather
42
+ # avoid, such as the deserialized binary data having no encoding on
43
+ # deserialization
44
+ set_encoding(command)
45
+
39
46
  data = YAML::dump(command)
40
47
  data += SEPARATOR
41
48
  end
@@ -51,7 +58,12 @@ module RightScale
51
58
  # === Raise
52
59
  # (RightScale::Exceptions::IO): If serialized data is incorrect
53
60
  def self.load(data)
61
+ # Data coming from eventmachine is cleaned of it's encoding, so set it
62
+ # to UTF-8 manually before deserializing or you'll throw transcode errors.
63
+ set_encoding(data)
64
+
54
65
  command = YAML::load(data)
66
+
55
67
  raise RightScale::Exceptions::IO, "Invalid serialized command:\n#{data}" unless command
56
68
  command
57
69
  rescue RightScale::Exceptions::IO
@@ -59,5 +71,28 @@ module RightScale
59
71
  rescue Exception => e
60
72
  raise RightScale::Exceptions::IO, "Invalid serialized command: #{e.message}\n#{data}"
61
73
  end
74
+
75
+ private
76
+ # Force set encodings on ruby strings.
77
+ #
78
+ # === Parameters
79
+ # obj(Object):: String, or Hash/Array of Strings
80
+ #
81
+ # === Return
82
+ # (nil):: Returns nothing, edits object in place
83
+ def self.set_encoding(obj, encoding = "UTF-8")
84
+ if obj.is_a?(Hash)
85
+ obj.each do |k,v|
86
+ set_encoding(v, encoding)
87
+ end
88
+ elsif obj.is_a?(Array)
89
+ obj.each do |v|
90
+ set_encoding(v, encoding)
91
+ end
92
+ elsif obj.is_a?(String) && !obj.frozen?
93
+ obj.force_encoding(encoding) if obj.respond_to?(:force_encoding)
94
+ end
95
+ end
96
+
62
97
  end
63
98
  end
@@ -27,6 +27,7 @@ require 'json'
27
27
 
28
28
  require File.normalize_path(File.join(File.dirname(__FILE__), 'message_pack'))
29
29
 
30
+
30
31
  # Monkey patch common classes to support MessagePack serialization
31
32
  # As with JSON, unserializing them is manual using existing methods such as parse
32
33
  class Date
data/right_agent.gemspec CHANGED
@@ -25,8 +25,8 @@ require 'rbconfig'
25
25
 
26
26
  Gem::Specification.new do |spec|
27
27
  spec.name = 'right_agent'
28
- spec.version = '2.1.4'
29
- spec.date = '2014-04-10'
28
+ spec.version = '2.1.5'
29
+ spec.date = '2014-04-15'
30
30
  spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro', 'Scott Messier']
31
31
  spec.email = 'lee@rightscale.com'
32
32
  spec.homepage = 'https://github.com/rightscale/right_agent'
@@ -253,6 +253,17 @@ describe RightScale::NonBlockingClient do
253
253
  @request_options[:path].should == "/api/foo/bar"
254
254
  end
255
255
 
256
+ it "converts connection errors to 500 by default" do
257
+ @headers.http_status = 500
258
+ @response.should_receive(:errback).and_yield.once
259
+ @response.should_receive(:error).and_return(nil)
260
+ @fiber.should_receive(:resume).with(500, "HTTP connection failure for GET").once
261
+ flexmock(Fiber).should_receive(:yield).and_return([500, "HTTP connection failure for GET"]).once
262
+ flexmock(EM::HttpRequest).should_receive(:new).with(@host, @connect_options).and_return(@request).once
263
+ lambda { @client.request(:get, @path, @host, @connect_options, @request_options) }.
264
+ should raise_error(RightScale::HttpExceptions::InternalServerError)
265
+ end
266
+
256
267
  it "converts Errno::ETIMEDOUT error to 504" do
257
268
  @headers.http_status = 504
258
269
  @response.should_receive(:errback).and_yield.once
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  #
2
3
  # Copyright (c) 2009-2011 RightScale Inc
3
4
  #
@@ -66,6 +67,19 @@ describe RightScale::CommandIO do
66
67
  @input.should == 'input'
67
68
  end
68
69
 
70
+ it 'should receive a command with UTF-8 characters' do
71
+ @input = ''
72
+ EM.run do
73
+ RightScale::CommandIO.instance.listen(@socket_port) { |input, _| @input = input; stop }
74
+ send_input({:command => "say_hello", :data => 'Привет world'})
75
+ EM.add_timer(2) { stop }
76
+ end
77
+
78
+ @input.should == {:command => "say_hello", :data => 'Привет world'}
79
+ @input[:command].encoding.to_s.should == "UTF-8" if "".respond_to?(:encoding)
80
+ @input[:data].encoding.to_s.should == "UTF-8" if "".respond_to?(:encoding)
81
+ end
82
+
69
83
  it 'should receive many commands' do
70
84
  @inputs = []
71
85
  EM.run do
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  #
2
3
  # Copyright (c) 2009-2011 RightScale Inc
3
4
  #
@@ -25,7 +26,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
25
26
  describe RightScale::CommandSerializer do
26
27
 
27
28
  before(:all) do
28
- @sample_data = [ 42, 'fourty two', { :haha => 42, 'hoho' => 'fourty_two' }]
29
+ @sample_data = [ 42, 'fourty two', { :hello => 'Привет', :haha => 42, 'hoho' => 'fourty_two' }]
29
30
  end
30
31
 
31
32
  it 'should serialize' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  prerelease:
6
6
  platform: x86-mingw32
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-04-10 00:00:00.000000000 Z
15
+ date: 2014-04-15 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: right_support
@@ -444,7 +444,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
444
444
  version: '0'
445
445
  segments:
446
446
  - 0
447
- hash: 3250741982797767948
447
+ hash: -210695347725236548
448
448
  requirements: []
449
449
  rubyforge_project:
450
450
  rubygems_version: 1.8.26