Browse Source

AMBARI-4245 Optimize relations in model for Service and Dashboard page. (atkach)

atkach 11 years ago
parent
commit
06c971ea3c

+ 3 - 3
ambari-web/app/models/service/hbase.js

@@ -20,9 +20,9 @@ var App = require('app');
 App.HBaseService = App.Service.extend({
   version: DS.attr('string'),
   master: DS.belongsTo('App.Host'),
-  regionServers: function(){
-    return this.get('hostComponents').filterProperty('componentName', 'HBASE_REGIONSERVER').mapProperty('host');
-  }.property('hostComponents.length'),
+  regionServers: function () {
+    return this.get('hostComponents').filterProperty('componentName', 'HBASE_REGIONSERVER');
+  }.property('hostComponents.@each'),
   masterStartTime: DS.attr('number'),
   masterActiveTime: DS.attr('number'),
   averageLoad: DS.attr('number'),

+ 6 - 3
ambari-web/app/models/service/hdfs.js

@@ -24,9 +24,12 @@ App.HDFSService = App.Service.extend({
   activeNameNode: DS.belongsTo('App.Host'),
   standbyNameNode: DS.belongsTo('App.Host'),
   standbyNameNode2: DS.belongsTo('App.Host'),
-  dataNodes: function(){
-    return this.get('hostComponents').filterProperty('componentName', 'DATANODE').mapProperty('host');
-  }.property('hostComponents.length'),
+  dataNodes: function () {
+    return this.get('hostComponents').filterProperty('componentName', 'DATANODE');
+  }.property('hostComponents.@each'),
+  journalNodes: function () {
+    return this.get('hostComponents').filterProperty('componentName', 'JOURNALNODE');
+  }.property('hostComponents.@each'),
   nameNodeStartTime: DS.attr('number'),
   jvmMemoryHeapUsed: DS.attr('number'),
   jvmMemoryHeapMax: DS.attr('number'),

+ 2 - 2
ambari-web/app/models/service/mapreduce.js

@@ -22,8 +22,8 @@ App.MapReduceService = App.Service.extend({
   jobHistoryServer: DS.belongsTo('App.Host'),
   jobTracker: DS.belongsTo('App.Host'),
   taskTrackers: function () {
-    return this.get('hostComponents').filterProperty('componentName', 'TASKTRACKER').mapProperty('host');
-  }.property('hostComponents.length'),
+    return this.get('hostComponents').filterProperty('componentName', 'TASKTRACKER');
+  }.property('hostComponents.@each'),
   jobTrackerStartTime: DS.attr('number'),
   jobTrackerHeapUsed: DS.attr('number'),
   jobTrackerHeapMax: DS.attr('number'),

+ 3 - 3
ambari-web/app/models/service/yarn.js

@@ -21,9 +21,9 @@ var objectUtils = require('utils/object_utils');
 App.YARNService = App.Service.extend({
   version: DS.attr('string'),
   resourceManagerNode: DS.belongsTo('App.Host'),
-  nodeManagerNodes: function(){
-    return this.get('hostComponents').filterProperty('componentName', 'NODEMANAGER').mapProperty('host');
-  }.property('hostComponents.length'),
+  nodeManagerNodes: function () {
+    return this.get('hostComponents').filterProperty('componentName', 'NODEMANAGER');
+  }.property('hostComponents.@each'),
   nodeManagerLiveNodes: DS.hasMany('App.Host'),
   nodeManagersCountActive: DS.attr('number'),
   nodeManagersCountUnhealthy: DS.attr('number'),

+ 6 - 6
ambari-web/app/views/main/dashboard/service/hbase.js

@@ -27,7 +27,7 @@ App.MainDashboardServiceHbaseView = App.MainDashboardServiceView.extend({
    */
   masters: function () {
     return this.get('service.hostComponents').filterProperty('isMaster', true);
-  }.property('service.hostComponents.@each'),
+  }.property('service.hostComponents.length'),
   /**
    * Passive master components
    */
@@ -40,8 +40,8 @@ App.MainDashboardServiceHbaseView = App.MainDashboardServiceView.extend({
 
 
   liveRegionServers: function () {
-    return App.HostComponent.find().filterProperty('componentName', 'HBASE_REGIONSERVER').filterProperty("workStatus","STARTED");
-  }.property('service.hostComponents.@each'),
+    return this.get('service.regionServers').filterProperty("workStatus", "STARTED");
+  }.property('service.regionServers.@each.workStatus'),
 
   regionServesText: function () {
     if (this.get('service.regionServers.length') == 0) {
@@ -55,8 +55,8 @@ App.MainDashboardServiceHbaseView = App.MainDashboardServiceView.extend({
 
   regionServersLiveTextView: App.ComponentLiveTextView.extend({
     liveComponents: function() {
-      return App.HostComponent.find().filterProperty('componentName', 'HBASE_REGIONSERVER').filterProperty("workStatus","STARTED").get('length');
-    }.property("service.hostComponents.@each"),
+      return this.get('service.regionServers').filterProperty("workStatus","STARTED").get('length');
+    }.property('service.regionServers.@each.workStatus'),
     totalComponents: function() {
       return this.get("service.regionServers.length");
     }.property("service.regionServers.length")
@@ -139,7 +139,7 @@ App.MainDashboardServiceHbaseView = App.MainDashboardServiceView.extend({
   }.property("service.masterActiveTime"),
 
   regionServerComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'HBASE_REGIONSERVER');
+    return this.get('service.regionServers').objectAt(0);
   }.property()
 
 });

+ 20 - 33
ambari-web/app/views/main/dashboard/service/hdfs.js

@@ -44,49 +44,36 @@ App.MainDashboardServiceHdfsView = App.MainDashboardServiceView.extend({
         return comp.get('isMaster') && comp.get('componentName') !== 'JOURNALNODE';
       });
       return masters;
-    }.property('service')
+    }.property('parentView.service.hostComponents')
   }),
 
-  dataNodesLive: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'DATANODE').filterProperty("workStatus","STARTED");
-  }.property('service.hostComponents.@each'),
-  dataNodesDead: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'DATANODE').filterProperty("workStatus","INSTALLED");
-  }.property('service.hostComponents.@each'),
-
-  dataNodeHostText: function () {
-    if (this.get("service.dataNodes").length == 0) {
-      return '';
-    } else if (this.get("service.dataNodes").length > 1) {
-      return Em.I18n.t('services.service.summary.viewHosts');
-    } else {
-      return Em.I18n.t('services.service.summary.viewHost');
-    }
-  }.property("service"),
+  dataNodesLive: function () {
+    return this.get('service.dataNodes').filterProperty("workStatus", "STARTED");
+  }.property('service.dataNodes.@each.workStatus'),
+  dataNodesDead: function () {
+    return this.get('service.dataNodes').filterProperty("workStatus", "INSTALLED");
+  }.property('service.dataNodes.@each.workStatus'),
 
   showJournalNodes: function () {
-    return App.HostComponent.find().filterProperty('componentName', 'JOURNALNODE').get('length') > 0;
-  }.property('service.hostComponents.@each'),
+    return this.get('service.journalNodes.length') > 0;
+  }.property('service.journalNodes.length'),
 
   dataNodesLiveTextView: App.ComponentLiveTextView.extend({
-    liveComponents: function() {
-      return App.HostComponent.find().filterProperty('componentName', 'DATANODE').filterProperty("workStatus","STARTED").get("length");
-    }.property("service.hostComponents.@each"),
+    liveComponents: function () {
+      return this.get('service.dataNodes').filterProperty("workStatus", "STARTED").get("length");
+    }.property("service.dataNodes.@each.workStatus"),
     totalComponents: function() {
       return this.get("service.dataNodes.length");
     }.property("service.dataNodes.length")
   }),
 
   journalNodesLiveTextView: App.ComponentLiveTextView.extend({
-    allJournalNodes: function () {
-      return App.HostComponent.find().filterProperty('componentName', 'JOURNALNODE')
-    }.property('service.hostComponents.@each'),
-    liveComponents: function() {
-      return this.get('allJournalNodes').filterProperty("workStatus","STARTED").get("length");
-    }.property("allJournalNodes"),
-    totalComponents: function() {
-      return this.get('allJournalNodes').get("length");
-    }.property("allJournalNodes")
+    liveComponents: function () {
+      return this.get('service.journalNodes').filterProperty("workStatus", "STARTED").get("length");
+    }.property("service.journalNodes.@each.workStatus"),
+    totalComponents: function () {
+      return this.get('service.journalNodes.length');
+    }.property("service.journalNodes.length")
   }),
 
   dfsTotalBlocks: function(){
@@ -164,11 +151,11 @@ App.MainDashboardServiceHdfsView = App.MainDashboardServiceView.extend({
   }.property('service.capacityUsed', 'service.capacityTotal'),
 
   dataNodeComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'DATANODE');
+    return this.get('service.dataNodes').objectAt(0);
   }.property(),
 
   journalNodeComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'JOURNALNODE');
+    return this.get('service.journalNodes').objectAt(0);
   }.property(),
 
   safeModeStatus: function () {

+ 6 - 6
ambari-web/app/views/main/dashboard/service/mapreduce.js

@@ -70,16 +70,16 @@ App.MainDashboardServiceMapreduceView = App.MainDashboardServiceView.extend({
 
   trackersSummary: function () {
     var svc = this.get('service');
-    var liveCount = App.HostComponent.find().filterProperty('componentName', 'TASKTRACKER').filterProperty("workStatus","STARTED").length;
+    var liveCount = svc.get('taskTrackers').filterProperty("workStatus", "STARTED").length;
     var totalCount = svc.get('taskTrackers').get('length');
     var template = this.t('dashboard.services.mapreduce.trackersSummary');
     return template.format(liveCount, totalCount);
-  }.property('service.aliveTrackers.length', 'service.taskTrackers.length'),
+  }.property('service.aliveTrackers.length', 'service.taskTrackers.@each.workStatus'),
 
   trackersLiveTextView: App.ComponentLiveTextView.extend({
-    liveComponents: function() {
-      return App.HostComponent.find().filterProperty('componentName', 'TASKTRACKER').filterProperty("workStatus","STARTED").get("length");
-    }.property("service.hostComponents.@each", "service.aliveTrackers.length"),
+    liveComponents: function () {
+      return this.get('service.taskTrackers').filterProperty("workStatus", "STARTED").get("length");
+    }.property("service.taskTrackers.@each.workStatus"),
     totalComponents: function() {
       return this.get("service.taskTrackers.length");
     }.property('service.taskTrackers.length')
@@ -135,6 +135,6 @@ App.MainDashboardServiceMapreduceView = App.MainDashboardServiceView.extend({
   }.property('service.mapSlots', 'service.reduceSlots', 'service.aliveTrackers'),
 
   taskTrackerComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'TASKTRACKER');
+    return this.get('service.taskTrackers').objectAt(0);
   }.property()
 });

+ 9 - 13
ambari-web/app/views/main/dashboard/service/yarn.js

@@ -41,11 +41,11 @@ App.MainDashboardServiceYARNView = App.MainDashboardServiceView.extend({
   }.property('service.nodeManagerNodes'),
   
   nodeManagerComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'NODEMANAGER');
-  }.property('service.hostComponents.@each'),
+    return this.get('service.nodeManagerNodes').objectAt(0);
+  }.property(),
   
   yarnClientComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'YARN_CLIENT');
+    return this.get('service.hostComponents').findProperty('componentName', 'YARN_CLIENT');
   }.property(),
 
   hasManyYarnClients: function () {
@@ -65,10 +65,6 @@ App.MainDashboardServiceYARNView = App.MainDashboardServiceView.extend({
     return this.t('services.service.summary.notRunning');
   }.property("service.resourceManagerStartTime"),
 
-  nodeManagersLive: function () {
-    return App.HostComponent.find().filterProperty('componentName', 'NODEMANAGER').filterProperty("workStatus","STARTED");
-  }.property('service.hostComponents.@each'),
-
   nodeManagerText: function () {
     if(!this.get("nodeManagerComponent") || this.get("nodeManagerComponent.length") == 0){
       return '';
@@ -80,12 +76,12 @@ App.MainDashboardServiceYARNView = App.MainDashboardServiceView.extend({
   }.property("nodeManagerComponent"),
 
   nodeManagersLiveTextView: App.ComponentLiveTextView.extend({
-    liveComponents: function() {
-      return App.HostComponent.find().filterProperty('componentName', 'NODEMANAGER').filterProperty("workStatus","STARTED").get("length");
-    }.property("service.hostComponents.@each"),
-    totalComponents: function() {
-      return App.HostComponent.find().filterProperty('componentName', 'NODEMANAGER').get("length");
-    }.property("service.hostComponents.@each")
+    liveComponents: function () {
+      return this.get('service.nodeManagerNodes').filterProperty("workStatus", "STARTED").get("length");
+    }.property("service.nodeManagerNodes.@each.workStatus"),
+    totalComponents: function () {
+      return this.get('service.nodeManagerNodes.length');
+    }.property("service.nodeManagerNodes.length")
   }),
 
   nodeManagersStatus: function () {

+ 6 - 6
ambari-web/app/views/main/dashboard/widgets/datanode_live.js

@@ -41,12 +41,12 @@ App.DataNodeUpView = App.TextDashboardWidgetView.extend({
   thresh2: 70,
   maxValue: 100,
 
-  dataNodesLive: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'DATANODE').filterProperty("workStatus","STARTED");
-  }.property('model.hostComponents.@each'),
-  dataNodesDead: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'DATANODE').filterProperty("workStatus","INSTALLED");
-  }.property('model.hostComponents.@each'),
+  dataNodesLive: function () {
+    return this.get('model.dataNodes').filterProperty("workStatus", "STARTED");
+  }.property('model.dataNodes.@each.workStatus'),
+  dataNodesDead: function () {
+    return this.get('model.dataNodes').filterProperty("workStatus", "INSTALLED");
+  }.property('model.dataNodes.@each.workStatus'),
 
   data: function () {
     if ( !this.get('model.dataNodes.length')) {

+ 3 - 3
ambari-web/app/views/main/dashboard/widgets/node_managers_live.js

@@ -46,9 +46,9 @@ App.NodeManagersLiveView = App.TextDashboardWidgetView.extend({
   thresh2: 70,
   maxValue: 100,
 
-  nodeManagersLive: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'NODEMANAGER').filterProperty("workStatus","STARTED");
-  }.property('model.hostComponents.@each'),
+  nodeManagersLive: function () {
+    return this.get('model.nodeManagerNodes').filterProperty("workStatus", "STARTED");
+  }.property('model.nodeManagerNodes.@each.workStatus'),
 
   data: function () {
     var nodeManagers = this.get('model.nodeManagerNodes.length');

+ 3 - 3
ambari-web/app/views/main/dashboard/widgets/tasktracker_live.js

@@ -39,9 +39,9 @@ App.TaskTrackerUpView = App.TextDashboardWidgetView.extend({
   thresh2: 70,
   maxValue: 100,
 
-  taskTrackersLive: function(){
-    return App.HostComponent.find().filterProperty('componentName', 'TASKTRACKER').filterProperty("workStatus","STARTED");
-  }.property('model.hostComponents.@each'),
+  taskTrackersLive: function () {
+    return this.get('model.taskTrackers').filterProperty("workStatus", "STARTED");
+  }.property('model.taskTrackers.@each.workStatus'),
 
   data: function () {
     if (!this.get('model.taskTrackers.length')) {

+ 1 - 38
ambari-web/app/views/main/service/info/summary.js

@@ -241,44 +241,6 @@ App.MainServiceInfoSummaryView = Em.View.extend({
     }
   },
 
-  /**
-   * Array of the hostComponents for service
-   */
-  components: [],
-
-  /**
-   * Copy hostComponents from controller to view to avoid flickering Summary block while data is updating in the controller
-   * rand - just marker in the Service model for determining that Service was updated (value changes in the service_mapper)
-   */
-  hostComponentsUpd: function() {
-      var components = [];
-      this.get('controller.content.hostComponents').forEach(function(component) {
-        var obj = {};
-        for(var prop in component){
-          if( component.hasOwnProperty(prop)
-            && prop.indexOf('__ember') < 0
-            && prop.indexOf('_super') < 0
-            && Ember.typeOf(component.get(prop)) !== 'function'
-            ) {
-            obj[prop] = component.get(prop);
-          }
-        }
-        obj.displayName = component.get('displayName'); // this is computed property and wasn't copied in the top block of code
-        // suppressing MySQL server from being displayed, because Ambari always installs MySQL server no matter what
-        // database type is selected, and shows an incorrect link in the summary to point to the host that's hosting
-        // the MySQL server
-        if (component.get('componentName') !== 'MYSQL_SERVER') {
-          components.push(obj);
-        }
-      });
-      this.set('components', components);
-
-  },
-  
-  _hostComponentsUpd: function() {
-    Ember.run.once(this, 'hostComponentsUpd');
-  }.observes('controller.content.rand', 'controller.content.hostComponents.@each.isMaster', 'controller.content.hostComponents.@each.host'),
-  
   /**
    * Wrapper for displayName. used to render correct display name for mysql_server
    */
@@ -456,6 +418,7 @@ App.MainServiceInfoSummaryView = Em.View.extend({
   }.property('App.router.clusterController.gangliaUrl', 'service.serviceName'),
 
   didInsertElement:function () {
+    //TODO delegate style calculation to css
     // We have to make the height of the Alerts section
     // match the height of the Summary section.
     var summaryTable = document.getElementById('summary-info');