123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- /**
- * 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');
- var stringUtils = require('utils/string_utils');
- App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
- name: 'mainAdminSecurityAddStep2Controller',
- isRecommendedLoaded: true,
- stepConfigs: [],
- installedServices: [],
- selectedService: null,
- securityUsers: [],
- filter: '',
- filterColumns: [],
- /**
- * map which depict connection between config and slave component
- * in order to set component hosts to config value
- */
- slaveComponentMap: [
- {
- serviceName: 'HDFS',
- configName: 'datanode_hosts',
- component: 'DATANODE'
- },
- {
- serviceName: 'YARN',
- configName: 'nodemanager_host',
- component: 'NODEMANAGER'
- },
- {
- serviceName: 'HBASE',
- configName: 'regionserver_hosts',
- component: 'HBASE_REGIONSERVER'
- },
- {
- serviceName: 'STORM',
- configName: 'supervisor_hosts',
- component: 'SUPERVISOR'
- }
- ],
- /**
- * map which depict connection between config and master component
- * in order to set component hosts to config value
- */
- masterComponentMap: [
- {
- serviceName: 'OOZIE',
- configName: 'oozie_servername',
- components: ['OOZIE_SERVER']
- },
- {
- serviceName: 'HIVE',
- configName: 'hive_metastore',
- components: ['HIVE_METASTORE', 'HIVE_SERVER']
- },
- {
- serviceName: 'HIVE',
- configName: 'webhcatserver_host',
- components: ['WEBHCAT_SERVER']
- },
- {
- serviceName: 'HDFS',
- configName: 'namenode_host',
- components: ['NAMENODE']
- },
- {
- serviceName: 'HDFS',
- configName: 'snamenode_host',
- components: ['SECONDARY_NAMENODE']
- },
- {
- serviceName: 'HDFS',
- configName: 'journalnode_hosts',
- components: ['JOURNALNODE']
- },
- {
- serviceName: 'MAPREDUCE2',
- configName: 'jobhistoryserver_host',
- components: ['HISTORYSERVER']
- },
- {
- serviceName: 'YARN',
- configName: 'resourcemanager_host',
- components: ['RESOURCEMANAGER']
- },
- {
- serviceName: 'YARN',
- configName: 'apptimelineserver_host',
- components: ['APP_TIMELINE_SERVER']
- },
- {
- serviceName: 'HBASE',
- configName: 'hbasemaster_host',
- components: ['HBASE_MASTER']
- },
- {
- serviceName: 'ZOOKEEPER',
- configName: 'zookeeperserver_hosts',
- components: ['ZOOKEEPER_SERVER']
- },
- {
- serviceName: 'FALCON',
- configName: 'falcon_server_host',
- components: ['FALCON_SERVER']
- },
- {
- serviceName: 'STORM',
- configName: 'storm_host',
- components: ['STORM_UI_SERVER', 'NIMBUS', 'SUPERVISOR']
- },
- {
- serviceName: 'STORM',
- configName: 'nimbus_host',
- components: ['NIMBUS']
- },
- {
- serviceName: 'KNOX',
- configName: 'knox_gateway_hosts',
- components: ['KNOX_GATEWAY']
- }
- ],
- hostToPrincipalMap: [
- {
- serviceName: 'OOZIE',
- configName: 'oozie_servername',
- principalName: 'oozie_principal_name',
- primaryName: 'oozie/'
- },
- {
- serviceName: 'OOZIE',
- configName: 'oozie_servername',
- principalName: 'oozie_http_principal_name',
- primaryName: 'HTTP/'
- },
- {
- serviceName: 'FALCON',
- configName: 'falcon_server_host',
- principalName: 'falcon_principal_name',
- primaryName: 'falcon/'
- },
- {
- serviceName: 'FALCON',
- configName: 'falcon_server_host',
- principalName: 'falcon_http_principal_name',
- primaryName: 'HTTP/'
- },
- {
- serviceName: 'HIVE',
- configName: 'webhcatserver_host',
- principalName: 'webHCat_http_principal_name',
- primaryName: 'HTTP/'
- }
- ],
- isSubmitDisabled: function () {
- return !this.get('stepConfigs').filterProperty('showConfig').everyProperty('errorCount', 0);
- }.property('stepConfigs.@each.errorCount'),
- /**
- * clear info of step
- */
- clearStep: function () {
- this.get('stepConfigs').clear();
- this.get('securityUsers').clear();
- },
- /**
- * Function is called whenever the step is loaded
- */
- loadStep: function () {
- console.log("TRACE: Loading addSecurity step2: Configure Services");
- var versionNumber = App.get('currentStackVersionNumber');
- if( stringUtils.compareVersions(versionNumber, "2.2") >= 0){
- // Add Nimbus config options
- var masterComponentMap = this.get('masterComponentMap');
- masterComponentMap.filterProperty('configName', 'storm_host').components = ["SUPERVISOR", "STORM_UI_SERVER", "DRPC_SERVER", "STORM_REST_API"];
- masterComponentMap.pushObject({
- serviceName: 'STORM',
- configName: 'nimbus_host',
- components: ['NIMBUS']
- });
- this.get('hostToPrincipalMap').pushObject({
- serviceName: 'STORM',
- configName: 'nimbus_host',
- principalName: 'storm_principal_name',
- primaryName: 'storm'
- });
- }
- this.clearStep();
- this.loadUsers();
- this.addUserPrincipals(this.get('content.services'), this.get('securityUsers'));
- this.addMasterHostToConfigs();
- this.addHostPrincipals();
- this.addSlaveHostToConfigs();
- this.renderServiceConfigs(this.get('content.services'));
- this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
- this.setStoredConfigsValue(this.get('content.serviceConfigProperties'));
- this.set('installedServices', App.Service.find().mapProperty('serviceName'));
- },
- /**
- * set stored values to service configs
- * @param storedConfigProperties
- * @return {Boolean}
- */
- setStoredConfigsValue: function (storedConfigProperties) {
- if (!storedConfigProperties) return false;
- // for all services`
- this.get('stepConfigs').forEach(function (_content) {
- _content.get('configs').forEach(function (_config) {
- var configProperty = storedConfigProperties.findProperty('name', _config.get('name'));
- if (configProperty) {
- _config.set('value', configProperty.value);
- }
- }, this);
- }, this);
- return true;
- },
- /**
- * Render configs for active services
- * @param serviceConfigs
- */
- renderServiceConfigs: function (serviceConfigs) {
- serviceConfigs.forEach(function (_serviceConfig) {
- var serviceConfig = App.ServiceConfig.create({
- filename: _serviceConfig.filename,
- serviceName: _serviceConfig.serviceName,
- displayName: _serviceConfig.displayName,
- configCategories: _serviceConfig.configCategories,
- showConfig: true,
- configs: this.wrapConfigProperties(_serviceConfig)
- });
- this.get('stepConfigs').pushObject(serviceConfig);
- }, this);
- this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig').objectAt(0));
- },
- /**
- * wrap configs into App.ServiceConfigProperty objects
- * @param _componentConfig
- */
- wrapConfigProperties: function (_componentConfig) {
- var configs = [];
- _componentConfig.configs.forEach(function (_serviceConfigProperty) {
- var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
- serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
- serviceConfigProperty.validate();
- configs.pushObject(serviceConfigProperty);
- }, this);
- return configs;
- },
- /**
- * fill config with hosts of component
- * @param serviceName
- * @param configName
- * @param componentNames
- * @return {Boolean}
- */
- setHostsToConfig: function (serviceName, configName, componentNames) {
- var service = this.get('content.services').findProperty('serviceName', serviceName);
- if (service) {
- var hosts = service.configs.findProperty('name', configName);
- if (hosts) {
- hosts.defaultValue = App.Service.find(service.serviceName)
- .get('hostComponents')
- .filter(function (component) {
- return componentNames.contains(component.get('componentName'));
- })
- .mapProperty('hostName')
- .uniq();
- return true;
- }
- return false;
- }
- return false;
- },
- /**
- * set principal default value based on config host and default primary name
- * @param serviceName
- * @param hostConfigName
- * @param principalConfigName
- * @param defaultPrimaryName
- * @return {Boolean}
- */
- setHostToPrincipal: function (serviceName, hostConfigName, principalConfigName, defaultPrimaryName) {
- var service = this.get('content.services').findProperty('serviceName', serviceName);
- if (service) {
- var host = service.configs.findProperty('name', hostConfigName);
- var principal = service.configs.findProperty('name', principalConfigName);
- var versionNumber = App.get('currentStackVersionNumber');
- var special22ConfigsMap = {
- storm_principal_name: defaultPrimaryName,
- oozie_http_principal_name: defaultPrimaryName + '_HOST'
- };
- if (stringUtils.compareVersions(versionNumber, "2.2") >= 0 && special22ConfigsMap[principalConfigName]) {
- principal.defaultValue = special22ConfigsMap[principalConfigName];
- return true;
- }
- if (host && principal) {
- var host_defaultValue = Array.isArray(host.defaultValue) ? host.defaultValue[0] : host.defaultValue;
- principal.defaultValue = defaultPrimaryName + host_defaultValue;
- return true;
- }
- return false;
- }
- return false;
- },
- /**
- * load services users
- */
- loadUsers: function () {
- var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
- if (Em.isNone(securityUsers) || securityUsers.length === 0) {
- if (App.get('testMode')) {
- securityUsers = securityUsers || [];
- securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
- securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
- securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
- securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
- securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
- } else {
- securityUsers = App.db.getSecureUserInfo();
- }
- }
- this.set('securityUsers', securityUsers);
- },
- /**
- * set default values to user principals and control their visibility
- * @param serviceConfigs
- * @param securityUsers
- */
- addUserPrincipals: function (serviceConfigs, securityUsers) {
- var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL').configs;
- this.setUserPrincipalValue(securityUsers.findProperty('name', 'smokeuser'), generalService.findProperty('name', 'smokeuser_principal_name'));
- var servicesWithUserPrincipals = ['HDFS', 'HBASE'];
- servicesWithUserPrincipals.forEach(function (serviceName) {
- var isServiceInstalled = serviceConfigs.someProperty('serviceName', serviceName);
- var userPrincipal = generalService.findProperty('name', serviceName.toLowerCase() + '_principal_name');
- var userKeytab = generalService.findProperty('name', serviceName.toLowerCase() + '_user_keytab');
- var userName = securityUsers.findProperty('name', serviceName.toLowerCase() + '_user');
- if (isServiceInstalled && this.setUserPrincipalValue(userName, userPrincipal)) {
- userPrincipal.isVisible = true;
- userKeytab.isVisible = true;
- }
- }, this);
- },
- /**
- * set default value of user principal
- * @param user
- * @param userPrincipal
- */
- setUserPrincipalValue: function (user, userPrincipal) {
- if (user && userPrincipal) {
- userPrincipal.defaultValue = user.value;
- return true;
- }
- return false;
- },
- /**
- * put hosts of slave component into defaultValue of configs
- */
- addSlaveHostToConfigs: function () {
- this.get('slaveComponentMap').forEach(function (service) {
- this.setHostsToConfig(service.serviceName, service.configName, [service.component]);
- }, this);
- },
- /**
- * put hosts of master component into defaultValue of configs
- */
- addMasterHostToConfigs: function () {
- this.get('masterComponentMap').forEach(function (item) {
- this.setHostsToConfig(item.serviceName, item.configName, item.components);
- }, this);
- },
- /**
- * put hosts to principal default values
- */
- addHostPrincipals: function () {
- this.get('hostToPrincipalMap').forEach(function (item) {
- this.setHostToPrincipal(item.serviceName, item.configName, item.principalName, item.primaryName);
- }, this);
- },
- /**
- * modify config categories depending on whether HA is enabled or not
- * @param serviceConfigs
- * @param stepConfigs
- */
- changeCategoryOnHa: function (serviceConfigs, stepConfigs) {
- var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
- if (hdfsService) {
- var properties = stepConfigs.findProperty('serviceName', 'HDFS').get('configs');
- var configCategories = hdfsService.configCategories;
- if ((App.get('testMode') && App.get('testNameNodeHA')) || (this.get('content.isNnHa') === 'true')) {
- this.removeConfigCategory(properties, configCategories, 'SNameNode');
- } else {
- this.removeConfigCategory(properties, configCategories, 'JournalNode');
- }
- return true;
- }
- return false;
- },
- /**
- * remove config category that belong to component and hide category configs
- * @param properties
- * @param configCategories
- * @param component
- */
- removeConfigCategory: function (properties, configCategories, component) {
- properties.filterProperty('category', component).forEach(function (_snConfig) {
- _snConfig.set('isVisible', false);
- }, this);
- var category = configCategories.findProperty('name', component);
- if (category) {
- configCategories.removeObject(category);
- }
- }
- });
|