Repository: ambari Updated Branches: refs/heads/trunk f5f40f534 -> 30fab7861
AMBARI-5528 UI unit tests and refactoring for controller of Add Host wizard. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/30fab786 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/30fab786 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/30fab786 Branch: refs/heads/trunk Commit: 30fab7861cd96cff411fc07ac4a10db81ed24ee4 Parents: f5f40f5 Author: atkach <atk...@hortonworks.com> Authored: Tue Apr 22 17:13:18 2014 +0300 Committer: atkach <atk...@hortonworks.com> Committed: Tue Apr 22 17:13:18 2014 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 3 +- .../app/controllers/global/update_controller.js | 2 +- ambari-web/app/controllers/installer.js | 10 - .../admin/highAvailability/wizard_controller.js | 26 +- .../app/controllers/main/host/add_controller.js | 234 +++---- .../controllers/main/service/add_controller.js | 29 +- .../main/service/reassign_controller.js | 26 +- ambari-web/app/controllers/wizard.js | 28 + .../main/host/add_controller_test.js | 613 +++++++++++++++++++ 9 files changed, 745 insertions(+), 226 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index b51575e..c4738f0 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -47,6 +47,7 @@ require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_cpuWaitIO_t require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused_test'); require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_memoryused_test'); require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn_ResourceUsed_test'); +require('test/controllers/main/host/add_controller_test'); require('test/controllers/main/service/add_controller_test'); require('test/controllers/main/service/reassign_controller_test'); require('test/controllers/main/dashboard_test'); @@ -103,7 +104,7 @@ require('test/views/common/quick_link_view_test'); require('test/views/common/rolling_restart_view_test'); require('test/views/main/dashboard_test'); require('test/views/main/dashboard/widget_test'); -require('test/views/main/dashboard/widgets_test');1 +require('test/views/main/dashboard/widgets_test'); require('test/views/main/dashboard/widgets/text_widget_test'); require('test/views/main/dashboard/widgets/uptime_text_widget_test'); require('test/views/main/dashboard/widgets/node_managers_live_test'); http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/global/update_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js index f992af8..d24e5ac 100644 --- a/ambari-web/app/controllers/global/update_controller.js +++ b/ambari-web/app/controllers/global/update_controller.js @@ -121,7 +121,7 @@ App.UpdateController = Em.Controller.extend({ var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/master_components.json' : '/data/dashboard/services.json'; var isFlumeInstalled = App.cache['services'].mapProperty('ServiceInfo.service_name').contains('FLUME'); var flumeHandlerParam = isFlumeInstalled ? 'ServiceComponentInfo/component_name=FLUME_HANDLER|' : ''; - realUrl = '/components/?' + flumeHandlerParam + + var realUrl = '/components/?' + flumeHandlerParam + 'ServiceComponentInfo/category=MASTER&fields=' + 'ServiceComponentInfo/Version,' + 'ServiceComponentInfo/StartTime,' + http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/installer.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/installer.js b/ambari-web/app/controllers/installer.js index 4cc7b8f..bc9617d 100644 --- a/ambari-web/app/controllers/installer.js +++ b/ambari-web/app/controllers/installer.js @@ -425,16 +425,6 @@ App.InstallerController = App.WizardController.extend({ this.set('content.advancedServiceConfig', this.getDBProperty('advancedServiceConfig')); }, - - /** - * Load information about hosts with clients components - */ - loadClients: function () { - var clients = this.getDBProperty('clientInfo'); - this.set('content.clients', clients); - console.log("InstallerController.loadClients: loaded list ", clients); - }, - /** * Generate clients list for selected services and save it to model * @param stepController step4WizardController http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js index 4839588..c838373 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability/wizard_controller.js @@ -66,10 +66,7 @@ App.HighAvailabilityWizardController = App.WizardController.extend({ * Load services data from server. */ loadServicesFromServer: function() { - var displayOrderConfig = require('data/services'); - var apiUrl = App.get('stack2VersionURL'); - var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl); - // + var apiService = this.loadServiceComponents(); apiService.forEach(function(item, index){ apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName); apiService[index].isDisabled = apiService[index].isSelected; @@ -104,27 +101,6 @@ App.HighAvailabilityWizardController = App.WizardController.extend({ this.set('content.hosts', hosts); console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts); }, - - /** - * Load master component hosts data for using in required step controllers - */ - loadMasterComponentHosts: function () { - var masterComponentHosts = App.db.getMasterComponentHosts(); - if(!masterComponentHosts){ - masterComponentHosts = []; - App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){ - masterComponentHosts.push({ - component: item.get('componentName'), - hostName: item.get('host.hostName'), - isInstalled: true - }) - }); - - } - this.set("content.masterComponentHosts", masterComponentHosts); - console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts); - }, - /** * save status of the cluster. * @param clusterStatus object with status,requestId fields. http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/main/host/add_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host/add_controller.js b/ambari-web/app/controllers/main/host/add_controller.js index ab282c1..077d2a7 100644 --- a/ambari-web/app/controllers/main/host/add_controller.js +++ b/ambari-web/app/controllers/main/host/add_controller.js @@ -57,6 +57,11 @@ App.AddHostController = App.WizardController.extend({ configGroups: null }), + /** + * save info about wizard progress, particularly current step of wizard + * @param currentStep + * @param completed + */ setCurrentStep: function (currentStep, completed) { this._super(currentStep, completed); App.clusterStatus.setClusterStatus({ @@ -69,7 +74,7 @@ App.AddHostController = App.WizardController.extend({ * return new object extended from clusterStatusTemplate * @return Object */ - getCluster: function(){ + getCluster: function () { return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()}); }, @@ -77,19 +82,11 @@ App.AddHostController = App.WizardController.extend({ * return new object extended from installOptionsTemplate * @return Object */ - getInstallOptions: function(){ + getInstallOptions: function () { return jQuery.extend({}, this.get('installOptionsTemplate')); }, /** - * return empty hosts array - * @return Array - */ - getHosts: function(){ - return []; - }, - - /** * Remove host from model. Used at <code>Confirm hosts</code> step * @param hosts Array of hosts, which we want to delete */ @@ -104,13 +101,11 @@ App.AddHostController = App.WizardController.extend({ /** * Load services data from server. + * TODO move to mixin */ - loadServicesFromServer: function() { - var displayOrderConfig = require('data/services'); - var apiUrl = App.get('stack2VersionURL'); - var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl); - // - apiService.forEach(function(item, index){ + loadServicesFromServer: function () { + var apiService = this.loadServiceComponents(); + apiService.forEach(function (item, index) { apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName); apiService[index].isDisabled = apiService[index].isSelected; apiService[index].isInstalled = apiService[index].isSelected; @@ -124,86 +119,28 @@ App.AddHostController = App.WizardController.extend({ */ loadServices: function () { var servicesInfo = this.getDBProperty('service'); + console.log('AddHostController.loadServices: loaded data ', servicesInfo); servicesInfo.forEach(function (item, index) { servicesInfo[index] = Em.Object.create(item); }); this.set('content.services', servicesInfo); - console.log('AddHostController.loadServices: loaded data ', servicesInfo); var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'); console.log('selected services ', serviceNames); }, /** - * Load master component hosts data for using in required step controllers - */ - loadMasterComponentHosts: function () { - var masterComponentHosts = this.getDBProperty('masterComponentHosts'); - if (!masterComponentHosts) { - masterComponentHosts = []; - App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) { - masterComponentHosts.push({ - component: item.get('componentName'), - hostName: item.get('host.hostName'), - isInstalled: true, - serviceId: item.get('service.id'), - display_name: item.get('displayName') - }) - }); - this.setDBProperty('masterComponentHosts', masterComponentHosts); - } - this.set("content.masterComponentHosts", masterComponentHosts); - console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts); - }, - - /** - * Save HBase and ZooKeeper to main controller - * @param stepController - */ - saveHbZk: function(stepController) { - var self = this; - var hosts = stepController.get('hosts'); - var headers = stepController.get('headers'); - var masterComponentHosts = this.getDBProperty('masterComponentHosts'); - - headers.forEach(function(header) { - var rm = masterComponentHosts.filterProperty('component', header.get('name')); - if(rm) { - masterComponentHosts.removeObjects(rm); - } - }); - - headers.forEach(function(header) { - var component = App.StackServiceComponent.find().findProperty('componentName', header.get('name')); - hosts.forEach(function(host) { - if (host.get('checkboxes').findProperty('title', component.display_name).checked) { - masterComponentHosts .push({ - display_name: component.get('displayName'), - component: component.get('componentName'), - hostName: host.get('hostName'), - serviceId: component.get('serviceName'), - isInstalled: false - }); - } - }); - }); - - console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts); - this.setDBProperty('masterComponentHosts', masterComponentHosts); - this.set('content.masterComponentHosts', masterComponentHosts); - }, - - /** * return slaveComponents bound to hosts * @return {Array} */ getSlaveComponentHosts: function () { - return this._super().filter(function(component){ + return this._super().filter(function (component) { return component.isInstalled; }); }, /** * Load master component hosts data for using in required step controllers + * TODO move to mixin */ loadSlaveComponentHosts: function () { var slaveComponentHosts = this.getDBProperty('slaveComponentHosts'); @@ -215,15 +152,6 @@ App.AddHostController = App.WizardController.extend({ }, /** - * Load information about hosts with clients components - */ - loadClients: function () { - var clients = this.getDBProperty('clientInfo'); - this.set('content.clients', clients); - console.log("AddHostController.loadClients: loaded list ", clients); - }, - - /** * Generate clients list for selected services and save it to model */ saveClients: function () { @@ -231,10 +159,10 @@ App.AddHostController = App.WizardController.extend({ var serviceComponents = App.StackServiceComponent.find(); var hostComponents = App.HostComponent.find(); - this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) { - var client = serviceComponents.filterProperty('serviceName', _service.serviceName).findProperty('isClient', true); + this.get('content.services').filterProperty('isSelected').forEach(function (_service) { + var client = serviceComponents.filterProperty('serviceName', _service.serviceName).findProperty('isClient'); if (client) { - clients.pushObject({ + clients.push({ component_name: client.get('componentName'), display_name: client.get('displayName'), isInstalled: hostComponents.filterProperty('componentName', client.get('componentName')).length > 0 @@ -252,14 +180,14 @@ App.AddHostController = App.WizardController.extend({ */ applyConfigGroup: function () { var serviceConfigGroups = this.get('content.serviceConfigGroups'); - serviceConfigGroups.forEach(function (group){ + serviceConfigGroups.forEach(function (group) { if (group.configGroups.someProperty('ConfigGroup.group_name', group.selectedConfigGroup)) { var configGroup = group.configGroups.findProperty('ConfigGroup.group_name', group.selectedConfigGroup); - group.hosts.forEach(function(host){ + group.hosts.forEach(function (host) { configGroup.ConfigGroup.hosts.push({ host_name: host }); - },this); + }, this); delete configGroup.href; App.ajax.send({ name: 'config_groups.update_config_group', @@ -270,7 +198,7 @@ App.AddHostController = App.WizardController.extend({ } }); } - },this); + }, this); }, /** @@ -293,33 +221,70 @@ App.AddHostController = App.WizardController.extend({ * Set content.serviceConfigGroups for step4 */ loadServiceConfigGroups: function () { - var slaveComponentHosts = this.get('content.slaveComponentHosts'); var selectedServices = []; - var selectedClientHosts = slaveComponentHosts.findProperty('componentName', 'CLIENT').hosts.mapProperty('hostName'); + this.loadServiceConfigGroupsBySlaves(selectedServices); + this.loadServiceConfigGroupsByClients(selectedServices); + this.sortServiceConfigGroups(selectedServices); + this.set('content.serviceConfigGroups', selectedServices); + }, + /** + * sort config groups by name + * @param selectedServices + */ + sortServiceConfigGroups: function (selectedServices) { + selectedServices.forEach(function (selectedService) { + selectedService.configGroups.sort(function (cfgA, cfgB) { + if (cfgA.ConfigGroup.group_name < cfgB.ConfigGroup.group_name) return -1; + if (cfgA.ConfigGroup.group_name > cfgB.ConfigGroup.group_name) return 1; + return 0; + }); + }); + }, + /** + * load service config groups by slave components, + * push them into selectedServices + * @param selectedServices + */ + loadServiceConfigGroupsBySlaves: function (selectedServices) { var componentServiceMap = App.QuickDataMapper.componentServiceMap(); - - slaveComponentHosts.forEach(function (slave) { - if (slave.hosts.length > 0) { - if (slave.componentName != "CLIENT") { - var service = componentServiceMap[slave.componentName]; - var configGroups = this.get('content.configGroups').filterProperty('ConfigGroup.tag', service); - var configGroupsNames = configGroups.mapProperty('ConfigGroup.group_name'); - var defaultGroupName = App.Service.DisplayNames[service] + ' Default'; - configGroupsNames.unshift(defaultGroupName); - selectedServices.push({ - serviceId: service, - displayName: App.Service.DisplayNames[service], - hosts: slave.hosts.mapProperty('hostName'), - configGroupsNames: configGroupsNames, - configGroups: configGroups, - selectedConfigGroup: defaultGroupName - }); + var slaveComponentHosts = this.get('content.slaveComponentHosts'); + if (slaveComponentHosts && slaveComponentHosts.length > 0) { + slaveComponentHosts.forEach(function (slave) { + if (slave.hosts.length > 0) { + if (slave.componentName !== "CLIENT") { + var service = componentServiceMap[slave.componentName]; + var configGroups = this.get('content.configGroups').filterProperty('ConfigGroup.tag', service); + var configGroupsNames = configGroups.mapProperty('ConfigGroup.group_name'); + var defaultGroupName = App.Service.DisplayNames[service] + ' Default'; + configGroupsNames.unshift(defaultGroupName); + selectedServices.push({ + serviceId: service, + displayName: App.Service.DisplayNames[service], + hosts: slave.hosts.mapProperty('hostName'), + configGroupsNames: configGroupsNames, + configGroups: configGroups, + selectedConfigGroup: defaultGroupName + }); + } } - } - }, this); - if (selectedClientHosts.length > 0) { + }, this); + return true; + } + return false; + }, + /** + * load service config groups by clients, + * push them into selectedServices + * @param selectedServices + */ + loadServiceConfigGroupsByClients: function (selectedServices) { + var componentServiceMap = App.QuickDataMapper.componentServiceMap(); + var slaveComponentHosts = this.get('content.slaveComponentHosts'); + var clients = this.get('content.clients'); + var client = slaveComponentHosts && slaveComponentHosts.findProperty('componentName', 'CLIENT'); + var selectedClientHosts = client && client.hosts.mapProperty('hostName'); + if (clients && selectedClientHosts && clients.length > 0 && selectedClientHosts.length > 0) { this.loadClients(); - var clients = this.get('content.clients'); clients.forEach(function (client) { var service = componentServiceMap[client.component_name]; var serviceMatch = selectedServices.findProperty('serviceId', service); @@ -340,13 +305,9 @@ App.AddHostController = App.WizardController.extend({ }); } }, this); + return true; } - selectedServices.forEach(function(selectedService){ - selectedService.configGroups.sort(function(cfgA, cfgB){ - return cfgA.ConfigGroup.group_name >= cfgB.ConfigGroup.group_name; - }); - }); - this.set('content.serviceConfigGroups', selectedServices); + return false; }, loadServiceConfigProperties: function () { @@ -405,32 +366,31 @@ App.AddHostController = App.WizardController.extend({ App.updater.immediateRun('updateHost'); }, + /** + * send request to server in order to install services + * @param isRetry + */ installServices: function (isRetry) { this.set('content.cluster.oldRequestsId', []); var clusterName = this.get('content.cluster.name'); - var data; - var name; - var hostnames = []; + var hostNames = []; for (var hostname in this.getDBProperty('hosts')) { - hostnames.push(hostname); + hostNames.push(hostname); } + if(!clusterName || hostNames.length === 0) return false; - if (isRetry) { - name = 'wizard.install_services.add_host_controller.is_retry'; - } - else { - name = 'wizard.install_services.add_host_controller.not_is_retry'; - } - data = { + var name = 'wizard.install_services.add_host_controller.'; + name += (isRetry) ? 'is_retry' : 'not_is_retry'; + + var data = JSON.stringify({ "RequestInfo": { "context": Em.I18n.t('requestInfo.installComponents'), - "query": "HostRoles/host_name.in(" + hostnames.join(',') + ")" + "query": "HostRoles/host_name.in(" + hostNames.join(',') + ")" }, "Body": { "HostRoles": {"state": "INSTALLED"} } - }; - data = JSON.stringify(data); + }); App.ajax.send({ name: name, sender: this, @@ -441,6 +401,6 @@ App.AddHostController = App.WizardController.extend({ success: 'installServicesSuccessCallback', error: 'installServicesErrorCallback' }); + return true; } - }); http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/main/service/add_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/add_controller.js b/ambari-web/app/controllers/main/service/add_controller.js index 8ce5411..c0f5f9b 100644 --- a/ambari-web/app/controllers/main/service/add_controller.js +++ b/ambari-web/app/controllers/main/service/add_controller.js @@ -104,9 +104,7 @@ App.AddServiceController = App.WizardController.extend({ if(this.getDBProperty('service')){ return; } - var displayOrderConfig = require('data/services'); - var apiUrl = App.get('stack2VersionURL'); - var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl); + var apiService = this.loadServiceComponents(); // apiService.forEach(function(item, index){ apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName); @@ -188,21 +186,7 @@ App.AddServiceController = App.WizardController.extend({ * Load master component hosts data for using in required step controllers */ loadMasterComponentHosts: function () { - var masterComponentHosts = this.getDBProperty('masterComponentHosts'); - if(!masterComponentHosts){ - masterComponentHosts = []; - App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){ - masterComponentHosts.push({ - component: item.get('componentName'), - hostName: item.get('host.hostName'), - isInstalled: true - }) - }); - - } - this.set("content.masterComponentHosts", masterComponentHosts); - console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts); - + this._super(); this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true)); this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep')); }, @@ -261,15 +245,6 @@ App.AddServiceController = App.WizardController.extend({ }, /** - * Load information about hosts with clients components - */ - loadClients: function(){ - var clients = this.getDBProperty('clientInfo'); - this.set('content.clients', clients); - console.log("AddServiceController.loadClients: loaded list ", clients); - }, - - /** * Generate clients list for selected services and save it to model * @param stepController step4WizardController */ http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/main/service/reassign_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/reassign_controller.js b/ambari-web/app/controllers/main/service/reassign_controller.js index 811b30b..25916f3 100644 --- a/ambari-web/app/controllers/main/service/reassign_controller.js +++ b/ambari-web/app/controllers/main/service/reassign_controller.js @@ -123,10 +123,7 @@ App.ReassignMasterController = App.WizardController.extend({ * Load services data from server. */ loadServicesFromServer: function () { - var displayOrderConfig = require('data/services'); - var apiUrl = App.get('stack2VersionURL'); - var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl); - // + var apiService = this.loadServiceComponents(); apiService.forEach(function (item, index) { apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName); apiService[index].isDisabled = apiService[index].isSelected; @@ -161,27 +158,6 @@ App.ReassignMasterController = App.WizardController.extend({ this.set('content.hosts', hosts); console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts); }, - - /** - * Load master component hosts data for using in required step controllers - */ - loadMasterComponentHosts: function () { - var masterComponentHosts = App.db.getMasterComponentHosts(); - if (!masterComponentHosts) { - masterComponentHosts = []; - App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) { - masterComponentHosts.push({ - component: item.get('componentName'), - hostName: item.get('host.hostName'), - isInstalled: true - }) - }); - - } - this.set("content.masterComponentHosts", masterComponentHosts); - console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts); - }, - /** * Load tasks statuses for step5 of Reassign Master Wizard to restore installation */ http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/app/controllers/wizard.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard.js b/ambari-web/app/controllers/wizard.js index a1f0489..00591aa 100644 --- a/ambari-web/app/controllers/wizard.js +++ b/ambari-web/app/controllers/wizard.js @@ -858,5 +858,33 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, { }); return result; + }, + /** + * Load master component hosts data for using in required step controllers + */ + loadMasterComponentHosts: function () { + var masterComponentHosts = this.getDBProperty('masterComponentHosts'); + if (!masterComponentHosts) { + masterComponentHosts = []; + App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) { + masterComponentHosts.push({ + component: item.get('componentName'), + hostName: item.get('host.hostName'), + isInstalled: true, + serviceId: item.get('service.id'), + display_name: item.get('displayName') + }) + }); + this.setDBProperty('masterComponentHosts', masterComponentHosts); + } + this.set("content.masterComponentHosts", masterComponentHosts); + }, + /** + * Load information about hosts with clients components + */ + loadClients: function () { + var clients = this.getDBProperty('clientInfo'); + this.set('content.clients', clients); + console.log(this.get('content.controllerName') + ".loadClients: loaded list ", clients); } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/30fab786/ambari-web/test/controllers/main/host/add_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host/add_controller_test.js b/ambari-web/test/controllers/main/host/add_controller_test.js new file mode 100644 index 0000000..6ca3f0d --- /dev/null +++ b/ambari-web/test/controllers/main/host/add_controller_test.js @@ -0,0 +1,613 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var App = require('app'); +require('controllers/wizard'); +require('controllers/main/host/add_controller'); +require('models/host_component'); +require('models/service'); +require('mappers/server_data_mapper'); + +describe('App.AddHostController', function () { + + var controller = App.AddHostController.create({ + testDBHosts: null, + getDBProperty: function () { + return this.get('testDBHosts'); + }, + setDBProperty: function () { + }, + loadClients: function () { + } + }); + + beforeEach(function () { + sinon.spy(controller, "setDBProperty"); + }); + afterEach(function () { + controller.setDBProperty.restore(); + }); + + describe('#removeHosts()', function () { + var testCases = [ + { + title: 'No hosts, db is empty', + content: { + hosts: [], + dbHosts: {} + }, + result: {} + }, + { + title: 'Host is passed, db is empty', + content: { + hosts: [ + {hostName: 'host1'} + ], + dbHosts: {} + }, + result: {} + }, + { + title: 'Passed host different from hosts in db', + content: { + hosts: [ + {hostName: 'host1'} + ], + dbHosts: { + 'host2': {} + } + }, + result: { + 'host2': {} + } + }, + { + title: 'Passed host match host in db', + content: { + hosts: [ + {hostName: 'host1'} + ], + dbHosts: { + 'host1': {} + } + }, + result: {} + } + ]; + testCases.forEach(function (test) { + it(test.title, function () { + controller.set('testDBHosts', test.content.dbHosts); + controller.removeHosts(test.content.hosts); + expect(controller.setDBProperty.calledWith('hosts', test.result)).to.be.true; + }); + }); + }); + + describe('#saveClients()', function () { + + var modelSetup = require('test/init_model_test'); + var testCases = [ + { + title: 'No services', + services: [], + result: [] + }, + { + title: 'No selected services', + services: [ + {isSelected: false} + ], + result: [] + }, + { + title: 'Service is not in stack', + services: [ + { + serviceName: 'TEST', + isSelected: true + } + ], + result: [] + }, + { + title: 'Service does not have any clients', + services: [ + { + serviceName: 'GANGLIA', + isSelected: true + } + ], + result: [] + }, + { + title: 'StackServiceComponent is empty', + services: [ + { + serviceName: 'HDFS', + isSelected: true + } + ], + result: [] + } + ]; + + testCases.forEach(function (test) { + it(test.title, function () { + controller.set('content.services', test.services); + controller.saveClients(); + expect(controller.setDBProperty.calledWith('clientInfo', test.result)).to.be.true; + expect(controller.get('content.clients')).to.be.empty; + }); + }); + + it('HDFS has uninstalled client', function () { + modelSetup.setupStackServiceComponent(); + var services = [ + { + serviceName: 'HDFS', + isSelected: true + } + ]; + controller.set('content.services', services); + controller.saveClients(); + expect(controller.get('content.clients')).to.eql([ + { + component_name: 'HDFS_CLIENT', + display_name: 'HDFS Client', + isInstalled: false + } + ]); + expect(controller.setDBProperty.calledWith('clientInfo', [ + { + component_name: 'HDFS_CLIENT', + display_name: 'HDFS Client', + isInstalled: false + } + ])).to.be.true; + modelSetup.cleanStackServiceComponent(); + }); + it('HDFS has installed client', function () { + modelSetup.setupStackServiceComponent(); + var services = [ + { + serviceName: 'HDFS', + isSelected: true + } + ]; + App.store.load(App.HostComponent, { + id: 'HDFS_CLIENT_host1', + component_name: "HDFS_CLIENT" + }); + controller.set('content.services', services); + controller.saveClients(); + expect(controller.get('content.clients')).to.eql([ + { + component_name: 'HDFS_CLIENT', + display_name: 'HDFS Client', + isInstalled: true + } + ]); + expect(controller.setDBProperty.calledWith('clientInfo', [ + { + component_name: 'HDFS_CLIENT', + display_name: 'HDFS Client', + isInstalled: true + } + ])).to.be.true; + modelSetup.cleanStackServiceComponent(); + }); + }); + + describe('#applyConfigGroup()', function () { + + beforeEach(function () { + sinon.spy(App.ajax, "send"); + }); + afterEach(function () { + App.ajax.send.restore(); + }); + + it('No config groups', function () { + controller.set('content.serviceConfigGroups', []); + controller.applyConfigGroup(); + expect(App.ajax.send.called).to.be.false; + }); + it('Selected group has no groups', function () { + var serviceConfigGroups = [ + { + configGroups: [], + selectedConfigGroup: '' + } + ]; + controller.set('content.serviceConfigGroups', serviceConfigGroups); + controller.applyConfigGroup(); + expect(App.ajax.send.called).to.be.false; + }); + it('Selected group does not match groups', function () { + var serviceConfigGroups = [ + { + configGroups: [ + { + ConfigGroup: { + group_name: 'group1' + } + } + ], + selectedConfigGroup: 'group2' + } + ]; + controller.set('content.serviceConfigGroups', serviceConfigGroups); + controller.applyConfigGroup(); + expect(App.ajax.send.called).to.be.false; + }); + it('Selected group has zero hosts', function () { + var serviceConfigGroups = [ + { + configGroups: [ + { + ConfigGroup: { + group_name: 'group1', + hosts: [] + }, + href: 'href' + } + ], + hosts: [], + selectedConfigGroup: 'group1' + } + ]; + controller.set('content.serviceConfigGroups', serviceConfigGroups); + controller.applyConfigGroup(); + expect(serviceConfigGroups[0].configGroups[0].ConfigGroup.hosts).to.be.empty; + expect(serviceConfigGroups[0].configGroups[0].href).to.be.undefined; + expect(App.ajax.send.calledOnce).to.be.true; + }); + it('Selected group has host', function () { + var serviceConfigGroups = [ + { + configGroups: [ + { + ConfigGroup: { + group_name: 'group1', + hosts: [] + }, + href: 'href' + } + ], + hosts: ['host1'], + selectedConfigGroup: 'group1' + } + ]; + controller.set('content.serviceConfigGroups', serviceConfigGroups); + controller.applyConfigGroup(); + expect(serviceConfigGroups[0].configGroups[0].ConfigGroup.hosts).to.eql([ + {host_name: 'host1'} + ]); + expect(serviceConfigGroups[0].configGroups[0].href).to.be.undefined; + expect(App.ajax.send.calledOnce).to.be.true; + }); + }); + + describe('#sortServiceConfigGroups()', function () { + var testCases = [ + { + title: 'No selected services', + selectedServices: [ + {configGroups: []} + ], + result: [ + {configGroups: []} + ] + }, + { + title: 'Only one group is present', + selectedServices: [ + {configGroups: [ + {configGroups: {group_name: 'b'}} + ]} + ], + result: [ + {configGroups: [ + {configGroups: {group_name: 'b'}} + ]} + ] + }, + { + title: 'Reverse order of groups', + selectedServices: [ + {configGroups: [ + {ConfigGroup: {group_name: 'b2'}}, + {ConfigGroup: {group_name: 'a1'}} + ]} + ], + result: [ + {configGroups: [ + {ConfigGroup: {group_name: 'a1'}}, + {ConfigGroup: {group_name: 'b2'}} + ]} + ] + }, + { + title: 'Correct order of groups', + selectedServices: [ + {configGroups: [ + {ConfigGroup: {group_name: 'a1'}}, + {ConfigGroup: {group_name: 'b2'}} + ]} + ], + result: [ + {configGroups: [ + {ConfigGroup: {group_name: 'a1'}}, + {ConfigGroup: {group_name: 'b2'}} + ]} + ] + } + ]; + + testCases.forEach(function (test) { + it(test.title, function () { + controller.sortServiceConfigGroups(test.selectedServices); + expect(test.selectedServices).to.eql(test.result); + }); + }); + }); + + describe('#loadServiceConfigGroupsBySlaves()', function () { + var testCases = [ + { + title: 'slaveComponentHosts is null', + slaveComponentHosts: null, + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'slaveComponentHosts is empty', + slaveComponentHosts: [], + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'Component does not have hosts', + slaveComponentHosts: [ + {hosts: []} + ], + result: { + output: true, + selectedServices: [] + } + }, + { + title: 'Only client component is present', + slaveComponentHosts: [ + { + hosts: [ + {hostName: 'host1'} + ], + componentName: 'CLIENT' + } + ], + result: { + output: true, + selectedServices: [] + } + }, + { + title: 'Slave component is present', + slaveComponentHosts: [ + { + hosts: [ + {hostName: 'host1'} + ], + componentName: 'DATANODE' + } + ], + result: { + output: true, + selectedServices: [ + { + serviceId: 'HDFS', + displayName: 'HDFS', + hosts: ['host1'], + configGroupsNames: ['HDFS Default', 'HDFS test'], + configGroups: [ + { + ConfigGroup: { + tag: 'HDFS', + group_name: 'HDFS test' + } + } + ], + selectedConfigGroup: 'HDFS Default' + } + ] + } + } + ]; + + controller.set('content.configGroups', [ + { + ConfigGroup: { + tag: 'HDFS', + group_name: 'HDFS test' + } + } + ]); + testCases.forEach(function (test) { + it(test.title, function () { + var selectedServices = []; + controller.set('content.slaveComponentHosts', test.slaveComponentHosts); + expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.equal(test.result.output); + expect(selectedServices).to.eql(test.result.selectedServices); + }); + }); + }); + + describe('#loadServiceConfigGroupsByClients()', function () { + var testCases = [ + { + title: 'slaveComponentHosts is null', + content: { + slaveComponentHosts: null, + clients: [], + selectedServices: [] + }, + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'slaveComponentHosts is empty', + content: { + slaveComponentHosts: [], + clients: [], + selectedServices: [] + }, + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'Client does not have hosts', + content: { + slaveComponentHosts: [ + { + componentName: 'CLIENT', + hosts: [] + } + ], + clients: [], + selectedServices: [] + }, + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'Client has hosts, but clients is empty', + content: { + slaveComponentHosts: [ + { + componentName: 'CLIENT', + hosts: [ + {hostName: 'host1'} + ] + } + ], + clients: [], + selectedServices: [] + }, + result: { + output: false, + selectedServices: [] + } + }, + { + title: 'Client is present', + content: { + slaveComponentHosts: [ + { + componentName: 'CLIENT', + hosts: [ + {hostName: 'host1'} + ] + } + ], + clients: [ + { + component_name: 'HDFS_CLIENT' + } + ], + selectedServices: [] + }, + result: { + output: true, + selectedServices: [ + { + serviceId: 'HDFS', + displayName: 'HDFS', + hosts: ['host1'], + configGroupsNames: ['HDFS Default', 'HDFS test'], + configGroups: [ + { + ConfigGroup: { + tag: 'HDFS', + group_name: 'HDFS test' + } + } + ], + selectedConfigGroup: 'HDFS Default' + } + ] + } + } + ]; + + testCases.forEach(function (test) { + it(test.title, function () { + controller.set('content.slaveComponentHosts', test.content.slaveComponentHosts); + controller.set('content.clients', test.content.clients); + expect(controller.loadServiceConfigGroupsByClients(test.content.selectedServices)).to.equal(test.result.output); + expect(test.content.selectedServices).to.eql(test.result.selectedServices); + }); + }); + }); + + describe('#installServices()', function () { + + beforeEach(function () { + sinon.spy(App.ajax, "send"); + }); + afterEach(function () { + App.ajax.send.restore(); + }); + + it('No hosts', function () { + controller.set('content.cluster', {name: 'cl'}); + controller.set('testDBHosts', {}); + expect(controller.installServices()).to.be.false; + expect(App.ajax.send.called).to.be.false; + }); + it('Cluster name is empty', function () { + controller.set('content.cluster', {name: ''}); + controller.set('testDBHosts', {'host1': {}}); + expect(controller.installServices()).to.be.false; + expect(App.ajax.send.called).to.be.false; + }); + it('Cluster name is correct and hosts are present', function () { + controller.set('content.cluster', {name: 'cl'}); + controller.set('testDBHosts', {'host1': {}}); + expect(controller.installServices()).to.be.true; + expect(App.ajax.send.called).to.be.true; + }); + it('Cluster name is correct and hosts are present, isRetry = true', function () { + controller.set('content.cluster', {name: 'cl'}); + controller.set('testDBHosts', {'host1': {}}); + expect(controller.installServices(true)).to.be.true; + expect(App.ajax.send.called).to.be.true; + }); + }); +});