You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2014/11/21 15:35:34 UTC

ambari git commit: AMBARI-8411. Alerts UI: Alert Definitions mapper should remove not existing models (onechiporenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 650e9d437 -> c507a1017


AMBARI-8411. Alerts UI: Alert Definitions mapper should remove not existing models (onechiporenko)


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

Branch: refs/heads/trunk
Commit: c507a1017554a34896bbb8bf57fc329ef45df45a
Parents: 650e9d4
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Fri Nov 21 16:17:03 2014 +0200
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Fri Nov 21 16:17:03 2014 +0200

----------------------------------------------------------------------
 .../app/mappers/alert_definitions_mapper.js     | 14 +++++++--
 .../app/views/main/alert_definitions_view.js    |  8 +++++
 .../mappers/alert_definitions_mapper_test.js    | 31 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c507a101/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 7d38621..66061c7 100644
--- a/ambari-web/app/mappers/alert_definitions_mapper.js
+++ b/ambari-web/app/mappers/alert_definitions_mapper.js
@@ -73,7 +73,8 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
   map: function (json) {
     if (json && json.items) {
 
-      var portAlertDefinitions = [],
+      var self = this,
+          portAlertDefinitions = [],
           metricsAlertDefinitions = [],
           webAlertDefinitions = [],
           aggregateAlertDefinitions = [],
@@ -83,6 +84,7 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
           alertMetricsUriDefinitions = [],
           alertGroupsMap = App.cache['previousAlertGroupsMap'],
           alertDefinitions = App.AlertDefinition.getAllDefinitions(),
+          alertDefinitionsToDelete = alertDefinitions.mapProperty('id'),
           rawSourceData = {};
 
       json.items.forEach(function (item) {
@@ -117,6 +119,8 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
           alertDefinition.last_triggered = oldAlertDefinition.get('lastTriggered');
         }
 
+        alertDefinitionsToDelete = alertDefinitionsToDelete.without(alertDefinition.id);
+
         // map properties dependent on Alert Definition type
         switch (item.AlertDefinition.source.type) {
           case 'PORT':
@@ -167,6 +171,10 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
         }
       }, this);
 
+      alertDefinitionsToDelete.forEach(function(definitionId) {
+        self.deleteRecord(alertDefinitions.findProperty('id', definitionId));
+      });
+
       // load all mapped data to model
       App.store.loadMany(this.get('reportModel'), alertReportDefinitions);
       App.store.loadMany(this.get('metricsSourceModel'), alertMetricsSourceDefinitions);
@@ -203,7 +211,9 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
   setAlertDefinitionsRawSourceData: function (rawSourceData) {
     var allDefinitions = App.AlertDefinition.getAllDefinitions();
     for (var alertDefinitionId in rawSourceData) {
-      allDefinitions.findProperty('id', +alertDefinitionId).set('rawSourceData', rawSourceData[alertDefinitionId]);
+      if (rawSourceData.hasOwnProperty(alertDefinitionId)) {
+        allDefinitions.findProperty('id', +alertDefinitionId).set('rawSourceData', rawSourceData[alertDefinitionId]);
+      }
     }
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/c507a101/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 6957caf..e5971a3 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -202,6 +202,10 @@ App.MainAlertDefinitionsView = App.TableView.extend({
     }
   }),
 
+  /**
+   * Filtering header for <label>alertDefinition</label> groups
+   * @type {Em.View}
+   */
   alertGroupFilterView: filters.createSelectView({
 
     column: 5,
@@ -220,6 +224,8 @@ App.MainAlertDefinitionsView = App.TableView.extend({
      * @method updateContent
      */
     updateContent: function() {
+      var value = this.get('value');
+
       this.set('content', [
         {
           value: '',
@@ -231,6 +237,8 @@ App.MainAlertDefinitionsView = App.TableView.extend({
           label: group.get('displayNameDefinitions')
         };
       })));
+
+      this.set('selected', this.get('content').findProperty('value', value));
     }.observes('App.router.clusterController.isLoaded', 'controller.mapperTimestamp'),
 
     onChangeValue: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/c507a101/ambari-web/test/mappers/alert_definitions_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/alert_definitions_mapper_test.js b/ambari-web/test/mappers/alert_definitions_mapper_test.js
index 802fd96..86f4ade 100644
--- a/ambari-web/test/mappers/alert_definitions_mapper_test.js
+++ b/ambari-web/test/mappers/alert_definitions_mapper_test.js
@@ -201,6 +201,8 @@ describe('App.alertDefinitionsMapper', function () {
       sinon.stub(App.AggregateAlertDefinition, 'find', function() {return [];});
       sinon.stub(App.ScriptAlertDefinition, 'find', function() {return [];});
 
+      sinon.stub(App.alertDefinitionsMapper, 'deleteRecord', Em.K);
+
       sinon.stub(App.store, 'commit', Em.K);
       sinon.stub(App.store, 'loadMany', function (type, content) {
         type.content = content;
@@ -239,6 +241,8 @@ describe('App.alertDefinitionsMapper', function () {
       App.AggregateAlertDefinition.find.restore();
       App.ScriptAlertDefinition.find.restore();
 
+      App.alertDefinitionsMapper.deleteRecord.restore();
+
       App.router.get.restore();
       App.cache['previousAlertGroupsMap'] = {};
 
@@ -433,6 +437,33 @@ describe('App.alertDefinitionsMapper', function () {
 
     });
 
+    describe('should delete not existing definitions', function () {
+
+      var definitions = [
+        Em.Object.create({id: 100500, type: 'PORT'})
+      ];
+
+      beforeEach(function () {
+
+        sinon.stub(App.AlertDefinition, 'getAllDefinitions', function () {
+          return definitions;
+        });
+
+      });
+
+      afterEach(function() {
+        App.AlertDefinition.getAllDefinitions.restore();
+      });
+
+      it('should delete PORT alert definition with id 100500', function () {
+
+        App.alertDefinitionsMapper.map(json);
+        expect(App.alertDefinitionsMapper.deleteRecord.calledOnce).to.be.true;
+        expect(App.alertDefinitionsMapper.deleteRecord.args[0][0].id).to.equal(100500);
+      });
+
+    });
+
   });
 
 });
\ No newline at end of file