[PATCH conductor 7/8] Updated events when launching a deployment and instance

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


From: Jan Provaznik <jprovazn at redhat.com>

Instance-related events are now associated with an instance,
deployment's history page now displays its own events and also events of
all its instances.

Changed ordering of events on instance show page to be ascending
(deployment events are ascending too).
---
 src/app/controllers/deployments_controller.rb |    2 +-
 src/app/controllers/instances_controller.rb   |    2 +-
 src/app/models/deployment.rb                  |   27 +++++++++---------------
 src/app/models/event.rb                       |    1 -
 src/app/util/taskomatic.rb                    |    6 +++++
 src/app/views/deployments/_history.html.haml  |    5 +++-
 src/config/locales/en.yml                     |    2 +
 7 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/app/controllers/deployments_controller.rb b/src/app/controllers/deployments_controller.rb
index 0ae49a1..6dc2c70 100644
--- a/src/app/controllers/deployments_controller.rb
+++ b/src/app/controllers/deployments_controller.rb
@@ -213,7 +213,7 @@ class DeploymentsController < ApplicationController
     details_tab_name = params[:details_tab].blank? ? 'instances' : params[:details_tab]
     @details_tab = @tabs.find {|t| t[:id] == details_tab_name} || @tabs.first[:name].downcase
     if @details_tab[:id] == 'history'
-      @events = @deployment.events
+      @events = @deployment.events_of_deployment_and_instances
     end
     if params[:details_tab]
       @view = @details_tab[:view]
diff --git a/src/app/controllers/instances_controller.rb b/src/app/controllers/instances_controller.rb
index ac78096..110f1d2 100644
--- a/src/app/controllers/instances_controller.rb
+++ b/src/app/controllers/instances_controller.rb
@@ -46,7 +46,7 @@ class InstancesController < ApplicationController
   def show
     load_instances
     save_breadcrumb(instance_path(@instance), @instance.name)
-    @events = @instance.events.descending_by_created_at.paginate(:page => params[:page] || 1)
+    @events = @instance.events.paginate(:page => params[:page] || 1)
     @view = params[:details_tab].blank? ? 'properties' : params[:details_tab]
     @tabs = [
       {:name => t('properties'), :view => @view, :id => 'properties'},
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 7bb5831..3ad7863 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -283,16 +283,6 @@ class Deployment < ActiveRecord::Base
                          config_server,
                          instance_configs[instance.uuid])
       rescue
-        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    ")
-
         # be default launching of instances is terminated if an error occurs,
         # user can set "partial_launch" attribute - launch request is then
         # sent for all deployment's instances
@@ -514,6 +504,15 @@ class Deployment < ActiveRecord::Base
     d
   end
 
+  def events_of_deployment_and_instances
+    instance_ids = instances.map(&:id)
+    Event.all(:conditions => ["(source_type='Instance' AND source_id in (?))"\
+                              "OR (source_type='Deployment' AND source_id=?)",
+                              instance_ids, self.id],
+              :order => "created_at ASC")
+
+  end
+
   PRESET_FILTERS_OPTIONS = []
 
   private
@@ -645,12 +644,6 @@ 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
@@ -716,7 +709,7 @@ class Deployment < ActiveRecord::Base
       rescue
         error_occured = true
         self.events << Event.create(
-          :source => self,
+          :source => instance,
           :event_time => DateTime.now,
           :status_code => 'instance_stop_failed',
           :summary => "Failed to stop instance #{instance.name}",
diff --git a/src/app/models/event.rb b/src/app/models/event.rb
index c2593f8..8479c58 100644
--- a/src/app/models/event.rb
+++ b/src/app/models/event.rb
@@ -46,7 +46,6 @@ class Event < ActiveRecord::Base
   attr_accessor :change_hash # allows us to pass in .changes on the parent ("source") object
 
   scope :lifetime, where(:status_code => [:first_running, :all_running, :some_running, :all_stopped])
-  scope :descending_by_created_at, order('created_at DESC')
 
   # Notifies the Event API if certain conditions are met
   def transmit_event
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index 994d1f9..0e95e12 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -135,6 +135,12 @@ module Taskomatic
     Rails.logger.error ex.backtrace.join("\n")
     task.state = Task::STATE_FAILED
     task.instance.state = Instance::STATE_CREATE_FAILED
+    task.instance.events << Event.create(
+      :source => task.instance,
+      :event_time => DateTime.now,
+      :status_code => 'instance_launch_failed',
+      :summary => "#{task.instance.name}: #{ex.message.to_s.split("\n").first}"
+    )
     raise ex
   end
 
diff --git a/src/app/views/deployments/_history.html.haml b/src/app/views/deployments/_history.html.haml
index ece5015..f5dbcec 100644
--- a/src/app/views/deployments/_history.html.haml
+++ b/src/app/views/deployments/_history.html.haml
@@ -1,4 +1,7 @@
 %ol.listing
   - @events.each do |event|
     %li
-      = "#{event.event_time.strftime('%d-%b-%Y %H:%M:%S')}: #{event.summary}"
+      = "#{event.event_time.strftime('%d-%b-%Y %H:%M:%S')}:"
+      - if event.source_type == 'Instance'
+        = link_to t('.instance', :name => event.source.name), instance_path(event.source)
+      = event.summary
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 9c42494..b20ecb6 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -267,6 +267,8 @@ en:
       deployable_xml: Deployable XML
     show:
       name: "%{name} Deployment"
+    history:
+      instance: "Instance %{name}"
     new:
       launch: Launch this deployment
       deployable_definition: Deployable definition
-- 
1.7.7.6




More information about the aeolus-devel mailing list