Repository: ambari Updated Branches: refs/heads/trunk 954a70409 -> 930c4a439
AMBARI-6032 Remove minor dependencies with Host and HostComponent models. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/930c4a43 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/930c4a43 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/930c4a43 Branch: refs/heads/trunk Commit: 930c4a4394bbb42201a550e0dbbb309544d9e82c Parents: 954a704 Author: atkach <[email protected]> Authored: Thu Jun 5 18:08:59 2014 +0300 Committer: atkach <[email protected]> Committed: Thu Jun 5 18:08:59 2014 +0300 ---------------------------------------------------------------------- .../controllers/global/cluster_controller.js | 6 ++ ambari-web/app/controllers/main/host.js | 56 +++++++++++++++- .../app/mappers/components_state_mapper.js | 3 + ambari-web/app/models/service/flume.js | 3 +- ambari-web/app/models/service_config.js | 1 + .../templates/main/admin/rollbackHA/step1.hbs | 55 +++++++++------- ambari-web/app/utils/component.js | 35 ---------- .../views/main/admin/rollbackHA/step1_view.js | 34 ++++++++-- ambari-web/app/views/main/host.js | 69 +++----------------- .../main/host/details/host_component_view.js | 2 +- .../app/views/main/service/info/summary.js | 27 +------- ambari-web/app/views/main/service/item.js | 2 +- .../app/views/main/service/services/flume.js | 7 +- ambari-web/test/utils/component_test.js | 25 ------- 14 files changed, 143 insertions(+), 182 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/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 0524195..8f609d4 100644 --- a/ambari-web/app/controllers/global/cluster_controller.js +++ b/ambari-web/app/controllers/global/cluster_controller.js @@ -293,6 +293,12 @@ App.ClusterController = Em.Controller.extend({ var usersUrl = App.testMode ? '/data/users/users.json' : App.apiPrefix + '/users/?fields=*'; var racksUrl = "/data/racks/racks.json"; + + var hostsController = App.router.get('mainHostController'); + hostsController.set('isCountersUpdating', true); + hostsController.updateStatusCounters(); + hostsController.set('isCountersUpdating', false); + App.HttpClient.get(racksUrl, App.racksMapper, { complete: function (jqXHR, textStatus) { self.updateLoadStatus('racks'); http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/controllers/main/host.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host.js b/ambari-web/app/controllers/main/host.js index d95f251..3e0d4f6 100644 --- a/ambari-web/app/controllers/main/host.js +++ b/ambari-web/app/controllers/main/host.js @@ -28,13 +28,19 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, { clearFilters: null, filteredCount: 0, + /** + * flag responsible for updating status counters of hosts + */ + isCountersUpdating: false, + + hostsCountMap: {}, /** * Components which will be shown in component filter * @returns {Array} */ componentsForFilter: function () { - var installedComponents = componentHelper.getInstalledComponents(); + var installedComponents = App.StackServiceComponent.find().toArray(); installedComponents.setEach('checkedForHostFilter', false); return installedComponents; }.property('App.router.clusterController.isLoaded'), @@ -252,6 +258,54 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, { }, /** + * update status counters of hosts + */ + updateStatusCounters: function () { + var self = this; + + if (this.get('isCountersUpdating')) { + App.ajax.send({ + name: 'host.status.counters', + sender: this, + data: {}, + success: 'updateStatusCountersSuccessCallback', + error: 'updateStatusCountersErrorCallback' + }); + + setTimeout(function () { + self.updateStatusCounters(); + }, App.get('componentsUpdateInterval')); + } + }, + + /** + * success callback on <code>updateStatusCounters()</code> + * map counters' value to categories + * @param data + */ + updateStatusCountersSuccessCallback: function (data) { + var hostsCountMap = { + 'HEALTHY': data.Clusters.health_report['Host/host_status/HEALTHY'], + 'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'], + 'ALERT': data.Clusters.health_report['Host/host_status/ALERT'], + 'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'], + 'health-status-WITH-ALERTS': (data.alerts) ? data.alerts.summary.CRITICAL + data.alerts.summary.WARNING : 0, + 'health-status-RESTART': data.Clusters.health_report['Host/stale_config'], + 'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'], + 'TOTAL': data.Clusters.total_hosts + }; + + this.set('hostsCountMap', hostsCountMap); + }, + + /** + * success callback on <code>updateStatusCounters()</code> + */ + updateStatusCountersErrorCallback: function() { + console.warn('ERROR: updateStatusCounters failed') + }, + + /** * Return value without predicate * @param {String} value * @return {String} http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/mappers/components_state_mapper.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mappers/components_state_mapper.js b/ambari-web/app/mappers/components_state_mapper.js index 7561d3a..0a63a28 100644 --- a/ambari-web/app/mappers/components_state_mapper.js +++ b/ambari-web/app/mappers/components_state_mapper.js @@ -86,6 +86,9 @@ App.componentsStateMapper = App.QuickDataMapper.create({ }, 'HDFS_CLIENT': { installed_clients: 'INSTALLED_PATH' + }, + 'FLUME_HANDLER': { + flume_handlers_total: 'TOTAL_PATH' } }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/models/service/flume.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/service/flume.js b/ambari-web/app/models/service/flume.js index 392a9b3..61dc7eb 100644 --- a/ambari-web/app/models/service/flume.js +++ b/ambari-web/app/models/service/flume.js @@ -19,7 +19,8 @@ var App = require('app'); App.FlumeService = App.Service.extend({ version: DS.attr('string'), - agents: DS.hasMany('App.FlumeAgent') + agents: DS.hasMany('App.FlumeAgent'), + flumeHandlersTotal: DS.attr('number') }); App.FlumeAgent = DS.Model.extend({ http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/models/service_config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/service_config.js b/ambari-web/app/models/service_config.js index fe42d10..dfc480e 100644 --- a/ambari-web/app/models/service_config.js +++ b/ambari-web/app/models/service_config.js @@ -493,6 +493,7 @@ App.ServiceConfigProperty = Ember.Object.extend({ var masterComponentHostsInDB = localDB.masterComponentHosts; var slaveComponentHostsInDB = localDB.slaveComponentHosts; var hostsInfo = localDB.hosts; // which we are setting in installerController in step3. + //all hosts should be in local storage without using App.Host model App.Host.find().forEach(function(item){ if(!hostsInfo[item.get('id')]){ hostsInfo[item.get('id')] = { http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/templates/main/admin/rollbackHA/step1.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/admin/rollbackHA/step1.hbs b/ambari-web/app/templates/main/admin/rollbackHA/step1.hbs index 898105d..7e92a5c 100644 --- a/ambari-web/app/templates/main/admin/rollbackHA/step1.hbs +++ b/ambari-web/app/templates/main/admin/rollbackHA/step1.hbs @@ -16,28 +16,35 @@ * limitations under the License. }} <div> - <h2>{{t admin.rollbackHighAvailability.wizard.step1.header}}</h2> - <div class="alert alert-info"> - <p> - Select Additional NameNode host: - {{view Ember.Select - contentBinding="view.addNNHosts" - valueBinding="view.selectedAddNNHost" - }} - </p> - <div class="code-snippet">Tip: Suggested host <b>{{view.tipAddNNHost}}</b></div> - </div> - <div class="alert alert-info"> - <p> - Select Secondary NameNode host: - {{view Ember.Select - contentBinding="view.sNNHosts" - valueBinding="view.selectedSNNHost" - }} - </p> - <div class="code-snippet">Tip: Suggested host <b>{{view.tipSNNHost}}</b></div> - </div> - <div class="btn-area"> - <a {{bindAttr class=":btn controller.isNameServiceIdValid::disabled :btn-success :pull-right"}} {{action done target="view"}}>{{t common.next}} →</a> - </div> + {{#if view.isLoaded}} + <h2>{{t admin.rollbackHighAvailability.wizard.step1.header}}</h2> + + <div class="alert alert-info"> + <p> + Select Additional NameNode host: + {{view Ember.Select + contentBinding="view.addNNHosts" + valueBinding="view.selectedAddNNHost" + }} + </p> + + <div class="code-snippet">Tip: Suggested host <b>{{view.tipAddNNHost}}</b></div> + </div> + <div class="alert alert-info"> + <p> + Select Secondary NameNode host: + {{view Ember.Select + contentBinding="view.sNNHosts" + valueBinding="view.selectedSNNHost" + }} + </p> + + <div class="code-snippet">Tip: Suggested host <b>{{view.tipSNNHost}}</b></div> + </div> + <div class="btn-area"> + <a {{bindAttr class=":btn controller.isNameServiceIdValid::disabled :btn-success :pull-right"}} {{action done target="view"}}>{{t common.next}} →</a> + </div> + {{else}} + <div class="spinner"></div> + {{/if}} </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/utils/component.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/component.js b/ambari-web/app/utils/component.js index e7e8540..b374fe2 100644 --- a/ambari-web/app/utils/component.js +++ b/ambari-web/app/utils/component.js @@ -23,41 +23,6 @@ var App = require('app'); module.exports = { - - /** - * Return list of installed components. Syntax is: - * - * [{ - * id : 'DATANODE', - * displayName : 'DataNode', - * isMaster : true, - * isSlave : false, - * isClient : false - * }] - * - * @method getInstalledComponents - * @return {object[]} - */ - getInstalledComponents : function(){ - var components = App.HostComponent.find(); - var names = components.mapProperty('componentName').uniq(); - var result = []; - - names.forEach(function(componentName){ - var component = components.findProperty('componentName', componentName); - result.push(Ember.Object.create({ - id: componentName, - isMaster: component.get('isMaster'), - isSlave: component.get('isSlave'), - isClient: component.get('isClient'), - displayName: component.get('displayName'), - serviceName: component.get('service.id') - })); - }); - - return result; - }, - /** * Format and load info about components to StackServiceComponent model. * http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/views/main/admin/rollbackHA/step1_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/admin/rollbackHA/step1_view.js b/ambari-web/app/views/main/admin/rollbackHA/step1_view.js index 69a3d33..7021085 100644 --- a/ambari-web/app/views/main/admin/rollbackHA/step1_view.js +++ b/ambari-web/app/views/main/admin/rollbackHA/step1_view.js @@ -28,20 +28,40 @@ App.RollbackHighAvailabilityWizardStep1View = Em.View.extend({ selectedSNNHost: null, selectedAddNNHost: null, - didInsertElement: function() { - var addNNHosts = App.HostComponent.find().filterProperty('componentName','NAMENODE'); - this.secondaryNNHosts = []; + isLoaded: false, + + loadHostsName: function () { + App.ajax.send({ + name: 'hosts.all', + sender: this, + data: {}, + success: 'loadHostsNameSuccessCallback', + error: 'loadHostsNameErrorCallback' + }); + }, + + loadHostsNameSuccessCallback: function (data) { + var addNNHosts = App.HostComponent.find().filterProperty('componentName', 'NAMENODE'); + this.secondaryNNHosts = []; this.set('selectedSNNHost', this.get('controller.content.sNNHost')); this.set('selectedAddNNHost', this.get('controller.content.addNNHost')); - if(addNNHosts.length == 2){ + if (addNNHosts.length == 2) { this.set('addNNHosts', addNNHosts.mapProperty('host.hostName')); } - App.Host.find().forEach(function(host){ - this.secondaryNNHosts.push(host.get('id')); - },this); + data.items.forEach(function (host) { + this.secondaryNNHosts.push(host.Hosts.host_name); + }, this); this.set('sNNHosts', this.secondaryNNHosts); + this.set('isLoaded', true); + }, + loadHostsNameErrorCallback: function(){ + this.set('isLoaded', true); + }, + + didInsertElement: function() { + this.loadHostsName(); }, tipAddNNHost: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/views/main/host.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/host.js b/ambari-web/app/views/main/host.js index 12563f3..a3a7ff4 100644 --- a/ambari-web/app/views/main/host.js +++ b/ambari-web/app/views/main/host.js @@ -33,17 +33,15 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, { selectAllHosts: false, /** - * flag responsible for updating status counters of hosts - */ - isCountersUpdating: false, - /** * Contains all selected hosts on cluster */ selectedHosts: [], /** * total number of installed hosts */ - totalCount: 0, + totalCount: function () { + return this.get('controller.hostsCountMap')['TOTAL'] || 0; + }.property('controller.hostsCountMap'), filteredCount: function () { return this.get('controller.filteredCount'); @@ -148,8 +146,8 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, { this.addObserver('controller.clearFilters', this, this.clearFiltersObs); this.clearFiltersObs(); this.addObserver('selectAllHosts', this, this.toggleAllHosts); - this.set('isCountersUpdating', true); - this.updateStatusCounters(); + this.set('controller.isCountersUpdating', true); + this.get('controller').updateStatusCounters(); }, /** @@ -161,7 +159,7 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, { }.observes('displayLength', 'startIndex'), willDestroyElement: function() { - this.set('isCountersUpdating', false); + this.set('controller.isCountersUpdating', false); }, /** @@ -420,58 +418,11 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, { }), /** - * update status counters of hosts - */ - updateStatusCounters: function () { - var self = this; - - if (this.get('isCountersUpdating')) { - App.ajax.send({ - name: 'host.status.counters', - sender: this, - data: {}, - success: 'updateStatusCountersSuccessCallback', - error: 'updateStatusCountersErrorCallback' - }); - - setTimeout(function () { - self.updateStatusCounters(); - }, App.get('componentsUpdateInterval')); - } - }, - - /** - * success callback on <code>updateStatusCounters()</code> - * map counters' value to categories - * @param data - */ - updateStatusCountersSuccessCallback: function (data) { - var hostsCountMap = { - 'HEALTHY': data.Clusters.health_report['Host/host_status/HEALTHY'], - 'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'], - 'ALERT': data.Clusters.health_report['Host/host_status/ALERT'], - 'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'], - 'health-status-WITH-ALERTS': (data.alerts) ? data.alerts.summary.CRITICAL + data.alerts.summary.WARNING : 0, - 'health-status-RESTART': data.Clusters.health_report['Host/stale_config'], - 'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'], - 'TOTAL': data.Clusters.total_hosts - }; - - this.set('totalCount', data.Clusters.total_hosts); - this.updateHostsCount(hostsCountMap); - }, - - /** - * success callback on <code>updateStatusCounters()</code> - */ - updateStatusCountersErrorCallback: function() { - console.warn('ERROR: updateStatusCounters failed') - }, - - /** * Update <code>hostsCount</code> in every category */ - updateHostsCount: function(hostsCountMap) { + updateHostsCount: function() { + var hostsCountMap = this.get('controller.hostsCountMap'); + this.get('categories').forEach(function(category) { var hostsCount = (category.get('healthStatus').trim() === "") ? hostsCountMap['TOTAL'] : hostsCountMap[category.get('healthStatus')]; @@ -480,7 +431,7 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, { category.set('hasHosts', (hostsCount > 0)); } }, this); - }, + }.observes('controller.hostsCountMap'), /** * Category view for all hosts http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/views/main/host/details/host_component_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/host/details/host_component_view.js b/ambari-web/app/views/main/host/details/host_component_view.js index 9e1f3a4..d8e2627 100644 --- a/ambari-web/app/views/main/host/details/host_component_view.js +++ b/ambari-web/app/views/main/host/details/host_component_view.js @@ -213,7 +213,7 @@ App.HostComponentView = Em.View.extend({ * @type {bool} */ isReassignable: function () { - return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.Host.find().content.length > 1; + return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.router.get('mainHostController.hostsCountMap')['TOTAL'] > 1; }.property('content.componentName'), /** http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/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 99ea72a..69e51f4 100644 --- a/ambari-web/app/views/main/service/info/summary.js +++ b/ambari-web/app/views/main/service/info/summary.js @@ -470,30 +470,5 @@ App.MainServiceInfoSummaryView = Em.View.extend({ $(alertsList).attr('style', "height:" + summaryActualHeight + "px;"); } } - }.observes('alertsController.isLoaded'), - - clientHosts:App.Host.find(), - - clientHostsLength:function () { - var text = this.t('services.service.summary.clientCount'); - var self = this; - return text.format(self.get('clientHosts.length')); - }.property('clientHosts'), - - clientComponents:function () { - return App.HostComponent.find().filterProperty('isClient', true); - }.property(), - - clientComponentsString:function () { - var components = this.get('clientComponents'); - var names = []; - components.forEach(function (component) { - if (names.indexOf(component.get('displayName')) == -1) { - names.push(component.get('displayName')); - } - }); - - return names.length ? names.join(', ') : false; - }.property('clientComponents') - + }.observes('alertsController.isLoaded') }); http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/views/main/service/item.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/service/item.js b/ambari-web/app/views/main/service/item.js index 4cce974..8afb3d0 100644 --- a/ambari-web/app/views/main/service/item.js +++ b/ambari-web/app/views/main/service/item.js @@ -24,7 +24,7 @@ App.MainServiceItemView = Em.View.extend({ maintenance: function(){ var options = []; var service = this.get('controller.content'); - var hosts = App.Host.find().content.length; + var hosts = App.router.get('mainHostController.hostsCountMap')['TOTAL']; var allMasters = this.get('controller.content.hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq(); var disabled = this.get('controller.isStopDisabled'); var serviceName = service.get('serviceName'); http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/app/views/main/service/services/flume.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/service/services/flume.js b/ambari-web/app/views/main/service/services/flume.js index 300e3b7..12dc89b 100644 --- a/ambari-web/app/views/main/service/services/flume.js +++ b/ambari-web/app/views/main/service/services/flume.js @@ -37,7 +37,7 @@ App.MainDashboardServiceFlumeView = App.TableView.extend({ summaryHeader: function () { var agents = App.FlumeService.find().objectAt(0).get('agents');//this.get('service.agents'); var agentCount = agents.get('length'); - var hostCount = this.get('service.hostComponents').filterProperty('componentName', 'FLUME_HANDLER').length; + var hostCount = this.get('service.flumeHandlersTotal'); var prefix = agentCount == 1 ? this.t("dashboard.services.flume.summary.single") : this.t("dashboard.services.flume.summary.multiple").format(agentCount); var suffix = hostCount == 1 ? this.t("dashboard.services.flume.summary.hosts.single") : @@ -46,7 +46,10 @@ App.MainDashboardServiceFlumeView = App.TableView.extend({ }.property('service.agents', 'service.hostComponents.length'), flumeHandlerComponent: function () { - return App.HostComponent.find().findProperty('componentName', 'FLUME_HANDLER'); + return Em.Object.create({ + componentName: 'FLUME_HANDLER' + }); + //return App.HostComponent.find().findProperty('componentName', 'FLUME_HANDLER'); }.property(), agentView: Em.View.extend({ http://git-wip-us.apache.org/repos/asf/ambari/blob/930c4a43/ambari-web/test/utils/component_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/component_test.js b/ambari-web/test/utils/component_test.js index 4c49cca..f98f9e2 100644 --- a/ambari-web/test/utils/component_test.js +++ b/ambari-web/test/utils/component_test.js @@ -22,31 +22,6 @@ require('models/host_component'); require('models/stack_service_component'); describe('utils/component', function(){ - describe('#getInstalledComponents()', function(){ - beforeEach(function(){ - App.HostComponent.find().set('content',[]); - App.store.loadMany(App.HostComponent, [ - { - "component_name" : "HISTORYSERVER", - "is_client" : false, - "is_master" : true, - "is_slave" : false - }, - { - "component_name" : "TASKTRACKER", - "is_client" : false, - "is_master" : false, - "is_slave" : true - } - ]); - }); - afterEach(function(){ - App.HostComponent.find().set('content',[]); - }); - it('names of components should be equal for input and output arrays', function(){ - expect(component.getInstalledComponents().mapProperty('id')).to.have.members(App.HostComponent.find().mapProperty('componentName')); - }); - }); describe('#loadStackServiceComponentModel()', function(){ var data = { "items": [
