Updated Branches: refs/heads/trunk 7af440286 -> 41c2d3ec8
AMBARI-3246 Cluster services/status mappers take 5 times the amount of time on Dashboard/service pages. (atkach) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/41c2d3ec Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/41c2d3ec Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/41c2d3ec Branch: refs/heads/trunk Commit: 41c2d3ec8f0950d5958db8c9e0aa280308b00b0e Parents: 7af4402 Author: atkach <[email protected]> Authored: Mon Sep 16 14:48:23 2013 +0300 Committer: atkach <[email protected]> Committed: Mon Sep 16 14:48:23 2013 +0300 ---------------------------------------------------------------------- ambari-web/app/mappers/service_mapper.js | 22 ++-- ambari-web/app/models/service.js | 137 ++++++++++++-------- ambari-web/app/views/main/dashboard/service.js | 6 +- 3 files changed, 98 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/41c2d3ec/ambari-web/app/mappers/service_mapper.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mappers/service_mapper.js b/ambari-web/app/mappers/service_mapper.js index cacc627..f85e10d 100644 --- a/ambari-web/app/mappers/service_mapper.js +++ b/ambari-web/app/mappers/service_mapper.js @@ -240,6 +240,7 @@ App.servicesMapper = App.QuickDataMapper.create({ // Host components result = []; + var hostComponentsMap = {}; var hostComponentToActualConfigsMap = {}; json.items.forEach(function(item){ item.components.forEach(function(component){ @@ -248,22 +249,20 @@ App.servicesMapper = App.QuickDataMapper.create({ hostComponentToActualConfigsMap[host_component.id] = host_component.HostRoles.actual_configs; var comp = this.parseIt(host_component, this.config3); comp.service_id = service; + this.calculateState(comp); result.push(comp); + hostComponentsMap[comp.id] = comp; }, this) }, this) }, this); - result.forEach(function(hcJson){ - this.calculateState(hcJson); - }, this); var oldHostComponents = App.HostComponent.find(); var item; var currentHCWithComponentNames = {}; var currentComponentNameHostNames = {}; - for ( var i = 0; i < oldHostComponents.content.length; i++) { - item = oldHostComponents.objectAt(i); - if (item && !result.findProperty('id', item.get('id'))) { + oldHostComponents.forEach(function (item) { + if (item && !hostComponentsMap[item.get('id')]) { item.deleteRecord(); } else { var componentName = item.get('componentName'); @@ -275,14 +274,15 @@ App.servicesMapper = App.QuickDataMapper.create({ } currentComponentNameHostNames[componentName].pushObject(item.get('host.hostName')); } - } + }, this); + result.forEach(function (item) { if (currentHCWithComponentNames[item.id] != null && !currentComponentNameHostNames[item.component_name].contains(item.host_id)) { item.id = (new Date).getTime(); } }); - + App.store.loadMany(this.get('model3'), result); for(var hostComponentId in hostComponentToActualConfigsMap){ var hostComponentObj = App.HostComponent.find(hostComponentId); @@ -290,11 +290,11 @@ App.servicesMapper = App.QuickDataMapper.create({ // Create actual_configs for(var site in hostComponentToActualConfigsMap[hostComponentId]){ var tag = hostComponentToActualConfigsMap[hostComponentId][site].tag; - var configObj = App.ConfigSiteTag.create({ + var configObj = { site: site, tag: tag, hostOverrides: {} - }); + }; var overrides = hostComponentToActualConfigsMap[hostComponentId][site].host_overrides; if(overrides!=null){ var hostOverridesArray = {}; @@ -303,7 +303,7 @@ App.servicesMapper = App.QuickDataMapper.create({ var tag = override.tag; hostOverridesArray[hostname] = tag; }); - configObj.set('hostOverrides', hostOverridesArray); + configObj.hostOverrides = hostOverridesArray; } actualConfigs.push(configObj); } http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/41c2d3ec/ambari-web/app/models/service.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/service.js b/ambari-web/app/models/service.js index dd0ceac..5730fb1 100644 --- a/ambari-web/app/models/service.js +++ b/ambari-web/app/models/service.js @@ -40,35 +40,100 @@ App.Service = DS.Model.extend({ // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties healthStatus: '', - updateHealthStatus: function () { - // console.log('model:service.healthStatus ' + this.get('serviceName')); - var components = this.get('hostComponents').filterProperty('isMaster', true); - var isGreen = this.get('serviceName') === 'HBASE' && App.supports.multipleHBaseMasters ? - components.someProperty('workStatus', App.HostComponentStatus.started) : - components.every(function (_component) { - return ([App.HostComponentStatus.started, App.HostComponentStatus.maintenance].contains(_component.get('workStatus'))); - }, this); + /** + * Every time when changes workStatus of any component we schedule recalculating values related from them + */ + _updateHealthStatus: (function() { + Ember.run.once(this, 'updateStatusDependencies'); + }).observes('[email protected]'), + + isStopped: false, + isStarted: false, + + /** + * compute service properties which depend on host components status + * service computed properties: + * healthStatus + * isStarted + * runningHostComponents + * unknownHostComponents + * isStopped + */ + updateStatusDependencies: function () { + var everyStarted = true, + everyStartedOrMaintenance = true, + masterComponents = [], + isStarted = false, + isUnknown = false, + isStarting = false, + isStopped = false, + isHbaseActive = false, + serviceName = this.get('serviceName'), + isRunning = true, + runningHCs = [], + unknownHCs = [], + hdfsHealthStatus; + + //look through all components to find out common statuses + this.get('hostComponents').forEach(function (_hostComponent) { + if (_hostComponent.get('isMaster')) { + everyStartedOrMaintenance = (everyStartedOrMaintenance) + ? ([App.HostComponentStatus.started, App.HostComponentStatus.maintenance].contains(_hostComponent.get('workStatus'))) + : false; + everyStarted = (everyStarted) + ? (_hostComponent.get('workStatus') === App.HostComponentStatus.started) + : false; + isStarted = (!isStarted) + ? (_hostComponent.get('workStatus') === App.HostComponentStatus.started) + : true; + isUnknown = (!isUnknown) + ? (_hostComponent.get('workStatus') === App.HostComponentStatus.unknown) + : true; + isStarting = (!isStarting) + ? (_hostComponent.get('workStatus') === App.HostComponentStatus.starting) + : true; + isStopped = (!isStopped) + ? (_hostComponent.get('workStatus') === App.HostComponentStatus.stopped) + : true; + isHbaseActive = (!isHbaseActive) + ? (_hostComponent.get('haStatus') === 'active') + : true; + + masterComponents.push(_hostComponent); + } + + if (_hostComponent.get('workStatus') !== App.HostComponentStatus.stopped && + _hostComponent.get('workStatus') !== App.HostComponentStatus.install_failed && + _hostComponent.get('workStatus') !== App.HostComponentStatus.unknown && + _hostComponent.get('workStatus') !== App.HostComponentStatus.maintenance) { + isRunning = false; + runningHCs.addObject(_hostComponent); + } else if (_hostComponent.get('workStatus') == App.HostComponentStatus.unknown) { + unknownHCs.addObject(_hostComponent); + } + }, this); + //computation of service health status + var isGreen = serviceName === 'HBASE' && App.supports.multipleHBaseMasters ? isStarted : everyStartedOrMaintenance; if (isGreen) { this.set('healthStatus', 'green'); - } else if (components.someProperty('workStatus', App.HostComponentStatus.unknown)) { + } else if (isUnknown) { this.set('healthStatus', 'yellow'); - } else if (components.someProperty('workStatus', App.HostComponentStatus.starting)) { + } else if (isStarting) { this.set('healthStatus', 'green-blinking'); - } else if (components.someProperty('workStatus', App.HostComponentStatus.stopped)) { + } else if (isStopped) { this.set('healthStatus', 'red'); } else { this.set('healthStatus', 'red-blinking'); } - if (this.get('serviceName') === 'HBASE' && App.supports.multipleHBaseMasters) { - var active = this.get('hostComponents').findProperty('haStatus', 'active'); - if (!active) { + if (serviceName === 'HBASE' && App.supports.multipleHBaseMasters) { + if (!isHbaseActive) { this.set('healthStatus', 'red'); } } - if (isGreen && this.get('serviceName') === 'HDFS' && components.length == 5) { // enabled HA + if (isGreen && serviceName === 'HDFS' && masterComponents.length == 5) { // enabled HA var activeNN = this.get('activeNameNode'); var nameNode = this.get('nameNode'); @@ -79,49 +144,11 @@ App.Service = DS.Model.extend({ } this.set('healthStatus', hdfsHealthStatus); } - }, - - /** - * Every time when changes workStatus of any component we schedule recalculating values related from them - */ - _updateHealthStatus: (function() { - Ember.run.once(this, 'updateHealthStatus'); - Ember.run.once(this, 'updateIsStopped'); - Ember.run.once(this, 'updateIsStarted'); - }).observes('[email protected]'), - isStopped: false, - isStarted: false, - - updateIsStopped: function () { - var components = this.get('hostComponents'); - var flag = true; - var runningHCs = []; - var unknownHCs = []; - - components.forEach(function (_component) { - if ( - _component.get('workStatus') !== App.HostComponentStatus.stopped && - _component.get('workStatus') !== App.HostComponentStatus.install_failed && - _component.get('workStatus') !== App.HostComponentStatus.unknown && - _component.get('workStatus') !== App.HostComponentStatus.maintenance - ) { - flag = false; - runningHCs.addObject(_component); - } else if (_component.get('workStatus') == App.HostComponentStatus.unknown) { - unknownHCs.addObject(_component); - } - }, this); + this.set('isStarted', everyStarted); this.set('runningHostComponents', runningHCs); this.set('unknownHostComponents', unknownHCs); - this.set('isStopped', flag); - }, - - updateIsStarted: function () { - var components = this.get('hostComponents').filterProperty('isMaster', true); - this.set('isStarted', - components.everyProperty('workStatus', App.HostComponentStatus.started) - ); + this.set('isStopped', isRunning); }, isConfigurable: function () { http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/41c2d3ec/ambari-web/app/views/main/dashboard/service.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/dashboard/service.js b/ambari-web/app/views/main/dashboard/service.js index 28d20aa..590bb12 100644 --- a/ambari-web/app/views/main/dashboard/service.js +++ b/ambari-web/app/views/main/dashboard/service.js @@ -35,7 +35,11 @@ App.MainDashboardServiceHealthView = Em.View.extend({ this.get("service").get("hostComponents").filterProperty('isMaster', true).forEach(function(item){ popupText += item.get("displayName") + " " + item.get("componentTextStatus") + "<br/>"; }); - this.set('data-original-title',popupText); + this.set('data-original-title', popupText); + }, + + _updateHostComponentStatus: function(){ + Ember.run.once(this, 'getHostComponentStatus'); }.observes('[email protected]'), /**
