Browse Source

AMBARI-8576. Alerts UI: ambari service should be included for alert definitions (srimanth)

Srimanth Gunturi 10 years ago
parent
commit
0dbbf5cb68

+ 2 - 0
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',

+ 1 - 0
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',

+ 1 - 0
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',

+ 18 - 0
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'),
@@ -156,6 +157,23 @@ App.AlertDefinition = DS.Model.extend({
     return !!summary[state];
   }.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}

+ 18 - 0
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'),
@@ -45,6 +46,23 @@ App.AlertInstance = DS.Model.extend({
     return '<span class="label alert-state-single-host alert-state-' + state + '">' + state + '</span>';
   }.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}

+ 1 - 1
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>

+ 2 - 2
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}}

+ 1 - 1
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>

+ 7 - 2
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');

+ 5 - 2
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');

+ 9 - 0
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 () {

+ 42 - 0
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');
+    });
+
+  });
+  
+});

+ 40 - 0
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'));
+    });
+  });
+
+});