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 2015/01/26 11:33:40 UTC

ambari git commit: AMBARI-9326. Not all dashboard's widgets displays on cluster with not all services after service adding. (onechiporenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk b4dbd5df0 -> 736511f00


AMBARI-9326. Not all dashboard's widgets displays on cluster with not all services after service adding. (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 736511f001596ce86fd0cb99eda0fa0d0a49db63
Parents: b4dbd5d
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Mon Jan 26 12:14:51 2015 +0200
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Mon Jan 26 12:14:51 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/views/main/dashboard/widgets.js  | 87 +++++---------------
 .../test/views/main/dashboard/widgets_test.js   | 48 +++++++++++
 2 files changed, 70 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/736511f0/ambari-web/app/views/main/dashboard/widgets.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/widgets.js b/ambari-web/app/views/main/dashboard/widgets.js
index 8e1ca51..d39c12f 100644
--- a/ambari-web/app/views/main/dashboard/widgets.js
+++ b/ambari-web/app/views/main/dashboard/widgets.js
@@ -373,80 +373,37 @@ App.MainDashboardWidgetsView = Em.View.extend(App.UserPref, App.LocalStorage, {
   checkServicesChange: function (currentPrefObject) {
     var toDelete = $.extend(true, {}, currentPrefObject);
     var toAdd = [];
-    var self = this;
+    var serviceWidgetsMap = {
+      hdfs_model: ['1', '2', '3', '4', '5', '10', '11'],
+      host_metrics_model: ['6', '7', '8', '9'],
+      hbase_model: ['12', '13', '14', '15', '16'],
+      yarn_model: ['17', '18', '19', '20', '23'],
+      storm_model: ['21'],
+      flume_model: ['22']
+    };
 
     // check each service, find out the newly added service and already deleted service
-    if (this.get('hdfs_model') != null) {
-      var hdfs = ['1', '2', '3', '4', '5', '10', '11'];
-      hdfs.forEach(function (item) {
-        toDelete = self.removeWidget(toDelete, item);
-      }, this);
-    }
-
-    // Display widgets for host metrics if the stack definition has a host metrics service to display it.
-    if (this.get('host_metrics_model') != null) {
-      var hostMetrics = ['6', '7', '8', '9'];
-      var flag = self.containsWidget(toDelete, hostMetrics[0]);
-      if (flag) {
-        hostMetrics.forEach(function (item) {
-          toDelete = self.removeWidget(toDelete, item);
-        }, this);
-      } else {
-        toAdd = toAdd.concat(hostMetrics);
+    Em.keys(serviceWidgetsMap).forEach(function (modelName) {
+      if (!Em.isNone(this.get(modelName))) {
+        var ids = serviceWidgetsMap[modelName];
+        var flag = this.containsWidget(toDelete, ids[0]);
+        if (flag) {
+          ids.forEach(function (item) {
+            toDelete = this.removeWidget(toDelete, item);
+          }, this);
+        } else {
+          toAdd = toAdd.concat(ids);
+        }
       }
-    }
+    }, this);
 
-    if (this.get('hbase_model') != null) {
-      var hbase = ['12', '13', '14', '15', '16'];
-      var flag = self.containsWidget(toDelete, hbase[0]);
-      if (flag) {
-        hbase.forEach(function (item) {
-          toDelete = self.removeWidget(toDelete, item);
-        }, this);
-      } else {
-        toAdd = toAdd.concat(hbase);
-      }
-    }
-    if (this.get('yarn_model') != null) {
-      var yarn = ['17', '18', '19', '20', '23'];
-      var flag = self.containsWidget(toDelete, yarn[0]);
-      if (flag) {
-        yarn.forEach(function (item) {
-          toDelete = self.removeWidget(toDelete, item);
-        }, this);
-      } else {
-        toAdd = toAdd.concat(yarn);
-      }
-    }
-    if (this.get('storm_model') != null) {
-      var storm = ['21'];
-      var flag = self.containsWidget(toDelete, storm[0]);
-      if (flag) {
-        storm.forEach(function (item) {
-          toDelete = self.removeWidget(toDelete, item);
-        }, this);
-      } else {
-        toAdd = toAdd.concat(storm);
-      }
-    }
-    if (this.get('flume_model') != null) {
-      var flume = ['22'];
-      var flag = self.containsWidget(toDelete, flume[0]);
-      if (flag) {
-        flume.forEach(function (item) {
-          toDelete = self.removeWidget(toDelete, item);
-        }, this);
-      } else {
-        toAdd = toAdd.concat(flume);
-      }
-    }
     var value = currentPrefObject;
     if (toDelete.visible.length || toDelete.hidden.length) {
       toDelete.visible.forEach(function (item) {
-        value = self.removeWidget(value, item);
+        value = this.removeWidget(value, item);
       }, this);
       toDelete.hidden.forEach(function (item) {
-        value = self.removeWidget(value, item[0]);
+        value = this.removeWidget(value, item[0]);
       }, this);
     }
     if (toAdd.length) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/736511f0/ambari-web/test/views/main/dashboard/widgets_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/dashboard/widgets_test.js b/ambari-web/test/views/main/dashboard/widgets_test.js
index 19050c6..e02fb7f 100644
--- a/ambari-web/test/views/main/dashboard/widgets_test.js
+++ b/ambari-web/test/views/main/dashboard/widgets_test.js
@@ -451,4 +451,52 @@ describe('App.MainDashboardWidgetsView', function () {
       expect(view.get('gangliaUrl')).to.equal('url/?r=hour&cs=&ce=&m=&s=by+name&c=HDPSlaves&tab=m&vn=');
     });
   });
+
+  describe('#checkServicesChange', function () {
+
+    var emptyCurrentPref = {
+        visible: [],
+        hidden: [],
+        threshold: {}
+      },
+      widgetsMap = {
+        hdfs_model: ['1', '2', '3', '4', '5', '10', '11'],
+        host_metrics_model: ['6', '7', '8', '9'],
+        hbase_model: ['12', '13', '14', '15', '16'],
+        yarn_model: ['17', '18', '19', '20', '23'],
+        storm_model: ['21'],
+        flume_model: ['22']
+      },
+      emptyModelTitle = '{0} absent',
+      notEmptyModelTitle = '{0} present';
+
+    Em.keys(widgetsMap).forEach(function (item, index, array) {
+      it(notEmptyModelTitle.format(item), function () {
+        array.forEach(function (modelName) {
+          view.set(modelName, modelName == item ? {} : null);
+        });
+        expect(view.checkServicesChange(emptyCurrentPref).visible).to.eql(widgetsMap[item]);
+      });
+    });
+
+    Em.keys(widgetsMap).forEach(function (item, index, array) {
+      it(emptyModelTitle.format(item), function () {
+        var expected = [];
+        array.forEach(function (modelName) {
+          if (modelName == item) {
+            view.set(modelName, null);
+          } else {
+            view.set(modelName, {});
+            expected = expected.concat(widgetsMap[modelName]);
+          }
+        });
+        expect(view.checkServicesChange({
+          visible: widgetsMap[item],
+          hidden: [],
+          threshold: {}
+        }).visible).to.eql(expected);
+      });
+    });
+
+  });
 });
\ No newline at end of file