[PATCH 1/2] 838726 (1) - mark 'new' instances as create_failed if deployment launch fails

jprovazn at redhat.com jprovazn at redhat.com
Fri Jul 13 14:27:08 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 |   11 ++++++++++-
 src/app/models/instance.rb   |    1 +
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index d524389..ac63509 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
 
@@ -694,6 +696,7 @@ class Deployment < ActiveRecord::Base
       end
     end
     if error_occured
+      cleanup_failed_launch
       self.state = STATE_ROLLBACK_FAILED
       save!
     end
@@ -709,4 +712,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.7.6




More information about the aeolus-devel mailing list