From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/app/models/deployment.rb | 29 ++++++++++++++++++++++++++++-
src/spec/models/deployment_spec.rb | 2 ++
2 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index f77b16d..ae95125 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -81,6 +81,7 @@ class Deployment < ActiveRecord::Base
before_create :generate_uuid
before_create :set_pool_family
before_create :set_new_state
+ after_save :log_state_change
USER_MUTABLE_ATTRS = ['name']
@@ -615,6 +616,15 @@ class Deployment < ActiveRecord::Base
elsif partial_launch and instances.all? {|i| i.failed_or_running?}
self.state = STATE_RUNNING
elsif !partial_launch and Instance::FAILED_STATES.include?(instance.state)
+ self.events << Event.create(
+ :source => self,
+ :event_time => DateTime.now,
+ :status_code => 'instance_launch_failed',
+ :summary => "Failed to launch instance #{instance.name}, doing
rollback"
+ )
+ # TODO: now this is done in instance's after_update callback - as part
+ # of instance save transaction - this might be done on background by
+ # using delayed_job
deployment_rollback
end
end
@@ -668,7 +678,13 @@ class Deployment < ActiveRecord::Base
i.stop(nil)
rescue
error_occured = true
- # TODO: add instance event for this exception
+ self.events << Event.create(
+ :source => self,
+ :event_time => DateTime.now,
+ :status_code => 'instance_stop_failed',
+ :summary => "Failed to stop instance #{i.name}",
+ :description => $!.message
+ )
logger.error $!.message
logger.error $!.backtrace.join("\n ")
end
@@ -678,4 +694,15 @@ class Deployment < ActiveRecord::Base
save!
end
end
+
+ def log_state_change
+ if state_changed?
+ self.events << Event.create(
+ :source => self,
+ :event_time => DateTime.now,
+ :status_code => self.state,
+ :summary => "State changed to #{self.state}"
+ )
+ end
+ end
end
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index cb4b756..7cf64f2 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -419,6 +419,8 @@ 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