From: Imre Farkas <ifarkas(a)redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=786535
Resending this patch based on Jozef's suggestion to add autoupdate to the error
messages. I also moved the error messages from flash messages to alerts for readabilty
reasons.
---
src/app/controllers/deployments_controller.rb | 2 +-
src/app/models/deployment.rb | 2 +-
src/app/util/taskomatic.rb | 8 +++
src/app/views/deployments/_alerts_show.html.haml | 62 ++++++++++++++++-----
src/public/javascripts/backbone/views.js | 34 ++++++++++++
5 files changed, 91 insertions(+), 17 deletions(-)
diff --git a/src/app/controllers/deployments_controller.rb
b/src/app/controllers/deployments_controller.rb
index 504a050..4ef653a 100644
--- a/src/app/controllers/deployments_controller.rb
+++ b/src/app/controllers/deployments_controller.rb
@@ -183,7 +183,7 @@ class DeploymentsController < ApplicationController
require_privilege(Privilege::VIEW, @deployment)
init_new_deployment_attrs
save_breadcrumb(deployment_path(@deployment, :viewstate => viewstate_id),
@deployment.name)
- @failed_instances = @deployment.failed_instances
+ @failed_instances = @deployment.failed_instances.list(sort_column(Instance),
sort_direction)
if filter_view?
@view = 'instances/list'
params[:instances_preset_filter] = "" unless
params[:instances_preset_filter]
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 4f80aff..6b0277a 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -432,7 +432,7 @@ class Deployment < ActiveRecord::Base
end
def failed_instances
- instances.select {|instance| instance.failed?}
+ instances.failed
end
PRESET_FILTERS_OPTIONS = []
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index a7181dc..463f521 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -73,6 +73,14 @@ module Taskomatic
rescue Exception => ex
task.state = Task::STATE_FAILED
task.message = ex.message
+ task.instance.update_attributes(:last_error => ex.message)
+
+ # For RHEV-M, since we need to start up the instance after the vm has been created
+ # we also have to handle create_failed state events separately
+ if task.instance.state == Instance::STATE_STOPPED && task.action ==
InstanceTask::ACTION_START &&
+ task.instance.provider_account.provider.provider_type.deltacloud_driver ==
'rhevm'
+ task.instance.update_attributes(:state => Instance::STATE_CREATE_FAILED)
+ end
ensure
task.save! if Task.exists?(task.id)
end
diff --git a/src/app/views/deployments/_alerts_show.html.haml
b/src/app/views/deployments/_alerts_show.html.haml
index f850c6c..6bc1519 100644
--- a/src/app/views/deployments/_alerts_show.html.haml
+++ b/src/app/views/deployments/_alerts_show.html.haml
@@ -1,15 +1,47 @@
-- if @failed_instances.count > 0
- %section.content-section.alerts.collapse_entity
- %header
- %h2=t 'alerts_label'
- %span.label.badge.alert.count= @failed_instances.count
- .section-controls
- = link_to t("providers.edit.toggle_alerts"), "#", :class
=> 'collapse alerts' unless @statistics[:instances_failed].blank?
- .content.collapsible
- %dl.alerts
- %ul
- - @failed_instances.each do |inst|
- %li.alert
- %dt.subject.critical= inst.name
- %dd.type=t 'alerts.instance_failure'
- %dd.desc= "#{inst.last_error.blank? ? inst.state :
inst.last_error}"
+#deployment-alerts
+ - if @failed_instances.count > 0
+ %section.content-section.alerts.collapse_entity
+ %header
+ %h2=t 'alerts_label'
+ %span.label.badge.alert.count= @failed_instances.count
+ .section-controls
+ = link_to t("providers.edit.toggle_alerts"), "#", :class
=> 'collapse alerts' unless @statistics[:instances_failed].blank?
+ .content.collapsible
+ %dl.alerts
+ %ul
+ - @failed_instances.each do |inst|
+ %li.alert
+ %dt.subject.critical= inst.name
+ %dd.type=t 'alerts.instance_failure'
+ %dd.desc= "#{inst.last_error.blank? ? inst.state :
inst.last_error}"
+
+%script#deploymentAlertsHeaderTemplate{ :type => 'text/x-jquery-tmpl' }
+ :plain
+ <section class="content-section alerts collapse_entity">
+ <header>
+ <h2>Alerts</h2>
+ <span class="label badge alert
count">${failedCount}</span>
+ <div class="section-controls">
+ <a class="collapse alerts"
href="#">#{t('providers.edit.toggle_alerts')}</a>
+ </div>
+ </header>
+ <div class="content collapsible">
+ <dl class="alerts">
+ <ul></ul>
+ </dl>
+ </div>
+ </section>
+
+%script#deploymentAlertTemplate{ :type => 'text/x-jquery-tmpl' }
+ :plain
+ <li class="alert">
+ <dt class="subject critical">${name}</dt>
+ <dd
class="type">#{t('alerts.instance_failure')}</dd>
+ <dd class="desc">
+ {{if last_error}}
+ ${last_error}
+ {{else}}
+ ${state}
+ {{/if}}
+ </dd>
+ </li>
diff --git a/src/public/javascripts/backbone/views.js
b/src/public/javascripts/backbone/views.js
index a28bb1f..8f2b6eb 100644
--- a/src/public/javascripts/backbone/views.js
+++ b/src/public/javascripts/backbone/views.js
@@ -219,6 +219,40 @@ Conductor.Views.DeploymentsShow = Backbone.View.extend({
$instances.empty();
$('#instanceTemplate').tmpl(this.collection.toJSON()).appendTo($instances);
+
+ var $alerts = this.$('#deployment-alerts');
+ var alertsVisible = $alerts.find('.collapsible').length == 0 ||
$alerts.find('.collapsible').is(":visible")
+ var failedInstances = _.compact(_.map(this.collection.models, function(model) {
+ if(model.get('is_failed')) {
+ return model.toJSON();
+ }
+ else {
+ return null;
+ }
+ }));
+
+ // Render alerts table
+ $alerts.empty();
+ if(failedInstances.length == 0) return;
+
+ $('#deploymentAlertsHeaderTemplate').tmpl({
+ 'failedCount' : failedInstances.length
+ }).appendTo($alerts);
+
+ // Add callback to Toggle link
+ $alerts.find('a.collapse').click(function(e) {
+ e.preventDefault();
+
$(this).parents('.collapse_entity').find('.collapsible').slideToggle(80);
+ });
+
+ // Restore toggle state on alerts table
+ if(!alertsVisible) {
+ $alerts.find('.collapsible').hide();
+ }
+
+ // Render alerts
+ var $alertsList = this.$('dl.alerts > ul');
+ $('#deploymentAlertTemplate').tmpl(failedInstances).appendTo($alertsList);
}
});
--
1.7.6.5