Repository: ambari Updated Branches: refs/heads/branch-2.6 60bbaaf22 -> 7598e1b0d
AMBARI-21969 Manage config groups at Add Service Wizard doesn't show host with selected components from filter. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7598e1b0 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7598e1b0 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7598e1b0 Branch: refs/heads/branch-2.6 Commit: 7598e1b0d100d2f8fbd7333898e9d3b54525d116 Parents: 60bbaaf Author: Andrii Tkach <atk...@apache.org> Authored: Fri Sep 15 19:25:18 2017 +0300 Committer: Andrii Tkach <atk...@apache.org> Committed: Mon Sep 18 13:43:34 2017 +0300 ---------------------------------------------------------------------- .../service/manage_config_groups_controller.js | 55 +++++++++++- ambari-web/app/utils/hosts.js | 4 +- .../manage_config_groups_controller_test.js | 89 +++++++++++++++++++- ambari-web/test/utils/hosts_test.js | 3 +- 4 files changed, 144 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7598e1b0/ambari-web/app/controllers/main/service/manage_config_groups_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js index 29c9d0a..a3f2be9 100644 --- a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js +++ b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js @@ -321,15 +321,16 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { * @private */ _loadHostsFromServerSuccessCallback: function (data) { - var wrappedHosts = []; + var wrappedHosts = [], + newlyAddedHostComponentsMap = this.getNewlyAddedHostComponentsMap(); data.items.forEach(function (host) { var hostComponents = []; - var diskInfo = host.Hosts.disk_info.filter(function(item) { + var diskInfo = host.Hosts.disk_info.filter(function (item) { return /^ext|^ntfs|^fat|^xfs/i.test(item.type); }); if (diskInfo.length) { - diskInfo = diskInfo.reduce(function(a, b) { + diskInfo = diskInfo.reduce(function (a, b) { return { available: parseInt(a.available) + parseInt(b.available), size: parseInt(a.size) + parseInt(b.size) @@ -342,6 +343,9 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { displayName: App.format.role(hostComponent.HostRoles.component_name, false) })); }, this); + if (this.get('isAddService') && newlyAddedHostComponentsMap[host.Hosts.host_name]) { + hostComponents.pushObjects(newlyAddedHostComponentsMap[host.Hosts.host_name]); + } wrappedHosts.pushObject(Em.Object.create({ id: host.Hosts.host_name, ip: host.Hosts.ip, @@ -372,6 +376,51 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { }, /** + * + * @returns {{}} + */ + getNewlyAddedHostComponentsMap: function () { + var newlyAddedHostComponentsMap = {}; + var clients = App.router.get('addServiceController.content.clients').filterProperty('isInstalled', false).map(function (component) { + return Em.Object.create({ + componentName: component.component_name, + displayName: component.display_name + }); + }); + + App.router.get('addServiceController.content.masterComponentHosts').forEach(function (component) { + if (!component.isInstalled) { + if (!newlyAddedHostComponentsMap[component.hostName]) { + newlyAddedHostComponentsMap[component.hostName] = []; + } + newlyAddedHostComponentsMap[component.hostName].push(Em.Object.create({ + componentName: component.component, + displayName: component.display_name + })); + } + }); + + App.router.get('addServiceController.content.slaveComponentHosts').forEach(function (component) { + component.hosts.forEach(function (host) { + if (!host.isInstalled) { + if (!newlyAddedHostComponentsMap[host.hostName]) { + newlyAddedHostComponentsMap[host.hostName] = []; + } + if (component.componentName === 'CLIENT') { + newlyAddedHostComponentsMap[host.hostName].pushObjects(clients); + } else { + newlyAddedHostComponentsMap[host.hostName].push(Em.Object.create({ + componentName: component.componentName, + displayName: component.displayName + })); + } + } + }); + }); + return newlyAddedHostComponentsMap; + }, + + /** * Load config groups from server if user is on the already installed cluster * If not - use loaded data form wizardStep7Controller * @param {string} serviceName http://git-wip-us.apache.org/repos/asf/ambari/blob/7598e1b0/ambari-web/app/utils/hosts.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/hosts.js b/ambari-web/app/utils/hosts.js index c81cc02..316c459 100644 --- a/ambari-web/app/utils/hosts.js +++ b/ambari-web/app/utils/hosts.js @@ -155,12 +155,12 @@ module.exports = { skip = true; } if (!skip && filterComponent && hostComponentNames.length > 0) { - skip = !hostComponentNames.contains(filterComponent.get('componentName')); + skip = !hostComponentNames.contains(filterComponent.get('componentName')); } host.set('filtered', !skip); }, this); - this.set('startIndex', 1); + this.set('startIndex', this.get('parentView.availableHosts').someProperty('filtered') ? 1 : 0); }.observes('parentView.availableHosts', 'filterColumn', 'filterText', 'filterComponent', 'filterComponent.componentName', 'showOnlySelectedHosts'), hostSelectMessage: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/7598e1b0/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js index e0ca439..19d0a49 100644 --- a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js +++ b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js @@ -20,7 +20,6 @@ var App = require('app'); var c; describe('App.ManageConfigGroupsController', function() { - var controller = App.ManageConfigGroupsController.create({}); beforeEach(function() { c = App.ManageConfigGroupsController.create({}); @@ -589,4 +588,92 @@ describe('App.ManageConfigGroupsController', function() { }); + describe('#getNewlyAddedHostComponentsMap', function() { + beforeEach(function() { + this.mockGet = sinon.stub(App.router, 'get'); + this.mockGet.withArgs('addServiceController.content.clients').returns([ + { + isInstalled: true, + component_name: 'Client1', + display_name: 'client1' + }, + { + isInstalled: false, + component_name: 'Client2', + display_name: 'client2' + } + ]); + this.mockGet.withArgs('addServiceController.content.masterComponentHosts').returns([ + { + isInstalled: true, + hostName: 'host1', + component: 'Master1', + display_name: 'master1' + }, + { + isInstalled: false, + hostName: 'host2', + component: 'Master2', + display_name: 'master2' + } + ]); + this.mockGet.withArgs('addServiceController.content.slaveComponentHosts').returns([ + { + componentName: 'Slave1', + displayName: 'slave1', + hosts: [ + { + hostName: 'host1', + isInstalled: false + } + ] + }, + { + componentName: 'Slave2', + displayName: 'slave2', + hosts: [ + { + hostName: 'host2', + isInstalled: true + } + ] + }, + { + componentName: 'CLIENT', + displayName: 'client', + hosts: [ + { + hostName: 'host1', + isInstalled: false + } + ] + } + ]); + }); + afterEach(function() { + this.mockGet.restore(); + }); + + it('should return host-components map', function() { + expect(JSON.stringify(c.getNewlyAddedHostComponentsMap())).to.be.equal(JSON.stringify({ + "host2": [ + { + "componentName": "Master2", + "displayName": "master2" + } + ], + "host1": [ + { + "componentName": "Slave1", + "displayName": "slave1" + }, + { + "componentName": "Client2", + "displayName": "client2" + } + ] + })); + }); + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7598e1b0/ambari-web/test/utils/hosts_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/hosts_test.js b/ambari-web/test/utils/hosts_test.js index 41fe555..0b20999 100644 --- a/ambari-web/test/utils/hosts_test.js +++ b/ambari-web/test/utils/hosts_test.js @@ -2858,8 +2858,9 @@ describe('hosts utils', function () { it('start index', function () { view.set('startIndex', 0); + view.set('parentView.availableHosts', []); view.propertyDidChange('filterColumn'); - expect(view.get('startIndex')).to.equal(1); + expect(view.get('startIndex')).to.equal(0); }); });