You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2014/12/07 22:05:36 UTC

[1/2] ambari git commit: AMBARI-8575. Alerts UI: Fix various alerts badge issues on Host Details page

Repository: ambari
Updated Branches:
  refs/heads/trunk e7c512c2c -> 0dbbf5cb6


AMBARI-8575. Alerts UI: Fix various alerts badge issues on Host Details page


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/abb48a46
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/abb48a46
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/abb48a46

Branch: refs/heads/trunk
Commit: abb48a464d7e8c58b08d0f5d78579d5e9820b616
Parents: e7c512c
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Sat Dec 6 16:15:46 2014 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Sat Dec 6 16:15:53 2014 -0800

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js |  2 +-
 ambari-web/app/controllers/main/host.js         | 14 +++++---
 .../main/host/host_alerts_controller.js         |  4 +--
 ambari-web/app/data/host/categories.js          |  2 +-
 ambari-web/app/mappers/hosts_mapper.js          |  6 ++--
 ambari-web/app/models/alert_instance.js         |  6 +---
 ambari-web/app/models/host.js                   |  3 +-
 ambari-web/app/templates/main/host.hbs          |  8 +++--
 ambari-web/app/templates/main/host/alerts.hbs   | 37 --------------------
 ambari-web/app/templates/main/host/details.hbs  |  7 +---
 .../app/templates/main/host/host_alerts.hbs     |  2 +-
 ambari-web/app/utils/ajax/ajax.js               |  2 +-
 ambari-web/app/views.js                         |  1 -
 ambari-web/app/views/main/host/alerts.js        | 27 --------------
 .../app/views/main/host/host_alerts_view.js     |  2 +-
 ambari-web/app/views/main/host/menu.js          | 35 ++++++++++++++++--
 16 files changed, 63 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index bb56c88..535b888 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -156,7 +156,7 @@ App.UpdateController = Em.Controller.extend({
       self = this,
       hostDetailsFilter = '';
     var realUrl = '/hosts?<parameters>fields=Hosts/host_name,Hosts/maintenance_state,Hosts/public_host_name,Hosts/cpu_count,Hosts/ph_cpu_count,' +
-      'Hosts/host_status,Hosts/last_heartbeat_time,Hosts/ip,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,' +
+      'alerts_summary,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/ip,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,' +
       'host_components/HostRoles/stale_configs,host_components/HostRoles/service_name,host_components/HostRoles/desired_admin_state,' +
         'metrics/disk,metrics/load/load_one,Hosts/total_mem<hostAuxiliaryInfo><stackVersions>&minimal_response=true';
     var hostAuxiliaryInfo = ',Hosts/os_arch,Hosts/os_type,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free';

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/controllers/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host.js b/ambari-web/app/controllers/main/host.js
index 787bd66..b7f31ef 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -103,8 +103,8 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
       type: 'EQUAL'
     },
     {
-      name: 'criticalAlertsCount',
-      key: 'legacy_alerts/summary/CRITICAL{0}|legacy_alerts/summary/WARNING{1}',
+      name: 'criticalWarningAlertsCount',
+      key: 'alerts_summary/CRITICAL{0}|alerts_summary/WARNING{1}',
       type: 'CUSTOM'
     },
     {
@@ -301,7 +301,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
       'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'],
       'ALERT': data.Clusters.health_report['Host/host_status/ALERT'],
       'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'],
-      'health-status-WITH-ALERTS': (data.legacy_alerts) ? data.legacy_alerts.summary.CRITICAL + data.legacy_alerts.summary.WARNING : 0,
+      'health-status-WITH-ALERTS': (data.alerts_summary) ? data.alerts_summary.CRITICAL + data.alerts_summary.WARNING : 0,
       'health-status-RESTART': data.Clusters.health_report['Host/stale_config'],
       'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'],
       'TOTAL': data.Clusters.total_hosts
@@ -486,7 +486,11 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
     App.db.setFilterConditions(this.get('name'), [filterForStack]);
   },
 
-  showAlertsPopup: function (event) {
+  goToHostAlerts: function (event) {
+    var host = event && event.context;
+    if (host) {
+      App.router.transitionTo('main.hosts.hostDetails.alerts', host);
+    }
   },
 
   /**
@@ -918,7 +922,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
     associations[4] = 'memoryFormatted';
     associations[5] = 'loadAvg';
     associations[6] = 'hostComponents';
-    associations[7] = 'criticalAlertsCount';
+    associations[7] = 'criticalWarningAlertsCount';
     associations[8] = 'componentsWithStaleConfigsCount';
     associations[9] = 'componentsInPassiveStateCount';
     associations[10] = 'selected';

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/controllers/main/host/host_alerts_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/host_alerts_controller.js b/ambari-web/app/controllers/main/host/host_alerts_controller.js
index 3dbe0d9..9eaddd6 100644
--- a/ambari-web/app/controllers/main/host/host_alerts_controller.js
+++ b/ambari-web/app/controllers/main/host/host_alerts_controller.js
@@ -26,8 +26,8 @@ App.MainHostAlertsController = Em.ArrayController.extend({
   }.property('App.router.mainHostDetailsController.content'),
 
   /**
-   * List of all <code>App.AlertDefinition</code> by Host
-   * @type {App.AlertDefinition[]}
+   * List of all <code>App.AlertInstance</code> by Host
+   * @type {App.AlertInstance[]}
    */
   content: function() {
     return App.AlertInstance.find().toArray().filterProperty('host', this.get('selectedHost'));

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/data/host/categories.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/data/host/categories.js b/ambari-web/app/data/host/categories.js
index 0bd4d7a..7e010d5 100644
--- a/ambari-web/app/data/host/categories.js
+++ b/ambari-web/app/data/host/categories.js
@@ -55,7 +55,7 @@ module.exports = [
   },
   {
     value: Em.I18n.t('hosts.host.alerts.label'),
-    hostProperty: 'criticalAlertsCount',
+    hostProperty: 'criticalWarningAlertsCount',
     class: 'icon-exclamation-sign',
     isHealthStatus: false,
     healthClass: 'health-status-WITH-ALERTS',

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/mappers/hosts_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/hosts_mapper.js b/ambari-web/app/mappers/hosts_mapper.js
index e4f6733..b593913 100644
--- a/ambari-web/app/mappers/hosts_mapper.js
+++ b/ambari-web/app/mappers/hosts_mapper.js
@@ -33,7 +33,8 @@ App.hostsMapper = App.QuickDataMapper.create({
     host_components: {
       item: 'id'
     },
-    critical_alerts_count: 'critical_alerts_count',
+    alerts_summary: 'alerts_summary',
+    critical_warning_alerts_count: 'critical_warning_alerts_count',
     cpu: 'Hosts.cpu_count',
     cpu_physical: 'Hosts.ph_cpu_count',
     memory: 'Hosts.total_mem',
@@ -113,7 +114,8 @@ App.hostsMapper = App.QuickDataMapper.create({
           }, this);
         }
 
-        item.critical_alerts_count = (item.legacy_alerts) ? item.legacy_alerts.summary.CRITICAL + item.legacy_alerts.summary.WARNING : 0;
+        var alertsSummary = item.alerts_summary;
+        item.critical_warning_alerts_count = alertsSummary ? (alertsSummary.CRITICAL || 0) + (alertsSummary.WARNING || 0) : 0;
         item.cluster_id = App.get('clusterName');
         item.index = index;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/models/alert_instance.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_instance.js b/ambari-web/app/models/alert_instance.js
index 3353a8c..e81317f 100644
--- a/ambari-web/app/models/alert_instance.js
+++ b/ambari-web/app/models/alert_instance.js
@@ -36,10 +36,6 @@ App.AlertInstance = DS.Model.extend({
   text: DS.attr('string'),
   notification: DS.hasMany('App.AlertNotification'),
 
-  formattedNotifications: function () {
-    return this.get('notification').mapProperty('name').join(', ');
-  }.property('notification'),
-
   /**
    * Status icon markup
    * @type {string}
@@ -53,7 +49,7 @@ App.AlertInstance = DS.Model.extend({
    * Formatted timestamp for latest instance triggering
    * @type {string}
    */
-  lastTriggered: function() {
+  lastTriggeredFormatted: function() {
     return dateUtils.dateFormat(this.get('originalTimestamp'));
   }.property('originalTimestamp'),
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/models/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host.js b/ambari-web/app/models/host.js
index 9f7aa28..8bff1c5 100644
--- a/ambari-web/app/models/host.js
+++ b/ambari-web/app/models/host.js
@@ -44,7 +44,8 @@ App.Host = DS.Model.extend({
   memFree:DS.attr('number'),
   cpuSystem:DS.attr('number'),
   cpuUser:DS.attr('number'),
-  criticalAlertsCount: DS.attr('number'),
+  criticalWarningAlertsCount: DS.attr('number'),
+  alertsSummary: DS.attr('object'),
   passiveState: DS.attr('string'),
   index: DS.attr('number'),
   stackVersions: DS.hasMany('App.HostStackVersion'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/templates/main/host.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host.hbs b/ambari-web/app/templates/main/host.hbs
index be92027..26cb5f9 100644
--- a/ambari-web/app/templates/main/host.hbs
+++ b/ambari-web/app/templates/main/host.hbs
@@ -105,8 +105,12 @@
             <span class="trim_hostname">
               <a title="{{unbound host.hostName}}" href="#" {{action "showDetails" host}}>{{unbound host.hostName}}</a>
             </span>
-            {{#if host.criticalAlertsCount}}
-              <span class="label label-important alerts-count" {{action "showAlertsPopup" host target="controller"}}>{{host.criticalAlertsCount}}</span>
+            {{#if host.criticalWarningAlertsCount}}
+              {{#if host.alertsSummary.CRITICAL}}
+                <span class="label alerts-count label-important" {{action "goToHostAlerts" host target="controller"}}>{{host.criticalWarningAlertsCount}}</span>
+              {{else}}
+                <span class="label alerts-count label-warning" {{action "goToHostAlerts" host target="controller"}}>{{host.criticalWarningAlertsCount}}</span>
+              {{/if}}
             {{/if}}
           </td>
           <td class="restart">

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/templates/main/host/alerts.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/alerts.hbs b/ambari-web/app/templates/main/host/alerts.hbs
deleted file mode 100644
index 205fb1e..0000000
--- a/ambari-web/app/templates/main/host/alerts.hbs
+++ /dev/null
@@ -1,37 +0,0 @@
-{{!
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-}}
-
-<div id="host-alerts">
-    <div class="box-header row">
-    </div>
-    <table class="table advanced-header-table table-bordered table-striped" id="">
-        <thead>
-          <tr class="filter-row">
-          </tr>
-        </thead>
-        <tbody>
-        </tbody>
-    </table>
-
-    <div>
-        <div class="spinner"></div>
-    </div>
-
-    <div class="page-bar">
-    </div>
-</div>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/templates/main/host/details.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/details.hbs b/ambari-web/app/templates/main/host/details.hbs
index 6059f79..8623c08 100644
--- a/ambari-web/app/templates/main/host/details.hbs
+++ b/ambari-web/app/templates/main/host/details.hbs
@@ -21,11 +21,6 @@
     <div class="status-info">
       <span rel="HealthTooltip" {{bindAttr class="view.content.healthClass view.content.healthIconClass"}} {{bindAttr data-original-title="view.content.healthToolTip" }}></span><span
             class='host-title'>{{unbound view.content.hostName}}</span>
-      {{#if view.content.criticalAlertsCount}}
-        <span class="label label-important alerts-count" {{action "showAlertsPopup" content target="App.router.mainHostController"}}>{{view.content.criticalAlertsCount}}</span>
-      {{else}}
-        <span class="label label-success alerts-count" {{action "showAlertsPopup" content target="App.router.mainHostController"}}>{{t hosts.host.alert.noAlerts}}</span>
-      {{/if}}
       {{#unless view.isActive}}
         <span class="host-maintenance-notice pull-right"><span class="icon-medkit"></span> {{t hosts.host.passive.mode}}</span>
       {{/unless}}
@@ -33,7 +28,7 @@
     <div><a href="javascript:void(null)" data-toggle="modal" {{action back}}><i
             class="icon-arrow-left"></i>&nbsp;{{t common.back}}</a></div>
     <div class="content">
-      {{view App.MainHostMenuView}}
+      {{view App.MainHostMenuView hostBinding="view.content"}}
       {{#isAccessible ADMIN}}
         <div class="service-button">
           <div class="btn-group display-inline-block">

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/templates/main/host/host_alerts.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/host_alerts.hbs b/ambari-web/app/templates/main/host/host_alerts.hbs
index 1ab4569..d51e504 100644
--- a/ambari-web/app/templates/main/host/host_alerts.hbs
+++ b/ambari-web/app/templates/main/host/host_alerts.hbs
@@ -47,7 +47,7 @@
           <td class="first">{{alertInstance.label}}</td>
           <td>{{{alertInstance.status}}}</td>
           <td>{{alertInstance.service.displayName}}</td>
-          <td><time class="timeago" {{bindAttr data-original-title="alertInstance.lastTriggered"}}>{{alertInstance.lastTriggeredAgoFormatted}}</time></td>
+          <td><time class="timeago" {{bindAttr data-original-title="alertInstance.lastTriggeredFormatted"}}>{{alertInstance.lastTriggeredAgoFormatted}}</time></td>
           <td>{{alertInstance.formattedNotifications}}</td>
         </tr>
       {{/each}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 7c308cb..6f00a5c 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -2005,7 +2005,7 @@ var urls = {
     }
   },
   'host.status.counters': {
-    'real': '/clusters/{clusterName}?fields=Clusters/health_report,Clusters/total_hosts&minimal_response=true',
+    'real': '/clusters/{clusterName}?fields=Clusters/health_report,Clusters/total_hosts,alerts_summary&minimal_response=true',
     'mock': '/data/hosts/HDP2/host_status_counters.json'
   },
   'components.filter_by_status': {

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views.js b/ambari-web/app/views.js
index 1f0eacd..f7dae7e 100644
--- a/ambari-web/app/views.js
+++ b/ambari-web/app/views.js
@@ -66,7 +66,6 @@ require('views/main/host/details/host_component_views/tasktracker_view');
 require('views/main/host/menu');
 require('views/main/host/summary');
 require('views/main/host/configs');
-require('views/main/host/alerts');
 require('views/main/host/configs_service');
 require('views/main/host/configs_service_menu');
 require('views/main/host/metrics');

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/views/main/host/alerts.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/alerts.js b/ambari-web/app/views/main/host/alerts.js
deleted file mode 100644
index 7fef21e..0000000
--- a/ambari-web/app/views/main/host/alerts.js
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-var App = require('app');
-var date = require('utils/date');
-
-App.MainHostAlertsView = Em.View.extend({
-  templateName: require('templates/main/host/alerts')
-
-
-
-});

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/views/main/host/host_alerts_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/host_alerts_view.js b/ambari-web/app/views/main/host/host_alerts_view.js
index bc9b442..8557890 100644
--- a/ambari-web/app/views/main/host/host_alerts_view.js
+++ b/ambari-web/app/views/main/host/host_alerts_view.js
@@ -44,7 +44,7 @@ App.MainHostAlertsView = App.TableView.extend({
     return this.get('content.length');
   }.property('content.length'),
 
-  colPropAssoc: ['', 'label', 'state', 'service.serviceName', 'lastTriggered', 'notifications'],
+  colPropAssoc: ['', 'label', 'state', 'service.serviceName', 'originalTimestamp', 'notifications'],
 
   sortView: sort.wrapperView,
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/abb48a46/ambari-web/app/views/main/host/menu.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/menu.js b/ambari-web/app/views/main/host/menu.js
index d00a480..ef247b3 100644
--- a/ambari-web/app/views/main/host/menu.js
+++ b/ambari-web/app/views/main/host/menu.js
@@ -21,6 +21,7 @@ var App = require('app');
 App.MainHostMenuView = Em.CollectionView.extend({
   tagName: 'ul',
   classNames: ["nav", "nav-tabs"],
+  host: null,
   content: function () {
     var array = [
       {
@@ -42,7 +43,9 @@ App.MainHostMenuView = Em.CollectionView.extend({
     if (App.get('supports.alerts')) {
       array.push({
         label: 'Alerts',
-        routing: 'alerts'
+        routing: 'alerts',
+        badgeText: '0',
+        badgeClasses: 'label '
       });
     }
     return array;
@@ -55,6 +58,7 @@ App.MainHostMenuView = Em.CollectionView.extend({
     $.each(this._childViews, function () {
       this.set('active', (this.get('content.routing') == defaultRoute ? "active" : ""));
     });
+    this.hostAlertsObserver();
   },
 
   deactivateChildViews: function() {
@@ -63,9 +67,36 @@ App.MainHostMenuView = Em.CollectionView.extend({
     });
   },
 
+  hostAlertsObserver : function() {
+    var criticalWarningCount = this.get('host.criticalWarningAlertsCount');
+    var criticalCount = this.get('host.alertsSummary.CRITICAL');
+    var warningCount = this.get('host.alertsSummary.WARNING');
+    var badgeText = "" + criticalWarningCount;
+    var badgeClasses = "label ";
+    if (criticalCount > 0) {
+      badgeClasses += "label-important";
+    } else if (warningCount > 0){
+      badgeClasses += "label-warning ";
+    }
+    // Update content
+    var content = this.get('content');
+    if (content) {
+      content.forEach(function(item) {
+        if (item.label == 'Alerts' && (item.badgeText !== badgeText || item.badgeClasses != badgeClasses)) {
+          Ember.set(item, 'badgeText', badgeText);
+          Ember.set(item, 'badgeClasses', badgeClasses);
+        }
+      });
+    }
+  }.observes('host.alertsSummary.CRITICAL', 'host.alertsSummary.WARNING', 'host.criticalWarningAlertsCount'),
+
   itemViewClass: Em.View.extend({
     classNameBindings: ["active"],
     active: "",
-    template: Ember.Handlebars.compile('<a {{action hostNavigate view.content.routing }} href="#"> {{unbound view.content.label}}</a>')
+    template: Ember.Handlebars.compile('<a {{action hostNavigate view.content.routing }} href="#"> {{unbound view.content.label}} ' +
+        '{{#if view.content.badgeText}} '+
+          '<span {{bindAttr class="view.content.badgeClasses"}}> '+
+            '{{view.content.badgeText}}'+
+          '</span>  {{/if}}</a>')
   })
 });
\ No newline at end of file


[2/2] ambari git commit: AMBARI-8576. Alerts UI: ambari service should be included for alert definitions (srimanth)

Posted by sr...@apache.org.
AMBARI-8576. Alerts UI: ambari service should be included for alert definitions (srimanth)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0dbbf5cb
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0dbbf5cb
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0dbbf5cb

Branch: refs/heads/trunk
Commit: 0dbbf5cb68ad14c1eeae819cd24668663b4451df
Parents: abb48a4
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Sun Dec 7 11:00:40 2014 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Sun Dec 7 11:58:46 2014 -0800

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |  2 +
 .../app/mappers/alert_definitions_mapper.js     |  1 +
 .../app/mappers/alert_instances_mapper.js       |  1 +
 ambari-web/app/models/alert_definition.js       | 18 +++++++++
 ambari-web/app/models/alert_instance.js         | 18 +++++++++
 ambari-web/app/templates/main/alerts.hbs        |  2 +-
 .../main/alerts/definition_details.hbs          |  4 +-
 .../app/templates/main/host/host_alerts.hbs     |  2 +-
 .../app/views/main/alert_definitions_view.js    |  9 ++++-
 .../app/views/main/host/host_alerts_view.js     |  7 +++-
 ambari-web/test/models/alert_definition_test.js |  9 +++++
 ambari-web/test/models/alert_instance_test.js   | 42 ++++++++++++++++++++
 .../views/main/alert_definitions_view_test.js   | 40 +++++++++++++++++++
 13 files changed, 147 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index ca815b2..a62e00b 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -159,6 +159,7 @@ var files = ['test/init_model_test',
   'test/views/common/configs/config_history_flow_test',
   'test/views/main/dashboard_test',
   'test/views/main/menu_test',
+  'test/views/main/alert_definitions_view_test',
   'test/views/main/alerts/manage_alert_groups_view_test',
   'test/views/main/alerts/manage_alert_notifications_view_test',
   'test/views/main/admin/stack_version/stack_version_details_test',
@@ -226,6 +227,7 @@ var files = ['test/init_model_test',
   'test/models/alert_test',
   'test/models/alert_config_test',
   'test/models/alert_definition_test',
+  'test/models/alert_instance_test',
   'test/models/authentication_test',
   'test/models/cluster_states_test',
   'test/models/config_group_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/mappers/alert_definitions_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_definitions_mapper.js b/ambari-web/app/mappers/alert_definitions_mapper.js
index 66061c7..b2da3e3 100644
--- a/ambari-web/app/mappers/alert_definitions_mapper.js
+++ b/ambari-web/app/mappers/alert_definitions_mapper.js
@@ -37,6 +37,7 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
     name: 'AlertDefinition.name',
     label: 'AlertDefinition.label',
     service_id: 'AlertDefinition.service_name',
+    service_name: 'AlertDefinition.service_name',
     component_name: 'AlertDefinition.component_name',
     enabled: 'AlertDefinition.enabled',
     scope: 'AlertDefinition.scope',

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/mappers/alert_instances_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_instances_mapper.js b/ambari-web/app/mappers/alert_instances_mapper.js
index 468d66c..cc13e71 100644
--- a/ambari-web/app/mappers/alert_instances_mapper.js
+++ b/ambari-web/app/mappers/alert_instances_mapper.js
@@ -27,6 +27,7 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
     definition_name: 'Alert.definition_name',
     definition_id: 'Alert.definition_id',
     service_id: 'Alert.service_name',
+    service_name: 'Alert.service_name',
     component_name: 'Alert.component_name',
     host_id: 'Alert.host_name',
     scope: 'Alert.scope',

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/models/alert_definition.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_definition.js b/ambari-web/app/models/alert_definition.js
index 45b12a7..9e22153 100644
--- a/ambari-web/app/models/alert_definition.js
+++ b/ambari-web/app/models/alert_definition.js
@@ -24,6 +24,7 @@ App.AlertDefinition = DS.Model.extend({
   name: DS.attr('string'),
   label: DS.attr('string'),
   service: DS.belongsTo('App.Service'),
+  serviceName: DS.attr('string'),
   componentName: DS.attr('string'),
   enabled: DS.attr('boolean'),
   scope: DS.attr('string'),
@@ -157,6 +158,23 @@ App.AlertDefinition = DS.Model.extend({
   }.property('summary'),
 
   /**
+   * For alerts we will have processes which are not typical
+   * cluster services - like Ambari-Server. This method unifies
+   * cluster services and other services into a common display-name.
+   * @see App.AlertInstance#serviceDisplayName()
+   */
+  serviceDisplayName : function() {
+    var serviceName = this.get('service.displayName');
+    if (!serviceName) {
+      serviceName = this.get('serviceName');
+      if (serviceName) {
+        serviceName = serviceName.toCapital();
+      }
+    }
+    return serviceName;
+  }.property('serviceName', 'service.displayName'),
+
+  /**
    * List of css-classes for alert types
    * @type {object}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/models/alert_instance.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_instance.js b/ambari-web/app/models/alert_instance.js
index e81317f..3542fbf 100644
--- a/ambari-web/app/models/alert_instance.js
+++ b/ambari-web/app/models/alert_instance.js
@@ -25,6 +25,7 @@ App.AlertInstance = DS.Model.extend({
   definitionName: DS.attr('string'),
   definitionId: DS.attr('number'),
   service: DS.belongsTo('App.Service'),
+  serviceName: DS.attr('string'),
   componentName: DS.attr('string'),
   host: DS.belongsTo('App.Host'),
   scope: DS.attr('string'),
@@ -46,6 +47,23 @@ App.AlertInstance = DS.Model.extend({
   }.property('state'),
 
   /**
+   * For alerts we will have processes which are not typical
+   * cluster services - like Ambari-Server. This method unifies
+   * cluster services and other services into a common display-name.
+   * @see App.AlertDefinition#serviceDisplayName()
+   */
+  serviceDisplayName : function() {
+    var serviceName = this.get('service.displayName');
+    if (!serviceName) {
+      serviceName = this.get('serviceName');
+      if (serviceName) {
+        serviceName = serviceName.toCapital();
+      }
+    }
+    return serviceName;
+  }.property('serviceName', 'service.displayName'),
+
+  /**
    * Formatted timestamp for latest instance triggering
    * @type {string}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/templates/main/alerts.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts.hbs b/ambari-web/app/templates/main/alerts.hbs
index 36a424b..ac5bc13 100644
--- a/ambari-web/app/templates/main/alerts.hbs
+++ b/ambari-web/app/templates/main/alerts.hbs
@@ -57,7 +57,7 @@
             <a href="#" {{action "gotoAlertDetails" alertDefinition}}>{{alertDefinition.label}}</a>
           </td>
           <td>{{{alertDefinition.status}}}</td>
-          <td>{{alertDefinition.service.displayName}}</td>
+          <td>{{alertDefinition.serviceDisplayName}}</td>
           <td>
             <span {{bindAttr class=":type-icon  alertDefinition.typeIconClass"}}></span>{{alertDefinition.type}}
           </td>

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/templates/main/alerts/definition_details.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/definition_details.hbs b/ambari-web/app/templates/main/alerts/definition_details.hbs
index 6969162..a0bfe3a 100644
--- a/ambari-web/app/templates/main/alerts/definition_details.hbs
+++ b/ambari-web/app/templates/main/alerts/definition_details.hbs
@@ -95,10 +95,10 @@
         {{/isAccessible}}
       </div>
       <div class="properties-list">
-        {{#if controller.content.service.displayName}}
+        {{#if controller.content.serviceDisplayName}}
         <div class="row-fluid">
           <div class="span4 property-name">{{t common.service}}:</div>
-          <div class="span8"><span>{{controller.content.service.displayName}}</span></div>
+          <div class="span8"><span>{{controller.content.serviceDisplayName}}</span></div>
         </div>
         {{/if}}
         {{#if controller.content.componentNameFormatted}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/templates/main/host/host_alerts.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/host_alerts.hbs b/ambari-web/app/templates/main/host/host_alerts.hbs
index d51e504..bc88e4e 100644
--- a/ambari-web/app/templates/main/host/host_alerts.hbs
+++ b/ambari-web/app/templates/main/host/host_alerts.hbs
@@ -46,7 +46,7 @@
         <tr>
           <td class="first">{{alertInstance.label}}</td>
           <td>{{{alertInstance.status}}}</td>
-          <td>{{alertInstance.service.displayName}}</td>
+          <td>{{alertInstance.serviceDisplayName}}</td>
           <td><time class="timeago" {{bindAttr data-original-title="alertInstance.lastTriggeredFormatted"}}>{{alertInstance.lastTriggeredAgoFormatted}}</time></td>
           <td>{{alertInstance.formattedNotifications}}</td>
         </tr>

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js b/ambari-web/app/views/main/alert_definitions_view.js
index 81cf2e7..23302ef 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -40,7 +40,7 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     return this.get('content.length');
   }.property('content.length'),
 
-  colPropAssoc: ['', 'label', 'summary', 'service.serviceName', 'type', 'lastTriggered', 'enabled', 'groups'],
+  colPropAssoc: ['', 'label', 'summary', 'serviceName', 'type', 'lastTriggered', 'enabled', 'groups'],
 
   /**
    * @type {string}
@@ -187,7 +187,12 @@ App.MainAlertDefinitionsView = App.TableView.extend({
           value: service.get('serviceName'),
           label: service.get('displayName')
         }
-      }));
+      }).concat([
+        {
+          value: 'AMBARI',
+          label: Em.I18n.t('app.name')
+        }
+      ]));
     }.property('App.router.clusterController.isLoaded'),
     onChangeValue: function () {
       this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/app/views/main/host/host_alerts_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/host_alerts_view.js b/ambari-web/app/views/main/host/host_alerts_view.js
index 8557890..a76124d 100644
--- a/ambari-web/app/views/main/host/host_alerts_view.js
+++ b/ambari-web/app/views/main/host/host_alerts_view.js
@@ -44,7 +44,7 @@ App.MainHostAlertsView = App.TableView.extend({
     return this.get('content.length');
   }.property('content.length'),
 
-  colPropAssoc: ['', 'label', 'state', 'service.serviceName', 'originalTimestamp', 'notifications'],
+  colPropAssoc: ['', 'label', 'state', 'serviceName', 'originalTimestamp', 'notifications'],
 
   sortView: sort.wrapperView,
 
@@ -167,7 +167,10 @@ App.MainHostAlertsView = App.TableView.extend({
               value: service.get('serviceName'),
               label: service.get('displayName')
             }
-          }));
+          })).concat({
+            value: 'AMBARI',
+            label: Em.I18n.t('app.name')
+          });
     }.property('App.router.clusterController.isLoaded'),
     onChangeValue: function () {
       this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/test/models/alert_definition_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/alert_definition_test.js b/ambari-web/test/models/alert_definition_test.js
index 3124059..65da5f9 100644
--- a/ambari-web/test/models/alert_definition_test.js
+++ b/ambari-web/test/models/alert_definition_test.js
@@ -132,6 +132,15 @@ describe('App.AlertDefinition', function () {
 
   });
 
+  describe('#serviceDisplayName', function () {
+
+    it('should get name for non-existing service', function () {
+      model.set('serviceName', 'FOOBAR');
+      expect(model.get('serviceDisplayName')).to.equal('Foobar');
+    });
+
+  });
+
   describe('#componentNameFormatted', function () {
 
     beforeEach(function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/test/models/alert_instance_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/alert_instance_test.js b/ambari-web/test/models/alert_instance_test.js
new file mode 100644
index 0000000..ba6fac1
--- /dev/null
+++ b/ambari-web/test/models/alert_instance_test.js
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('models/alert_instance');
+
+var model;
+
+describe('App.AlertInstance', function () {
+
+  beforeEach(function () {
+
+    model = App.AlertInstance.createRecord();
+
+  });
+
+  describe('#serviceDisplayName', function () {
+
+    it('should get name for non-existing service', function () {
+      model.set('serviceName', 'FOOBAR');
+      expect(model.get('serviceDisplayName')).to.equal('Foobar');
+    });
+
+  });
+  
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dbbf5cb/ambari-web/test/views/main/alert_definitions_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alert_definitions_view_test.js b/ambari-web/test/views/main/alert_definitions_view_test.js
new file mode 100644
index 0000000..47aee7f
--- /dev/null
+++ b/ambari-web/test/views/main/alert_definitions_view_test.js
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('messages');
+require('views/main/alert_definitions_view');
+
+var view;
+
+describe('App.MainAlertDefinitionsView', function () {
+
+  beforeEach(function () {
+    view = App.MainAlertDefinitionsView.create({});
+  });
+
+  describe('#serviceFilterView', function () {
+    it('Add Ambari service to filters', function () {
+      var serviceFilterClass = view.serviceFilterView;
+      var content = serviceFilterClass.create({}).get('content');
+      expect(content[0].label==Em.I18n.t('common.all'));
+      expect(content[content.length-1].label==Em.I18n.t('app.name'));
+    });
+  });
+
+});