[PATCH conductor 1/2] 838726 (1) - mark 'new' instances as create_failed if deployment launch fails
jprovazn at redhat.com
jprovazn at redhat.com
Thu Jul 26 11:33:48 UTC 2012
From: Jan Provaznik <jprovazn at redhat.com>
After whole launch process fails (= deployment ends in failed or
rollback_failed state) then all instances which remained in 'new'
state are marked as 'create_failed'.
---
src/app/models/deployment.rb | 14 ++++++++++++--
src/app/models/instance.rb | 1 +
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index d524389..df74398 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -654,13 +654,15 @@ class Deployment < ActiveRecord::Base
if Instance::ACTIVE_FAILED_STATES.include?(instance.state)
# if this instance stop failed, whole deployment rollback failed
self.state = STATE_ROLLBACK_FAILED
+ cleanup_failed_launch
elsif instance.state == Instance::STATE_RUNNING
deployment_rollback
- elsif instances.all? {|i| i.inactive?}
+ elsif instances.all? {|i| i.inactive? or i.state == Instance::STATE_NEW}
# some other instances might be failed (because their
# launch failed), but it shouldn't be a problem if all
# running instances stopped correctly
self.state = STATE_ROLLBACK_COMPLETE
+ cleanup_failed_launch
end
end
@@ -670,7 +672,7 @@ class Deployment < ActiveRecord::Base
save!
end
- if instances.all? {|i| i.inactive? or i.state == Instance::STATE_NEW}
+ if instances.all? {|i| i.inactive?}
self.state = STATE_ROLLBACK_COMPLETE
save!
return
@@ -697,6 +699,8 @@ class Deployment < ActiveRecord::Base
self.state = STATE_ROLLBACK_FAILED
save!
end
+
+ cleanup_failed_launch
end
def log_state_change
@@ -709,4 +713,10 @@ class Deployment < ActiveRecord::Base
)
end
end
+
+ def cleanup_failed_launch
+ instances.in_new_state.each do |instance|
+ instance.update_attribute(:state, Instance::STATE_CREATE_FAILED)
+ end
+ end
end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 9c39d75..5ca080a 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -129,6 +129,7 @@ class Instance < ActiveRecord::Base
# FIXME: "pending" is misleading as it doesn't just cover STATE_PENDING
scope :pending, :conditions => { :state => [STATE_NEW, STATE_PENDING] }
scope :running, :conditions => { :state => [STATE_RUNNING] }
+ scope :in_new_state, :conditions => { :state => [STATE_NEW] }
scope :pending_or_deployed, :conditions => { :state => [STATE_NEW, STATE_PENDING, STATE_RUNNING, STATE_SHUTTING_DOWN] }
# FIXME: "failed" is misleading too...
scope :failed, :conditions => { :state => FAILED_STATES }
--
1.7.10.4
More information about the aeolus-devel
mailing list