Repository: ambari Updated Branches: refs/heads/trunk 955bc6607 -> 9067dfafb
AMBARI-20588 Remove deprecated code of status filter on Hosts page. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9067dfaf Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9067dfaf Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9067dfaf Branch: refs/heads/trunk Commit: 9067dfafb8f68e1fe9a975e142b873f0eb9cc950 Parents: 955bc66 Author: Andrii Tkach <[email protected]> Authored: Mon Mar 27 18:56:22 2017 +0300 Committer: Andrii Tkach <[email protected]> Committed: Mon Mar 27 19:49:04 2017 +0300 ---------------------------------------------------------------------- .../controllers/global/cluster_controller.js | 3 - ambari-web/app/controllers/main/host.js | 8 +- ambari-web/app/utils/ajax/ajax.js | 4 +- ambari-web/app/views/main/host.js | 193 +------------- .../global/cluster_controller_test.js | 7 - ambari-web/test/controllers/main/host_test.js | 18 +- ambari-web/test/views/main/host_test.js | 256 ++----------------- 7 files changed, 30 insertions(+), 459 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/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 21508ab..b24219e 100644 --- a/ambari-web/app/controllers/global/cluster_controller.js +++ b/ambari-web/app/controllers/global/cluster_controller.js @@ -197,9 +197,6 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, { } App.router.get('userSettingsController').getAllUserSettings(); App.router.get('errorsHandlerController').loadErrorLogs(); - var hostsController = App.router.get('mainHostController'); - hostsController.set('isCountersUpdating', true); - hostsController.updateStatusCounters(); this.loadClusterInfo(); this.restoreUpgradeState(); http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/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 05551af..f294b42 100644 --- a/ambari-web/app/controllers/main/host.js +++ b/ambari-web/app/controllers/main/host.js @@ -343,7 +343,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, { if (this.get('isCountersUpdating')) { App.ajax.send({ - name: 'host.status.counters', + name: 'host.status.total_count', sender: this, data: {}, success: 'updateStatusCountersSuccessCallback', @@ -364,12 +364,6 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, { */ 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-RESTART': data.Clusters.health_report['Host/stale_config'], - 'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'], 'TOTAL': data.Clusters.total_hosts }; http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/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 0198a63..e8be31c 100644 --- a/ambari-web/app/utils/ajax/ajax.js +++ b/ambari-web/app/utils/ajax/ajax.js @@ -2509,8 +2509,8 @@ var urls = { }; } }, - 'host.status.counters': { - 'real': '/clusters/{clusterName}?fields=Clusters/health_report,Clusters/total_hosts,alerts_summary_hosts&minimal_response=true', + 'host.status.total_count': { + 'real': '/clusters/{clusterName}?fields=Clusters/total_hosts&minimal_response=true', 'mock': '/data/hosts/HDP2/host_status_counters.json' }, 'host.stack_versions.install': { http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/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 f74e1b1..6a8dcf2 100644 --- a/ambari-web/app/views/main/host.js +++ b/ambari-web/app/views/main/host.js @@ -197,10 +197,13 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, { this.addObserver('filteredCount', this, this.updatePaging); // should show overlay even when filtering has begun before observer was added this.overlayObserver(); + this.set('controller.isCountersUpdating', true); + this.get('controller').updateStatusCounters(); }, willDestroyElement: function () { $('.tooltip').remove(); + this.set('controller.isCountersUpdating', false); }, onInitialLoad: function () { @@ -453,196 +456,6 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, { }), /** - * Update <code>hostsCount</code> in every category - */ - 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')]; - - if (!Em.isNone(hostsCount)) { - category.set('hostsCount', hostsCount); - category.set('hasHosts', (hostsCount > 0)); - } - }, this); - }.observes('controller.hostsCountMap'), - - /** - * Category view for all hosts - * @type {Object} - */ - //@TODO maybe should be separated to two types (basing on <code>isHealthStatus</code>) - categoryObject: Em.Object.extend({ - - /** - * Text used with <code>hostsCount</code> in category label - * @type {String} - */ - value: null, - /** - * Is category based on host health status - * @type {bool} - */ - isHealthStatus: true, - /** - * host health status (used if <code>isHealthStatus</code> is true) - * @type {String} - */ - healthStatusValue: '', - /** - * Should category be displayed on the top of the hosts table - * @type {bool} - */ - isVisible: true, - /** - * Is category selected now - * @type {bool} - */ - isActive: false, - /** - * String with path that category should observe - * @type {String} - */ - observes: null, - /** - * CSS-class for span in the category-link (used if <code>isHealthStatus</code> is false) - * @type {String} - */ - class: null, - /** - * Associated column number - * @type {Number} - */ - column: null, - /** - * Type of filter value (string, number, boolean) - * @type {String} - */ - type: null, - /** - * @type {String|Number|bool} - */ - filterValue: null, - /** - * <code>App.Host</code> property that should be used to calculate <code>hostsCount</code> (used if <code>isHealthStatus</code> is false) - * @type {String} - */ - hostProperty: null, - - /** - * Number of host in current category - * @type {Number} - */ - hostsCount: 0, - - /** - * Determine if category has hosts - * @type {bool} - */ - hasHosts: false, - - /** - * Add "active" class for category span-wrapper if current category is selected - * @type {String} - */ - itemClass: Em.computed.ifThenElse('isActive', 'active', ''), - - /** - * Text shown on the right of category icon - * @type {String} - */ - label: function () { - return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount')); - }.property('hostsCount') - }), - - /** - * List of categories used to filter hosts - * @type {Array} - */ - categories: function () { - var self = this; - var category_mocks = require('data/host/categories'); - - return category_mocks.map(function(category_mock) { - return self.categoryObject.create(category_mock); - }); - }.property(), - - /** - * Category for <code>selected</code> property of each App.Host - */ - selectedCategory: Em.computed.findBy('categories', 'selected', true), - - statusFilter: Em.View.extend({ - column: 0, - categories: [], - value: null, - class: "", - comboBoxLabel: function(){ - var selected = this.get('categories').findProperty('isActive'); - if (!this.get('value') || !selected) { - return "%@ (%@)".fmt(Em.I18n.t('common.all'), this.get('parentView.totalCount')); - } else { - return "%@ (%@)".fmt(selected.get('value'), selected.get('hostsCount')) - } - }.property('value', 'parentView.totalCount'), - /** - * switch active category label - */ - onCategoryChange: function () { - this.get('categories').setEach('isActive', false); - var selected = this.get('categories').findProperty('healthStatus', this.get('value')); - selected.set('isActive', true); - this.set('class', selected.get('class') + ' ' + selected.get('healthClass')); - }.observes('value'), - - showClearFilter: function () { - var mockEvent = { - context: this.get('categories').findProperty('healthStatus', this.get('value')) - }; - this.selectCategory(mockEvent); - }, - /** - * Trigger on Category click - * @param {Object} event - */ - selectCategory: function(event){ - var category = event.context; - - this.set('value', category.get('healthStatus')); - this.get('parentView').resetFilterByColumns([0, 7, 8, 9]); - if (category.get('isHealthStatus')) { - var status = category.get('healthStatus'); - if (!status) { - // only "All" option has no specific status, just refresh - this.get('parentView').refresh(); - } else { - this.get('parentView').updateFilter(0, status, 'string'); - } - } else { - this.get('parentView').updateFilter(category.get('column'), category.get('filterValue'), category.get('type')); - } - }, - - /** - * set value - * @param {string} value - */ - setValue: function (value) { - this.set('value', value); - }, - - clearFilter: function() { - this.get('categories').setEach('isActive', false); - this.set('value', ''); - this.set('class', ''); - this.showClearFilter(); - } - }), - - /** * associations between host property and column index * @type {Array} */ http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/ambari-web/test/controllers/global/cluster_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/global/cluster_controller_test.js b/ambari-web/test/controllers/global/cluster_controller_test.js index ad6e6f9..e7b71f9 100644 --- a/ambari-web/test/controllers/global/cluster_controller_test.js +++ b/ambari-web/test/controllers/global/cluster_controller_test.js @@ -856,7 +856,6 @@ describe('App.clusterController', function () { sinon.stub(App.router.get('mainController'), 'startPolling'); sinon.stub(App.router.get('userSettingsController'), 'getAllUserSettings'); sinon.stub(App.router.get('errorsHandlerController'), 'loadErrorLogs'); - sinon.stub(App.router.get('mainHostController'), 'updateStatusCounters'); sinon.stub(App.router.get('wizardWatcherController'), 'getUser'); sinon.stub(App.db, 'setFilterConditions'); sinon.stub(App.router.get('updateController'), 'updateClusterEnv'); @@ -867,7 +866,6 @@ describe('App.clusterController', function () { App.router.get('updateController').updateClusterEnv.restore(); App.db.setFilterConditions.restore(); App.router.get('wizardWatcherController').getUser.restore(); - App.router.get('mainHostController').updateStatusCounters.restore(); App.router.get('errorsHandlerController').loadErrorLogs.restore(); App.router.get('userSettingsController').getAllUserSettings.restore(); App.router.get('mainController').startPolling.restore(); @@ -904,11 +902,6 @@ describe('App.clusterController', function () { expect(App.router.get('errorsHandlerController').loadErrorLogs.calledOnce).to.be.true; }); - it('updateStatusCounters should be called', function() { - controller.loadClusterData(); - expect(App.router.get('mainHostController').updateStatusCounters.calledOnce).to.be.true; - }); - it('loadClusterInfo should be called', function() { controller.loadClusterData(); expect(controller.loadClusterInfo.calledOnce).to.be.true; http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/ambari-web/test/controllers/main/host_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host_test.js b/ambari-web/test/controllers/main/host_test.js index f7161d7..ee1e149 100644 --- a/ambari-web/test/controllers/main/host_test.js +++ b/ambari-web/test/controllers/main/host_test.js @@ -135,27 +135,19 @@ describe('MainHostController', function () { it("isCountersUpdating is false", function() { hostController.set('isCountersUpdating', false); hostController.updateStatusCounters(); - expect(testHelpers.findAjaxRequest('name', 'host.status.counters')).to.be.undefined; + expect(testHelpers.findAjaxRequest('name', 'host.status.total_count')).to.be.undefined; }); it("isCountersUpdating is true", function() { hostController.set('isCountersUpdating', true); hostController.updateStatusCounters(); - expect(testHelpers.findAjaxRequest('name', 'host.status.counters')).to.be.exist; + expect(testHelpers.findAjaxRequest('name', 'host.status.total_count')).to.be.exist; }); }); describe("#updateStatusCountersSuccessCallback()", function() { var data = { Clusters: { - health_report: { - 'Host/host_status/HEALTHY': 1, - 'Host/host_status/UNHEALTHY': 2, - 'Host/host_status/ALERT': 3, - 'Host/host_status/UNKNOWN': 4, - 'Host/stale_config': 5, - 'Host/maintenance_state': 6 - }, total_hosts: 21 } }; @@ -163,12 +155,6 @@ describe('MainHostController', function () { it("hostsCountMap should be set", function() { hostController.updateStatusCountersSuccessCallback(data); expect(hostController.get('hostsCountMap')).to.be.eql({ - "HEALTHY": 1, - "UNHEALTHY": 2, - "ALERT": 3, - "UNKNOWN": 4, - "health-status-RESTART": 5, - "health-status-PASSIVE_STATE": 6, "TOTAL": 21 }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9067dfaf/ambari-web/test/views/main/host_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/host_test.js b/ambari-web/test/views/main/host_test.js index 8d66b05..e0eb9bc 100644 --- a/ambari-web/test/views/main/host_test.js +++ b/ambari-web/test/views/main/host_test.js @@ -22,7 +22,9 @@ require('views/main/host'); function getView() { return App.MainHostView.create({ - controller: App.MainHostController.create({ + pageContent: Em.A([]), + controller: Em.Object.create({ + updateStatusCounters: sinon.spy(), updater: Em.Object.create({ tableUpdaterMap: { 'Hosts': 'updateHost' @@ -103,6 +105,25 @@ describe('App.MainHostView', function () { view.didInsertElement(); expect(view.overlayObserver.calledOnce).to.be.true; }); + + it('isCountersUpdating should be true', function () { + view.didInsertElement(); + expect(view.get('controller.isCountersUpdating')).to.be.true; + }); + + it('updateStatusCounters should be called', function () { + view.didInsertElement(); + expect(view.get('controller').updateStatusCounters.calledOnce).to.be.true; + }); + }); + + describe('#willDestroyElement', function() { + + it("isCountersUpdating should be false", function() { + view.set('controller.isCountersUpdating', true); + view.willDestroyElement(); + expect(view.get('controller.isCountersUpdating')).to.be.false; + }); }); describe("#onRequestErrorHandler()", function () { @@ -950,239 +971,6 @@ describe('App.MainHostView', function () { }); }); - describe("#updateHostsCount()", function () { - - it("should update host counter in categories", function() { - view.reopen({ - categories: [ - Em.Object.create({healthStatus: ''}), - Em.Object.create({healthStatus: 'HEALTHY'}), - Em.Object.create({healthStatus: 'UNKNOWN', hostsCount: 0, hasHosts: false}) - ] - }); - view.set('controller.hostsCountMap', { - TOTAL: 10, - HEALTHY: 1 - }); - view.updateHostsCount(); - expect(view.get('categories').mapProperty('hostsCount')).to.be.eql([10, 1, 0]); - expect(view.get('categories').mapProperty('hasHosts')).to.be.eql([true, true, false]); - }); - }); - - describe("#categoryObject", function () { - var categoryObject; - - beforeEach(function() { - categoryObject = view.get('categoryObject').create(); - }); - - describe("#label", function () { - - it("should return label", function() { - categoryObject.set('hostsCount', 1); - categoryObject.set('value', 'val1'); - expect(categoryObject.get('label')).to.be.equal('val1 (1)'); - }); - }); - }); - - describe("#statusFilter", function () { - var statusFilter; - - beforeEach(function () { - statusFilter = view.get('statusFilter').create({ - parentView: Em.Object.create({ - resetFilterByColumns: Em.K, - refresh: Em.K, - updateFilter: Em.K - }) - }); - }); - - describe("#comboBoxLabel", function () { - beforeEach(function() { - sinon.stub(statusFilter, 'onCategoryChange'); - }); - - afterEach(function() { - statusFilter.onCategoryChange.restore(); - }); - - var testCases = [ - { - value: 'val1', - categories: [Em.Object.create({isActive: true, hostsCount: 1, value: "val1"})], - totalCount: 10, - expected: 'val1 (1)' - }, - { - value: 'val1', - categories: [Em.Object.create({isActive: false, hostsCount: 1})], - totalCount: 10, - expected: Em.I18n.t('common.all') + ' (10)' - }, - { - value: '', - categories: [], - totalCount: 10, - expected: Em.I18n.t('common.all') + ' (10)' - } - ]; - - testCases.forEach(function(test) { - it("value=" + test.value + - " categories=" + JSON.stringify(test.categories) + - " totalCount=" + test.totalCount, function () { - statusFilter.setProperties({ - value: test.value, - categories: test.categories - }); - statusFilter.set('parentView.totalCount', test.totalCount); - expect(statusFilter.get('comboBoxLabel')).to.be.equal(test.expected); - }); - }); - }); - - describe("#onCategoryChange()", function () { - - it("should set class", function() { - statusFilter.setProperties({ - value: 'val1', - categories: [ - Em.Object.create({ - healthStatus: 'val1', - class: 'cl1', - healthClass: 'hcl1' - }) - ] - }); - expect(statusFilter.get('class')).to.be.equal('cl1 hcl1'); - expect(statusFilter.get('categories')[0].get('isActive')).to.be.true; - }); - }); - - describe("#showClearFilter()", function () { - - beforeEach(function() { - sinon.stub(statusFilter, 'selectCategory'); - sinon.stub(statusFilter, 'onCategoryChange'); - }); - - afterEach(function() { - statusFilter.selectCategory.restore(); - statusFilter.onCategoryChange.restore(); - }); - - it("selectCategory should be called", function() { - statusFilter.setProperties({ - value: 'val1', - categories: [ - Em.Object.create({ - healthStatus: 'val1' - }) - ] - }); - statusFilter.showClearFilter(); - expect(statusFilter.selectCategory.getCall(0).args).to.be.eql([ - { - context: Em.Object.create({ - healthStatus: 'val1' - }) - } - ]); - }); - }); - - describe("#selectCategory()", function () { - var category = Em.Object.create({ - healthStatus: 'val1', - column: 1, - isHealthStatus: false, - filterValue: 'val1', - type: 't1' - }); - - beforeEach(function() { - sinon.stub(statusFilter.get('parentView'), 'resetFilterByColumns'); - sinon.stub(statusFilter.get('parentView'), 'refresh'); - sinon.stub(statusFilter.get('parentView'), 'updateFilter'); - sinon.stub(statusFilter, 'onCategoryChange'); - }); - - afterEach(function() { - statusFilter.get('parentView').resetFilterByColumns.restore(); - statusFilter.get('parentView').refresh.restore(); - statusFilter.get('parentView').updateFilter.restore(); - statusFilter.onCategoryChange.restore(); - }); - - it("value should be set", function() { - statusFilter.selectCategory({context: category}); - expect(statusFilter.get('value')).to.be.equal('val1'); - }); - - it("resetFilterByColumns should be called", function() { - statusFilter.selectCategory({context: category}); - expect(statusFilter.get('parentView').resetFilterByColumns.calledWith([0, 7, 8, 9])).to.be.true; - }); - - it("updateFilter should be called, isHealthStatus=false", function() { - category.set('isHealthStatus', false); - statusFilter.selectCategory({context: category}); - expect(statusFilter.get('parentView').updateFilter.calledWith(1, 'val1', 't1')).to.be.true; - }); - - it("updateFilter should be called, isHealthStatus=true", function() { - category.set('isHealthStatus', true); - category.set('healthStatus', 'val1'); - statusFilter.selectCategory({context: category}); - expect(statusFilter.get('parentView').updateFilter.calledWith(0, 'val1', 'string')).to.be.true; - }); - - it("refresh should be called, isHealthStatus=true", function() { - category.set('isHealthStatus', true); - category.set('healthStatus', null); - statusFilter.selectCategory({context: category}); - expect(statusFilter.get('parentView').refresh.calledOnce).to.be.true; - }); - }); - - describe("#clearFilter()", function () { - - beforeEach(function() { - sinon.stub(statusFilter, 'showClearFilter'); - sinon.stub(statusFilter, 'onCategoryChange'); - }); - - afterEach(function() { - statusFilter.showClearFilter.restore(); - statusFilter.onCategoryChange.restore(); - }); - - it("isActive should be false", function() { - statusFilter.set('categories', [Em.Object.create()]); - statusFilter.clearFilter(); - expect(statusFilter.get('categories')[0].get('isActive')).to.be.false; - }); - - it("value should be empty", function() { - statusFilter.clearFilter(); - expect(statusFilter.get('value')[0]).to.be.empty; - }); - - it("class should be empty", function() { - statusFilter.clearFilter(); - expect(statusFilter.get('class')).to.be.empty; - }); - - it("showClearFilter should be called", function() { - statusFilter.clearFilter(); - expect(statusFilter.showClearFilter.calledOnce).to.be.true; - }); - }); - }); - describe("#clearFilters()", function () { beforeEach(function() {
