[PATCH conductor 6/8] Launch and rollback is done on background

jprovazn at redhat.com jprovazn at redhat.com
Thu Jun 14 13:36:33 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

Instances are now launched on background, stopping of instances when
doing rollback is on background too.

https://www.aeolusproject.org/redmine/issues/3395
---
 src/app/models/deployment.rb           |   34 ++++++++++++++++++++++---------
 src/config/initializers/delayed_job.rb |    4 ++-
 src/spec/models/deployment_spec.rb     |    2 -
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 4e42422..7bb5831 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -234,6 +234,7 @@ class Deployment < ActiveRecord::Base
     self.reload unless self.new_record?
     self.state = STATE_PENDING
     save!
+
     all_inst_match, account, errs = find_match_with_common_account
 
     if all_inst_match
@@ -249,6 +250,11 @@ class Deployment < ActiveRecord::Base
                    :errors => errs.join(", "))
     end
 
+    # Array of InstanceMatches returned by find_match_with_common_account
+    # is converted to hashes because if we use directly instance of
+    # InstanceMatch model, delayed job tries to load this object from DB
+    all_inst_match.map!{|m| m.attributes}
+
     if deployable_xml.requires_config_server?
       # the instance configurations need to be generated from the entire set of
       # instances (and not each individual instance) in order to do parameter
@@ -262,24 +268,28 @@ class Deployment < ActiveRecord::Base
       instance_configs = {}
     end
 
+    delay.send_launch_requests(all_inst_match, config_server,
+                               instance_configs, user)
+  end
 
-    # TODO: in follow up patch there should be only delayed job call
-    # on this place
-    # For now, we just call DC create intance method on foreground, if an error
-    # occurs (for example DC API is not running, or config server is not
-    # running), then CREATE_FAILED is set in instance.launch!
+  def send_launch_requests(all_inst_match, config_server, instance_configs, user)
     instances.each do |instance|
       instance.reset_attrs unless instance.state == Instance::STATE_NEW
-      match = all_inst_match.find{|m| m.instance.id == instance.id}
-      instance.instance_matches << match
+      instance.instance_matches << InstanceMatch.new(
+        all_inst_match.find{|m| m['instance_id'] == instance.id})
       begin
-        instance.launch!(match,
+        instance.launch!(instance.instance_matches.last,
                          user,
                          config_server,
                          instance_configs[instance.uuid])
       rescue
-        errors.add(:base,
-                   "#{instance.name}: #{$!.message.to_s.split("\n").first}")
+        self.events << Event.create(
+          :source => self,
+          :event_time => DateTime.now,
+          :status_code => 'instance_launch_failed',
+          :summary => "#{instance.name}: #{$!.message.to_s.split("\n").first}"
+        )
+
         logger.error $!.message
         logger.error $!.backtrace.join("\n    ")
 
@@ -695,6 +705,10 @@ class Deployment < ActiveRecord::Base
       return
     end
 
+    delay.send_rollback_requests
+  end
+
+  def send_rollback_requests
     error_occured = false
     instances.running.each do |instance|
       begin
diff --git a/src/config/initializers/delayed_job.rb b/src/config/initializers/delayed_job.rb
index 6e0d177..6f95a6b 100644
--- a/src/config/initializers/delayed_job.rb
+++ b/src/config/initializers/delayed_job.rb
@@ -6,4 +6,6 @@ Delayed::Worker.destroy_failed_jobs = false
 Delayed::Worker.max_attempts = 2
 #Delayed::Worker.max_run_time = 5.minutes
 #Delayed::Worker.read_ahead = 10
-#Delayed::Worker.delay_jobs = !Rails.env.test?
+
+# in test env jobs are not delayed and are executed directly
+Delayed::Worker.delay_jobs = !Rails.env.test?
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index cf4cde0..c996d51 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -427,8 +427,6 @@ describe Deployment do
           @inst2.save!
           @deployment.reload
           @deployment.state.should == Deployment::STATE_ROLLBACK_IN_PROGRESS
-          @deployment.events.find_by_status_code('instance_launch_failed').
-            should_not be_nil
         end
 
         it "should stop all running instances if an instance fails" do
-- 
1.7.7.6




More information about the aeolus-devel mailing list