eb_deployer 0.4.4.beta4 → 0.4.4.beta5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/eb_deployer.rb CHANGED
@@ -15,6 +15,7 @@ require 'eb_deployer/deployment_strategy'
15
15
  require 'eb_deployer/cloud_formation_provisioner'
16
16
  require 'eb_deployer/application'
17
17
  require 'eb_deployer/resource_stacks'
18
+ require 'eb_deployer/throttling_handling'
18
19
  require 'eb_deployer/eb_environment'
19
20
  require 'eb_deployer/environment'
20
21
  require 'eb_deployer/default_component'
@@ -175,6 +176,7 @@ module EbDeployer
175
176
  bs = opts[:bs_driver] || AWSDriver::Beanstalk.new
176
177
  s3 = opts[:s3_driver] || AWSDriver::S3Driver.new
177
178
  cf = opts[:cf_driver] || AWSDriver::CloudFormationDriver.new
179
+
178
180
  app_name = opts[:application]
179
181
  version_prefix = opts[:version_prefix].to_s.strip
180
182
  version_label = "#{version_prefix}#{opts[:version_label].to_s.strip}"
@@ -183,7 +185,7 @@ module EbDeployer
183
185
  resource_stacks = ResourceStacks.new(opts[:resources],
184
186
  cf,
185
187
  opts[:skip_resource_stack_update])
186
-
188
+ bs = ThrottlingHandling.new(bs, AWS::ElasticBeanstalk::Errors::Throttling)
187
189
  environment = Environment.new(application, opts[:environment], bs) do |env|
188
190
  env.resource_stacks = resource_stacks
189
191
  env.settings = opts[:option_settings] || opts[:settings] || []
@@ -41,7 +41,9 @@ module EbDeployer
41
41
 
42
42
  def swap_cname_with(another)
43
43
  log("Swap CNAME with env #{another.name}")
44
- @bs.environment_swap_cname(self.app, self.name, another.name)
44
+ with_polling_events(/Completed swapping CNAMEs for environments/i) do
45
+ @bs.environment_swap_cname(self.app, self.name, another.name)
46
+ end
45
47
  end
46
48
 
47
49
  def log(msg)
@@ -41,9 +41,7 @@ module EbDeployer
41
41
  end
42
42
 
43
43
  def fetch_events_from_eb(options)
44
- backoff(AWS::ElasticBeanstalk::Errors::Throttling) do
45
- @eb_driver.fetch_events(@app, @env, options)
46
- end
44
+ @eb_driver.fetch_events(@app, @env, options)
47
45
  end
48
46
  end
49
47
  end
@@ -0,0 +1,17 @@
1
+ module EbDeployer
2
+ class ThrottlingHandling
3
+ include Utils
4
+
5
+ def initialize(delegatee, throttling_error)
6
+ @delegatee = delegatee
7
+ @throttling_error = throttling_error
8
+ end
9
+
10
+ def method_missing(method, *args, &block)
11
+ super unless @delegatee.respond_to?(method)
12
+ backoff(@throttling_error) do
13
+ @delegatee.send(method, *args, &block)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module EbDeployer
2
- VERSION = "0.4.4.beta4"
2
+ VERSION = "0.4.4.beta5"
3
3
  end
@@ -33,7 +33,8 @@ class EBStub
33
33
  :version => version,
34
34
  :cname_prefix => cname_prefix,
35
35
  :tier => tier,
36
- :settings => settings}
36
+ :settings => settings }
37
+ set_env_ready(app, env, false)
37
38
  end
38
39
 
39
40
  def delete_environment(app, env)
@@ -43,7 +44,9 @@ class EBStub
43
44
  end
44
45
 
45
46
  def update_environment(app, env, version, tier, settings)
47
+ raise "not in ready state, consider waiting for previous action finish by pulling envents" unless env_ready?(app, env)
46
48
  @envs[env_key(app, env)].merge!(:version => version, :settings => settings, :tier => tier)
49
+ set_env_ready(app, env, false)
47
50
  end
48
51
 
49
52
  def environment_exists?(app_name, env_name)
@@ -79,13 +82,18 @@ class EBStub
79
82
  end
80
83
 
81
84
  def fetch_events(app_name, env_name, options={})
85
+ set_env_ready(app_name, env_name, true)
86
+
82
87
  unless @events # unrestricted mode for testing if no explicit events set
83
88
  return generate_event_from_messages(['Environment update completed successfully',
84
- 'terminateEnvironment completed successfully',
85
- 'Successfully launched environment'])
89
+ 'terminateEnvironment completed successfully',
90
+ 'Successfully launched environment',
91
+ 'Completed swapping CNAMEs for environments'
92
+ ])
86
93
  end
87
94
 
88
95
  @events[env_key(app_name, env_name)]
96
+ # assume env become ready after it spit out all the events
89
97
  end
90
98
 
91
99
 
@@ -101,10 +109,14 @@ class EBStub
101
109
 
102
110
 
103
111
  def environment_swap_cname(app_name, env1_name, env2_name)
112
+ raise "#{env1_name} not in ready state, consider to wait for previous action finsish by pulling events" unless env_ready?(app_name, env1_name)
113
+
104
114
  env1, env2 = @envs[env_key(app_name, env1_name)], @envs[env_key(app_name, env2_name)]
105
115
  temp = env1[:cname_prefix]
106
116
  env1[:cname_prefix] = env2[:cname_prefix]
107
117
  env2[:cname_prefix] = temp
118
+ set_env_ready(app_name, env1_name, false)
119
+ set_env_ready(app_name, env2_name, false)
108
120
  end
109
121
 
110
122
  def environment_health_state(app_name, env_name)
@@ -116,6 +128,9 @@ class EBStub
116
128
  end
117
129
 
118
130
  #test only
131
+ def mark_all_envs_ready
132
+ @envs.values.each { |env| set_env_ready(env[:application], env[:name], true) }
133
+ end
119
134
 
120
135
  def environment_tier(app_name, env_name)
121
136
  @envs[env_key(app_name, env_name)][:tier]
@@ -149,6 +164,16 @@ class EBStub
149
164
 
150
165
  private
151
166
 
167
+ def set_env_ready(app, env, ready)
168
+ if record = @envs[env_key(app, env)]
169
+ record[:ready] = ready
170
+ end
171
+ end
172
+
173
+ def env_ready?(app, env)
174
+ @envs[env_key(app, env)][:ready]
175
+ end
176
+
152
177
  def generate_event_from_messages(messages)
153
178
  [messages.reverse.map do |m|
154
179
  {:event_date => Time.now.utc,
data/test/deploy_test.rb CHANGED
@@ -23,6 +23,7 @@ class DeployTest < MiniTest::Unit::TestCase
23
23
  end
24
24
 
25
25
  def deploy(opts)
26
+ @eb.mark_all_envs_ready
26
27
  EbDeployer.deploy({:package => @sample_package,
27
28
  :strategy => :'inplace-update',
28
29
  :version_label => 1}.merge(opts).merge(stubs))
@@ -87,7 +87,7 @@ class InplaceUpdateDeployTest < DeployTest
87
87
  end
88
88
  end
89
89
 
90
- def test_deploy_should_retry_on_temporary_throttling_error
90
+ def test_deploy_should_retry_on_temporary_throttling_error_from_fetch_events
91
91
  throttling_error = AWS::ElasticBeanstalk::Errors::Throttling.new("bang!")
92
92
  error_seq = [throttling_error] * 5
93
93
  @eb.set_error_generator(:fetch_events) do
@@ -97,4 +97,14 @@ class InplaceUpdateDeployTest < DeployTest
97
97
  assert @eb.environment_exists?('simple', t('production', 'simple'))
98
98
  end
99
99
 
100
+ def test_deploy_should_retry_on_temporary_throttling_error_from_create_env
101
+ throttling_error = AWS::ElasticBeanstalk::Errors::Throttling.new("bang!")
102
+ error_seq = [throttling_error] * 5
103
+ @eb.set_error_generator(:create_environment) do
104
+ error_seq.pop
105
+ end
106
+ deploy(:application => 'simple', :environment => "production")
107
+ assert @eb.environment_exists?('simple', t('production', 'simple'))
108
+ end
109
+
100
110
  end
data/test/test_helper.rb CHANGED
@@ -45,7 +45,7 @@ class ErrorRaisingWrapper < SimpleDelegator
45
45
  end
46
46
 
47
47
  def #{method}(*args, &block)
48
- if error_gen = @errors[:fetch_events]
48
+ if error_gen = @errors[:#{method}]
49
49
  error = error_gen.call
50
50
  raise error if error
51
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eb_deployer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4.beta4
4
+ version: 0.4.4.beta5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-04 00:00:00.000000000 Z
13
+ date: 2014-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -69,6 +69,7 @@ files:
69
69
  - lib/eb_deployer/package.rb
70
70
  - lib/eb_deployer/resource_stacks.rb
71
71
  - lib/eb_deployer/smoke_test.rb
72
+ - lib/eb_deployer/throttling_handling.rb
72
73
  - lib/eb_deployer/utils.rb
73
74
  - lib/eb_deployer/version.rb
74
75
  - lib/eb_deployer/version_cleaner.rb