ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject [1/2] ambari git commit: AMBARI-10746. Integrate service summary page and heatmap page with the active layout API. (jaimin)
Date Sat, 25 Apr 2015 16:38:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 682d82eef -> 36ab07ca6


http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/assets/data/widget_layouts/YARN_SUMMARY.json
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/data/widget_layouts/YARN_SUMMARY.json b/ambari-web/app/assets/data/widget_layouts/YARN_SUMMARY.json
new file mode 100644
index 0000000..6b4317e
--- /dev/null
+++ b/ambari-web/app/assets/data/widget_layouts/YARN_SUMMARY.json
@@ -0,0 +1,84 @@
+
+{
+  "href" : "http://c6401.ambari.apache.org:8080/api/v1/users/admin/activeWidgetLayouts?WidgetLayoutInfo/section_name=YARN_SUMMARY",
+  "items" : [
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/widget_layouts/10",
+      "WidgetLayoutInfo" : {
+        "cluster_name" : "c1",
+        "display_name" : "Standard YARN Dashboard",
+        "id" : 10,
+        "layout_name" : "admin_yarn_dashboard",
+        "scope" : "USER",
+        "section_name" : "YARN_SUMMARY",
+        "user_name" : "admin",
+        "widgets" : [
+          {
+            "WidgetInfo" : {
+              "id" : 34,
+              "metrics" : "[{\"name\":\"yarn.NodeManagerMetrics.AllocatedGB\",\"metric_path\":\"metrics/yarn/AllocatedGB\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"},{\"name\":\"proc_total\",\"metric_path\":\"metrics/process/proc_total\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"}]",
+              "author" : "ambari",
+              "description" : "",
+              "scope" : "CLUSTER",
+              "properties" : "{\"display_unit\":\"\",\"graph_type\":\"LINE\",\"time_range\":\"1\"}",
+              "widget_name" : "NodeManager RAM Utilization",
+              "widget_type" : "GRAPH",
+              "time_created" : 1429906622523,
+              "display_name" : "NodeManager RAM Utilization",
+              "values" : "[{\"name\":\"Total Allocatable RAM Utilized across NodeManager\",\"value\":\"${yarn.NodeManagerMetrics.AllocatedGB}\"},{\"name\":\"NodeManager
total processes\",\"value\":\"${proc_total}\"}]",
+              "cluster_name" : "c1"
+            }
+          },
+          {
+            "WidgetInfo" : {
+              "id" : 35,
+              "metrics" : "[{\"name\":\"yarn.NodeManagerMetrics.AllocatedVCores\",\"metric_path\":\"metrics/yarn/AllocatedVCores\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"},{\"name\":\"cpu_idle\",\"metric_path\":\"metrics/cpu/cpu_idle\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"}]",
+              "author" : "ambari",
+              "description" : "",
+              "scope" : "CLUSTER",
+              "properties" : "{\"display_unit\":\"\",\"graph_type\":\"LINE\",\"time_range\":\"1\"}",
+              "widget_name" : "NodeManager CPU Utilization",
+              "widget_type" : "GRAPH",
+              "time_created" : 1429906622523,
+              "display_name" : "NodeManager CPU Utilization",
+              "values" : "[{\"name\":\"Total Allocatable CPU Utilized across NodeManager\",\"value\":\"${yarn.NodeManagerMetrics.AllocatedVCores}\"},{\"name\":\"NodeManager
CPU Idle\",\"value\":\"${cpu_idle}\"}]",
+              "cluster_name" : "c1"
+            }
+          },
+          {
+            "WidgetInfo" : {
+              "id" : 36,
+              "metrics" : "[{\"name\":\"read_bytes\",\"metric_path\":\"metrics/disk/read_bytes\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"},{\"name\":\"write_bytes\",\"metric_path\":\"metrics/disk/write_bytes\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"},{\"name\":\"bytes_in\",\"metric_path\":\"metrics/network/bytes_in\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"},{\"name\":\"bytes_out\",\"metric_path\":\"metrics/network/bytes_out\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"}]",
+              "author" : "ambari",
+              "description" : "",
+              "scope" : "CLUSTER",
+              "properties" : "{\"display_unit\":\"\",\"graph_type\":\"LINE\",\"time_range\":\"1\"}",
+              "widget_name" : "NodeManager Disk and Network Utilization",
+              "widget_type" : "GRAPH",
+              "time_created" : 1429906622523,
+              "display_name" : "NodeManager Disk and Network Utilization",
+              "values" : "[{\"name\":\"DISK IO\",\"value\":\"${read_bytes + write_bytes}\"},{\"name\":\"Network
IO\",\"value\":\"${bytes_in + bytes_out}\"}]",
+              "cluster_name" : "c1"
+            }
+          },
+          {
+            "WidgetInfo" : {
+              "id" : 37,
+              "metrics" : "[{\"name\":\"yarn.NodeManagerMetrics.ContainersFailed\",\"metric_path\":\"metrics/yarn/ContainersFailed\",\"service_name\":\"YARN\",\"component_name\":\"NODEMANAGER\"}]",
+              "author" : "ambari",
+              "description" : "",
+              "scope" : "CLUSTER",
+              "properties" : "{\"display_unit\":\"\",\"graph_type\":\"LINE\",\"time_range\":\"1\"}",
+              "widget_name" : "NodeManager Container Failures",
+              "widget_type" : "GRAPH",
+              "time_created" : 1429906622523,
+              "display_name" : "NodeManager Container Failures",
+              "values" : "[{\"name\":\"NodeManager Container Failures\",\"value\":\"${yarn.NodeManagerMetrics.ContainersFailed}\"}]",
+              "cluster_name" : "c1"
+            }
+          }
+        ]
+      }
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/controllers/main/charts/heatmap.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap.js b/ambari-web/app/controllers/main/charts/heatmap.js
index 8404c2a..f5741f0 100644
--- a/ambari-web/app/controllers/main/charts/heatmap.js
+++ b/ambari-web/app/controllers/main/charts/heatmap.js
@@ -74,7 +74,7 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin,
{
       });
       var categories = self.categorizeByServiceName(self.get('allHeatmaps'));
       self.set('heatmapCategories', categories);
-      self.loadActiveWidgetLayout();
+      self.getActiveWidgetLayout();
     });
   },
 
@@ -112,20 +112,6 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin,
{
   },
 
   /**
-   * success callback of <code>loadActiveWidgetLayout()</code>
-   * @overrriden
-   * @param {object|null} data
-   */
-  loadActiveWidgetLayoutSuccessCallback: function (data) {
-    if (data.items[0]) {
-      App.widgetMapper.map(data.items[0].WidgetLayoutInfo);
-      App.widgetLayoutMapper.map(data);
-      this.set('activeWidgetLayout', App.WidgetLayout.find().findProperty('layoutName', this.get('defaultLayoutName')));
-      this.set('isWidgetsLoaded', true);
-    }
-  },
-
-  /**
    *  Gets all heatmap widgets that should be available in select metrics dropdown on heatmap
page
    * @return {$.ajax}
    */
@@ -136,7 +122,8 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin,
{
       name: 'widgets.get',
       sender: this,
       data: {
-        urlParams: urlParams
+        urlParams: urlParams,
+        sectionName: this.get('sectionName')
       }
     });
   },
@@ -250,7 +237,7 @@ App.MainChartsHeatmapController = Em.Controller.extend(App.WidgetSectionMixin,
{
     var self = this;
     var metricItem = Em.Object.create(event.context);
     this.saveWidgetLayout([metricItem]).done(function(){
-      self.loadActiveWidgetLayout();
+      self.getActiveWidgetLayout();
     });
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/controllers/main/service/info/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/info/summary.js b/ambari-web/app/controllers/main/service/info/summary.js
index e65b9dc..9223cc0 100644
--- a/ambari-web/app/controllers/main/service/info/summary.js
+++ b/ambari-web/app/controllers/main/service/info/summary.js
@@ -315,13 +315,6 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix
 
 
   /**
-   * @type {Em.A}
-   */
-  widgetLayouts: function () {
-    return App.WidgetLayout.find();
-  }.property('isWidgetLayoutsLoaded'),
-
-  /**
    * load widget layouts across all users in CLUSTER scope
    * @returns {$.ajax}
    */
@@ -513,7 +506,7 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix
    * update current active widget layout
    */
   updateActiveLayout: function () {
-    this.loadActiveWidgetLayout();
+    this.getActiveWidgetLayout();
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/mixins/common/widgets/widget_section.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/widget_section.js b/ambari-web/app/mixins/common/widgets/widget_section.js
index c8b76e9..8ba6fd5 100644
--- a/ambari-web/app/mixins/common/widgets/widget_section.js
+++ b/ambari-web/app/mixins/common/widgets/widget_section.js
@@ -33,17 +33,38 @@ App.WidgetSectionMixin = Ember.Mixin.create({
   }.property('content.serviceName'),
 
   /**
+   * UI user default layout name
+   */
+  userLayoutName: function () {
+    var heatmapType;
+    var loginName = App.router.get('loginName');
+    if (this.get('content.serviceName')) {
+      heatmapType = this.get('content.serviceName').toLowerCase();
+    } else {
+      heatmapType = "system";
+    }
+    return loginName + "_" + heatmapType + this.layoutNameSuffix;
+  }.property('content.serviceName'),
+
+  /**
    * UI section name
    */
   sectionName: function () {
     if (this.get('content.serviceName')) {
       return this.get('content.serviceName') + this.sectionNameSuffix;
     } else {
-      return "SYSTEM"  + this.sectionNameSuffix
+      return "SYSTEM" + this.sectionNameSuffix
     }
   }.property('content.serviceName'),
 
 
+  /**
+   * @type {Em.A}
+   */
+  widgetLayouts: function () {
+    return App.WidgetLayout.find();
+  }.property('isWidgetLayoutsLoaded'),
+
 
   /**
    * Does Service has widget descriptor defined in the stack
@@ -57,7 +78,7 @@ App.WidgetSectionMixin = Ember.Mixin.create({
     } else if (this.get('sectionName') === 'SYSTEM_HEATMAPS') {
       isServiceWithWidgetdescriptor = true;
     }
-    return isServiceWithWidgetdescriptor && App.supports.customizedWidgets;
+    return isServiceWithWidgetdescriptor && (App.supports.customizedWidgets || this.sectionNameSuffix
=== "_HEATMAPS");
   }.property('content.serviceName'),
 
   /**
@@ -73,27 +94,31 @@ App.WidgetSectionMixin = Ember.Mixin.create({
       if (this.get('activeWidgetLayout.widgets')) {
         return this.get('activeWidgetLayout.widgets').toArray();
       } else {
-        return  [];
+        return [];
       }
     }
   }.property('isWidgetsLoaded'),
 
+
   /**
    * load widgets defined by user
    * @returns {$.ajax}
    */
-  loadActiveWidgetLayout: function () {
+  getActiveWidgetLayout: function () {
+    var sectionName = this.get('sectionName');
+    var urlParams = 'WidgetLayoutInfo/section_name=' + sectionName;
     this.set('activeWidgetLayout', {});
     this.set('isWidgetsLoaded', false);
     if (this.get('isServiceWithEnhancedWidgets')) {
       return App.ajax.send({
-        name: 'widget.layout.get',
+        name: 'widgets.layouts.active.get',
         sender: this,
         data: {
-          layoutName: this.get('defaultLayoutName'),
-          serviceName: this.get('content.serviceName')
+          userName: App.router.get('loginName'),
+          sectionName: sectionName,
+          urlParams: urlParams
         },
-        success: 'loadActiveWidgetLayoutSuccessCallback'
+        success: 'getActiveWidgetLayoutSuccessCallback'
       });
     } else {
       this.set('isWidgetsLoaded', true);
@@ -102,18 +127,112 @@ App.WidgetSectionMixin = Ember.Mixin.create({
 
 
   /**
-   * success callback of <code>loadActiveWidgetLayout()</code>
+   * success callback of <code>getActiveWidgetLayout()</code>
    * @param {object|null} data
    */
-  loadActiveWidgetLayoutSuccessCallback: function (data) {
+  getActiveWidgetLayoutSuccessCallback: function (data) {
+    var self = this;
     if (data.items[0]) {
+      self.getWidgetLayoutSuccessCallback(data);
+    } else {
+      self.getAllActiveWidgetLayouts().done(function (activeWidgetLayoutsData) {
+        self.getDefaultWidgetLayoutByName(self.get('defaultLayoutName')).done(function (defaultWidgetLayoutData)
{
+          self.createUserWidgetLayout(defaultWidgetLayoutData).done(function (userLayoutIdData)
{
+            var activeWidgetLayouts;
+            var widgetLayouts = [];
+            if (!!activeWidgetLayoutsData.items.length) {
+              widgetLayouts = activeWidgetLayoutsData.items.map(function (item) {
+                return {
+                  "id": item.WidgetLayoutInfo.id
+                }
+              });
+            }
+            widgetLayouts.push({id: userLayoutIdData.resources[0].WidgetLayoutInfo.id});
+            activeWidgetLayouts = {
+              "WidgetLayouts": widgetLayouts
+            };
+            self.saveActiveWidgetLayouts(activeWidgetLayouts).done(function () {
+              self.getActiveWidgetLayout();
+            });
+          });
+        });
+      });
+    }
+  },
+
+  getAllActiveWidgetLayouts: function () {
+    return App.ajax.send({
+      name: 'widgets.layouts.all.active.get',
+      sender: this,
+      data: {
+        userName: App.router.get('loginName')
+      }
+    });
+  },
+
+  /**
+   * success callback of <code>getWidgetLayout()</code>
+   * @param {object|null} data
+   */
+  getWidgetLayoutSuccessCallback: function (data) {
+    if (data) {
       App.widgetMapper.map(data.items[0].WidgetLayoutInfo);
       App.widgetLayoutMapper.map(data);
-      this.set('activeWidgetLayout', App.WidgetLayout.find().findProperty('layoutName', this.get('defaultLayoutName')));
+      this.set('activeWidgetLayout', App.WidgetLayout.find().findProperty('id', data.items[0].WidgetLayoutInfo.id));
       this.set('isWidgetsLoaded', true);
     }
   },
 
+
+  getDefaultWidgetLayoutByName: function (layoutName) {
+    var urlParams = 'WidgetLayoutInfo/layout_name=' + layoutName;
+    return App.ajax.send({
+      name: 'widget.layout.get',
+      sender: this,
+      data: {
+        urlParams: urlParams
+      }
+    });
+  },
+
+  createUserWidgetLayout: function (defaultWidgetLayoutData) {
+    var layout = defaultWidgetLayoutData.items[0].WidgetLayoutInfo;
+    var layoutName = this.get('userLayoutName');
+    var data = {
+      "WidgetLayoutInfo": {
+        "display_name": layout.display_name,
+        "layout_name": layoutName,
+        "scope": "USER",
+        "section_name": layout.section_name,
+        "user_name": App.router.get('loginName'),
+        "widgets": layout.widgets.map(function (widget) {
+          return {
+            "id": widget.WidgetInfo.id
+          }
+        })
+      }
+    };
+    return App.ajax.send({
+      name: 'widget.layout.create',
+      sender: this,
+      data: {
+        data: data
+      }
+    });
+  },
+
+  saveActiveWidgetLayouts: function (activeWidgetLayouts) {
+    return App.ajax.send({
+      name: 'widget.activelayouts.edit',
+      sender: this,
+      data: {
+        data: activeWidgetLayouts,
+        userName: App.router.get('loginName')
+      }
+    });
+  },
+
+
   /**
    * save layout after re-order widgets
    * return {$.ajax}

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/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 cbb0021..9911562 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -2408,7 +2408,7 @@ var urls = {
 
   'widgets.get': {
     real: '/clusters/{clusterName}/widgets?{urlParams}',
-    mock: '/data/widget_layouts/all_heatmaps.json'
+    mock: '/data/widget_layouts/{sectionName}_WIDGETS.json'
   },
 
   'widgets.all.shared.get': {
@@ -2426,8 +2426,13 @@ var urls = {
     mock: '/data/widget_layouts/HBASE/stack_layout.json'
   },
 
+  'widget.layout.id.get': {
+    real: '/clusters/{clusterName}/widget_layouts/{layoutId}',
+    mock: '/data/widget_layouts/{serviceName}/default_dashboard.json'
+  },
+
   'widget.layout.get': {
-    real: '/clusters/{clusterName}/widget_layouts?WidgetLayoutInfo/layout_name={layoutName}',
+    real: '/clusters/{clusterName}/widget_layouts?{urlParams}',
     mock: '/data/widget_layouts/{serviceName}/default_dashboard.json'
   },
 
@@ -2442,6 +2447,17 @@ var urls = {
     }
   },
 
+  'widget.layout.create': {
+    real: '/clusters/{clusterName}/widget_layouts',
+    mock: '',
+    format: function (data) {
+      return {
+        type: 'POST',
+        data: JSON.stringify(data.data)
+      }
+    }
+  },
+
   'widgets.layout.userDefined.get': {
     real: '/users/{loginName}/widget_layouts?section_name={sectionName}',
     mock: '/data/widget_layouts/HBASE/empty_user_layout.json'
@@ -2452,6 +2468,29 @@ var urls = {
     mock: '/data/widget_layouts/HBASE/layouts.json'
   },
 
+  'widgets.layouts.active.get': {
+    real: '/users/{userName}/activeWidgetLayouts?{urlParams}',
+    mock: '/data/widget_layouts/{sectionName}.json'
+  },
+
+  'widgets.layouts.all.active.get': {
+    real: '/users/{userName}/activeWidgetLayouts',
+    mock: ''
+  },
+
+
+  'widget.activelayouts.edit': {
+    real: '/users/{userName}/activeWidgetLayouts/',
+    mock: '',
+    format: function (data) {
+      return {
+        type: 'PUT',
+        data: JSON.stringify(data.data)
+      }
+    }
+  },
+
+
   'widget.action.delete': {
     real: '/clusters/{clusterName}/widgets/{id}',
     mock: '',

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/views/common/widget/graph_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index 1f705fa..4d170c5 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -95,7 +95,7 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, {
         dataLength = metrics.findProperty('name', match).data.length;
       } else {
         validExpression = false;
-        console.warn('Metrics not found to compute expression');
+        console.error('Metrics with name "' + match + '" not found to compute expression');
       }
     });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/app/views/main/service/info/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/summary.js b/ambari-web/app/views/main/service/info/summary.js
index eed0629..99d937d 100644
--- a/ambari-web/app/views/main/service/info/summary.js
+++ b/ambari-web/app/views/main/service/info/summary.js
@@ -543,7 +543,7 @@ App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, {
     var isMetricsSupported = svcName != 'STORM' || App.get('isStormMetricsSupported');
 
     if (App.get('supports.customizedWidgets')) {
-        this.get('controller').loadActiveWidgetLayout();
+        this.get('controller').getActiveWidgetLayout();
       if (App.get('supports.customizedWidgetLayout')) {
         this.get('controller').loadWidgetLayouts();
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/36ab07ca/ambari-web/test/controllers/main/service/info/summary_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/service/info/summary_test.js b/ambari-web/test/controllers/main/service/info/summary_test.js
index c0a3fb2..18ef3c4 100644
--- a/ambari-web/test/controllers/main/service/info/summary_test.js
+++ b/ambari-web/test/controllers/main/service/info/summary_test.js
@@ -227,7 +227,7 @@ describe('App.MainServiceInfoSummaryController', function () {
 
   });
 
-  describe("#loadActiveWidgetLayout() for Enhanced Dashboard", function () {
+  describe("#getActiveWidgetLayout() for Enhanced Dashboard", function () {
     before(function () {
       sinon.stub(App.ajax, 'send');
     });
@@ -239,12 +239,12 @@ describe('App.MainServiceInfoSummaryController', function () {
         isServiceWithEnhancedWidgets: true,
         content: Em.Object.create({serviceName: 'HDFS'})
       });
-      controller.loadActiveWidgetLayout();
-      expect(App.ajax.send.getCall(0).args[0].name).to.equal('widget.layout.get');
+      controller.getActiveWidgetLayout();
+      expect(App.ajax.send.getCall(0).args[0].name).to.equal('widgets.layouts.active.get');
     });
   });
 
-  describe("#loadActiveWidgetLayoutSuccessCallback()", function () {
+  describe("#getActiveWidgetLayoutSuccessCallback()", function () {
     beforeEach(function () {
       sinon.stub( App.widgetLayoutMapper, 'map');
       sinon.stub( App.widgetMapper, 'map');
@@ -258,7 +258,7 @@ describe('App.MainServiceInfoSummaryController', function () {
         isServiceWithEnhancedWidgets: true,
         content: Em.Object.create({serviceName: 'HDFS'})
       });
-      controller.loadActiveWidgetLayoutSuccessCallback({items:[{
+      controller.getActiveWidgetLayoutSuccessCallback({items:[{
         WidgetLayoutInfo: {}
       }]});
       expect(controller.get('isWidgetsLoaded')).to.be.true;


Mime
View raw message