You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2013/09/25 12:51:04 UTC
git commit: AMBARI-3335 UI optimization: move update of statuses into
status mapper. (atkach)
Updated Branches:
refs/heads/trunk 6075303ce -> 1f4ab2a7e
AMBARI-3335 UI optimization: move update of statuses into status mapper. (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/1f4ab2a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/1f4ab2a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/1f4ab2a7
Branch: refs/heads/trunk
Commit: 1f4ab2a7e063843425485d797c4a4dd657793197
Parents: 6075303
Author: atkach <an...@gmail.com>
Authored: Wed Sep 25 13:50:57 2013 +0300
Committer: atkach <an...@gmail.com>
Committed: Wed Sep 25 13:50:57 2013 +0300
----------------------------------------------------------------------
.../controllers/global/cluster_controller.js | 8 +-
ambari-web/app/mappers/status_mapper.js | 186 +++++++++++++++++--
ambari-web/app/models/host.js | 32 +---
ambari-web/app/models/service.js | 97 ----------
ambari-web/app/views/main/dashboard/service.js | 18 +-
5 files changed, 188 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1f4ab2a7/ambari-web/app/controllers/global/cluster_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/cluster_controller.js b/ambari-web/app/controllers/global/cluster_controller.js
index a845846..db5f737 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/ambari-web/app/controllers/global/cluster_controller.js
@@ -58,7 +58,8 @@ App.ClusterController = Em.Controller.extend({
'alerts':false,
'users':false,
'datasets':false,
- 'targetclusters':false
+ 'targetclusters':false,
+ 'status': false
}),
/**
@@ -355,7 +356,10 @@ App.ClusterController = Em.Controller.extend({
});
App.router.get('updateController').updateServiceMetric(function(){
- self.updateLoadStatus('services');
+ self.loadUpdatedStatus(function(){
+ self.updateLoadStatus('status');
+ });
+ self.updateLoadStatus('services');
}, true);
this.loadAlerts(function(){
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1f4ab2a7/ambari-web/app/mappers/status_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/status_mapper.js b/ambari-web/app/mappers/status_mapper.js
index 2f2b0fa..f49d8d4 100644
--- a/ambari-web/app/mappers/status_mapper.js
+++ b/ambari-web/app/mappers/status_mapper.js
@@ -36,6 +36,24 @@ App.statusMapper = App.QuickDataMapper.create({
if (json.items) {
var result = {};
+
+ //host_components
+ result = this.parse_host_components(json);
+
+ var hostComponents = App.HostComponent.find();
+ var servicesMap = {};
+ var hostsMap = {};
+
+ hostComponents.forEach(function(hostComponent) {
+ var item = result[hostComponent.get('id')];
+ if (item) {
+ hostComponent.set('workStatus', item.work_status);
+ hostComponent.set('haStatus', item.ha_status);
+ this.countHostComponents(hostComponent, hostsMap, hostsMap[hostComponent.get('host.id')]);
+ this.countServiceComponents(hostComponent, servicesMap, servicesMap[hostComponent.get('service.id')]);
+ }
+ }, this);
+
json.items.forEach(function (item) {
item = this.parseIt(item, this.config);
result[item.id] = item;
@@ -49,33 +67,177 @@ App.statusMapper = App.QuickDataMapper.create({
}
});
- //host_components
- result = this.parse_host_components(json);
+ this.updateHostsStatus(App.Host.find(), hostsMap);
+ this.updateServicesStatus(App.Service.find(), servicesMap);
- // console.profile("App.statusMapper.map() profile");
+ console.log('out status mapper. Took ' + (new Date().getTime() - start) + 'ms');
+ }
+ },
- var hostComponents = App.HostComponent.find();
+ /**
+ * fill serviceMap with aggregated data of hostComponents for each service
+ * @param hostComponent
+ * @param servicesMap
+ * @param service
+ */
+ countServiceComponents: function(hostComponent, servicesMap, service){
+ if (!service) {
+ service = {
+ everyStarted: true,
+ everyStartedOrMaintenance: true,
+ masterComponents: [],
+ isStarted: false,
+ isUnknown: false,
+ isStarting: false,
+ isStopped: false,
+ isHbaseActive: false,
+ serviceName: this.get('serviceName'),
+ isRunning: true,
+ runningHCs: [],
+ unknownHCs: [],
+ hdfsHealthStatus: '',
+ toolTipContent: ''
+ };
+ servicesMap[hostComponent.get('service.id')] = service;
+ }
+ if (hostComponent.get('isMaster')) {
+ service.everyStartedOrMaintenance = (service.everyStartedOrMaintenance)
+ ? ([App.HostComponentStatus.started, App.HostComponentStatus.maintenance].contains(hostComponent.get('workStatus')))
+ : false;
+ service.everyStarted = (service.everyStarted)
+ ? (hostComponent.get('workStatus') === App.HostComponentStatus.started)
+ : false;
+ service.isStarted = (!service.isStarted)
+ ? (hostComponent.get('workStatus') === App.HostComponentStatus.started)
+ : true;
+ service.isUnknown = (!service.isUnknown)
+ ? (hostComponent.get('workStatus') === App.HostComponentStatus.unknown)
+ : true;
+ service.isStarting = (!service.isStarting)
+ ? (hostComponent.get('workStatus') === App.HostComponentStatus.starting)
+ : true;
+ service.isStopped = (!service.isStopped)
+ ? (hostComponent.get('workStatus') === App.HostComponentStatus.stopped)
+ : true;
+ service.isHbaseActive = (!service.isHbaseActive)
+ ? (hostComponent.get('haStatus') === 'active')
+ : true;
- hostComponents.forEach(function(hostComponent) {
- var item = result[hostComponent.get('id')];
- if (item) {
- hostComponent.set('workStatus', item.work_status);
+ service.masterComponents.push(hostComponent);
+
+ service.toolTipContent += hostComponent.get("displayName") + " " + hostComponent.get("componentTextStatus") + "<br/>";
+ }
+
+ 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) {
+ service.isRunning = false;
+ service.runningHCs.addObject(hostComponent);
+ } else if (hostComponent.get('workStatus') == App.HostComponentStatus.unknown) {
+ service.unknownHCs.addObject(hostComponent);
+ }
+ },
+
+ /**
+ * compute service status and properties by servicesMap of hostComponents
+ * @param services
+ * @param servicesMap
+ */
+ updateServicesStatus: function(services, servicesMap){
+ services.forEach(function(_service){
+ var service = servicesMap[_service.get('id')];
+ var serviceName = _service.get('serviceName');
+ //computation of service health status
+ var isGreen = serviceName === 'HBASE' && App.supports.multipleHBaseMasters ? service.isStarted : service.everyStartedOrMaintenance;
+ if (isGreen) {
+ _service.set('healthStatus', 'green');
+ } else if (service.isUnknown) {
+ _service.set('healthStatus', 'yellow');
+ } else if (service.isStarting) {
+ _service.set('healthStatus', 'green-blinking');
+ } else if (service.isStopped) {
+ _service.set('healthStatus', 'red');
+ } else {
+ _service.set('healthStatus', 'red-blinking');
+ }
+
+ if (serviceName === 'HBASE' && App.supports.multipleHBaseMasters) {
+ if (!service.isHbaseActive) {
+ _service.set('healthStatus', 'red');
}
- });
+ }
- // console.profileEnd();
+ _service.set('isStarted', service.everyStarted);
+ _service.set('runningHostComponents', service.runningHCs);
+ _service.set('unknownHostComponents', service.unknownHCs);
+ _service.set('isStopped', service.isRunning);
+ _service.set('toolTipContent', service.toolTipContent);
+ }, this);
+ },
- console.log('out status mapper. Took ' + (new Date().getTime() - start) + 'ms');
+ /**
+ * fill hostsMap with aggregated data of hostComponents for each host
+ * @param hostComponent
+ * @param hostsMap
+ * @param host
+ */
+ countHostComponents: function(hostComponent, hostsMap, host){
+ var isMasterRunning = (hostComponent.get('isMaster') && hostComponent.get('workStatus') === App.HostComponentStatus.started);
+ var isSlaveRunning = (hostComponent.get('isSlave') && hostComponent.get('workStatus') === App.HostComponentStatus.started);
+ if (host) {
+ host.mastersRunning = host.mastersRunning + ~~isMasterRunning;
+ host.slavesRunning = host.slavesRunning + ~~isSlaveRunning;
+ host.totalMasters = host.totalMasters + ~~hostComponent.get('isMaster');
+ host.totalSlaves = host.totalSlaves + ~~hostComponent.get('isSlave');
+ } else {
+ hostsMap[hostComponent.get('host.id')] = {
+ mastersRunning: ~~isMasterRunning,
+ slavesRunning: ~~isSlaveRunning,
+ totalMasters: ~~hostComponent.get('isMaster'),
+ totalSlaves: ~~hostComponent.get('isSlave')
+ }
}
},
+ /**
+ * compute host status by hostsMap of hostComponents
+ * @param hosts
+ * @param hostsMap
+ */
+ updateHostsStatus: function(hosts, hostsMap){
+ hosts.forEach(function(_host){
+ var healthStatus = _host.get('healthStatus');
+ var host = hostsMap[_host.get('id')];
+ var status;
+ var masterComponentsRunning = (host.mastersRunning === host.totalMasters);
+ var slaveComponentsRunning = (host.slavesRunning === host.totalSlaves);
+ if (_host.get('isNotHeartBeating') || healthStatus == 'UNKNOWN') {
+ status = 'DEAD-YELLOW';
+ } else if (masterComponentsRunning && slaveComponentsRunning) {
+ status = 'LIVE';
+ } else if (host.totalMasters > 0 && !masterComponentsRunning) {
+ status = 'DEAD-RED';
+ } else {
+ status = 'DEAD-ORANGE';
+ }
+ if (status) {
+ healthStatus = status;
+ }
+ _host.set('healthClass', 'health-status-' + healthStatus);
+ }, this);
+ },
+
parse_host_components: function(json) {
var result = {};
json.items.forEach(function (item) {
item.components.forEach(function (component) {
component.host_components.forEach(function (host_component) {
host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
- result[host_component.id] = this.parseIt(host_component, this.config3);
+ result[host_component.id] = {
+ work_status: host_component.HostRoles.state,
+ ha_status: host_component.HostRoles.ha_status
+ };
}, this)
}, this)
}, this);
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1f4ab2a7/ambari-web/app/models/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host.js b/ambari-web/app/models/host.js
index fe9cb15..457133b 100644
--- a/ambari-web/app/models/host.js
+++ b/ambari-web/app/models/host.js
@@ -121,37 +121,11 @@ App.Host = DS.Model.extend({
// See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
healthClass: '',
- _updateHealthClass: function(){
- Ember.run.once(this, 'updateHealthClass');
- }.observes('healthStatus', 'hostComponents.@each.workStatus'),
-
updateHealthClass: function(){
- var healthStatus = this.get('healthStatus');
- /**
- * Do nothing until load
- */
- if (!this.get('isLoaded') || this.get('isSaving')) {
- } else {
- var status;
- var masterComponents = this.get('hostComponents').filterProperty('isMaster');
- var masterComponentsRunning = masterComponents.everyProperty('workStatus', App.HostComponentStatus.started);
- var slaveComponents = this.get('hostComponents').filterProperty('isSlave');
- var slaveComponentsRunning = slaveComponents.everyProperty('workStatus', App.HostComponentStatus.started);
- if (this.get('isNotHeartBeating') || healthStatus == 'UNKNOWN') {
- status = 'DEAD-YELLOW';
- } else if (masterComponentsRunning && slaveComponentsRunning) {
- status = 'LIVE';
- } else if (masterComponents.length > 0 && !masterComponentsRunning) {
- status = 'DEAD-RED';
- } else {
- status = 'DEAD-ORANGE';
- }
- if (status) {
- healthStatus = status;
- }
+ if(this.get('isNotHeartBeating') || this.get('healthStatus') == 'UNKNOWN'){
+ this.set('healthClass', 'health-status-DEAD-YELLOW');
}
- this.set('healthClass', 'health-status-' + healthStatus);
- },
+ }.observes('healthStatus'),
healthToolTip: function(){
var hostComponents = this.get('hostComponents').filter(function(item){
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1f4ab2a7/ambari-web/app/models/service.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/service.js b/ambari-web/app/models/service.js
index e8a0cfe..b49e91c 100644
--- a/ambari-web/app/models/service.js
+++ b/ambari-web/app/models/service.js
@@ -39,106 +39,9 @@ App.Service = DS.Model.extend({
// the computed property too many times and freezes the UI without this hack.
// See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
healthStatus: '',
-
- /**
- * Every time when changes workStatus of any component we schedule recalculating values related from them
- */
- _updateHealthStatus: (function() {
- Ember.run.once(this, 'updateStatusDependencies');
- }).observes('hostComponents.@each.workStatus'),
-
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 (isUnknown) {
- this.set('healthStatus', 'yellow');
- } else if (isStarting) {
- this.set('healthStatus', 'green-blinking');
- } else if (isStopped) {
- this.set('healthStatus', 'red');
- } else {
- this.set('healthStatus', 'red-blinking');
- }
-
- if (serviceName === 'HBASE' && App.supports.multipleHBaseMasters) {
- if (!isHbaseActive) {
- this.set('healthStatus', 'red');
- }
- }
-
- this.set('isStarted', everyStarted);
- this.set('runningHostComponents', runningHCs);
- this.set('unknownHostComponents', unknownHCs);
- this.set('isStopped', isRunning);
- },
-
isConfigurable: function () {
var configurableServices = [
"HDFS",
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1f4ab2a7/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 590bb12..69480c0 100644
--- a/ambari-web/app/views/main/dashboard/service.js
+++ b/ambari-web/app/views/main/dashboard/service.js
@@ -30,17 +30,9 @@ App.MainDashboardServiceHealthView = Em.View.extend({
rel: 'HealthTooltip',
'data-original-title': '',
- getHostComponentStatus: function(){
- var popupText = "";
- 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);
- },
-
- _updateHostComponentStatus: function(){
- Ember.run.once(this, 'getHostComponentStatus');
- }.observes('service.hostComponents.@each.workStatus'),
+ updateToolTip: function () {
+ this.set('data-original-title', this.get('service.toolTipContent'));
+ }.observes('service.toolTipContent'),
/**
* When set to true, extending classes should
@@ -94,7 +86,7 @@ App.MainDashboardServiceHealthView = Em.View.extend({
}.property('service.healthStatus'),
didInsertElement: function () {
- this.getHostComponentStatus();
+ this.updateToolTip();
$("[rel='HealthTooltip']").tooltip();
this.doBlink(); // check for blink availability
}
@@ -160,4 +152,4 @@ App.MainDashboardServiceView = Em.View.extend({
};
}.property('service')
-});
\ No newline at end of file
+});