ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-12786. App.alertGroupsMapper shouldn't commit not changed data (onechiporenko)
Date Mon, 17 Aug 2015 12:02:36 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 930d44999 -> 0f693987c


AMBARI-12786. App.alertGroupsMapper shouldn't commit not changed data (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 0f693987c6162e0edf7716af543198ac65e8e603
Parents: 930d449
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Mon Aug 17 14:49:01 2015 +0300
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Mon Aug 17 15:02:26 2015 +0300

----------------------------------------------------------------------
 ambari-web/app/mappers/alert_groups_mapper.js | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0f693987/ambari-web/app/mappers/alert_groups_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_groups_mapper.js b/ambari-web/app/mappers/alert_groups_mapper.js
index 50a8ea5..fffbd2c 100644
--- a/ambari-web/app/mappers/alert_groups_mapper.js
+++ b/ambari-web/app/mappers/alert_groups_mapper.js
@@ -20,6 +20,7 @@ var App = require('app');
 /**
  * Mapper for <code>App.AlertGroup</code>
  * Save general information
+ * Doesn't save not changed data (check it using <code>App.cache['previousAlertGroupsFullMap']</code>)
  * Use <code>App.cache['previousAlertGroupsMap']</code> to store map alertDefinitions-alertGroups.
This map is used
  * in the <code>App.AlertDefinitionsMapper</code> to correctly link alertDefinitions
and alertGroups
  */
@@ -39,10 +40,14 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
   },
 
   map: function (json) {
+    if(Em.isNone(App.cache['previousAlertGroupsFullMap'])) {
+      App.cache['previousAlertGroupsFullMap'] = {};
+    }
     if (!Em.isNone(json, 'items')) {
-
+      console.time('App.alertGroupsMapper execution time');
       var alertGroups = [],
         self = this,
+        groupsMap = {},
         groupsToDelete = App.AlertGroup.find().mapProperty('id'),
         /**
          * AlertGroups-map for <code>App.AlertDefinitionsMappers</code>
@@ -65,7 +70,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
         group.targets = [];
         group.definitions = [];
         if (item.AlertGroup.definitions) {
-          item.AlertGroup.definitions.forEach(function(definition) {
+          item.AlertGroup.definitions.forEach(function (definition) {
             if (!group.definitions.contains(definition.id)) {
               group.definitions.push(definition.id);
             }
@@ -76,7 +81,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
           });
         }
         if (item.AlertGroup.targets) {
-          item.AlertGroup.targets.forEach(function(target) {
+          item.AlertGroup.targets.forEach(function (target) {
             if (!group.targets.contains(target.id)) {
               group.targets.push(target.id);
             }
@@ -86,7 +91,14 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
             alertNotificationsGroupsMap[target.id].push(group.id);
           });
         }
-        alertGroups.push(group);
+
+        groupsMap[group.id] = group;
+        var previousGroup = App.cache['previousAlertGroupsFullMap'][group.id] ? App.cache['previousAlertGroupsFullMap'][group.id]
: {};
+        var changedFields = self.getDiscrepancies(group, previousGroup, ['name', 'description',
'default', 'targets', 'definitions']);
+        if (Object.keys(changedFields).length) {
+          alertGroups.push(group);
+        }
+
       }, this);
 
       groupsToDelete.forEach(function(groupId) {
@@ -94,9 +106,11 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
       });
 
       App.cache['previousAlertGroupsMap'] = alertDefinitionsGroupsMap;
+      App.cache['previousAlertGroupsFullMap'] = groupsMap;
       App.cache['alertNotificationsGroupsMap'] = alertNotificationsGroupsMap;
       App.store.loadMany(this.get('model'), alertGroups);
       App.store.commit();
+      console.timeEnd('App.alertGroupsMapper execution time');
     }
   }
 });


Mime
View raw message