step2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
  21. name: 'mainAdminSecurityAddStep2Controller',
  22. isRecommendedLoaded: true,
  23. stepConfigs: [],
  24. installedServices: [],
  25. selectedService: null,
  26. securityUsers: [],
  27. filter: '',
  28. filterColumns: [],
  29. /**
  30. * map which depict connection between config and slave component
  31. * in order to set component hosts to config value
  32. */
  33. slaveComponentMap: [
  34. {
  35. serviceName: 'HDFS',
  36. configName: 'datanode_hosts',
  37. component: 'DATANODE'
  38. },
  39. {
  40. serviceName: 'MAPREDUCE',
  41. configName: 'tasktracker_hosts',
  42. component: 'TASKTRACKER'
  43. },
  44. {
  45. serviceName: 'YARN',
  46. configName: 'nodemanager_host',
  47. component: 'NODEMANAGER'
  48. },
  49. {
  50. serviceName: 'HBASE',
  51. configName: 'regionserver_hosts',
  52. component: 'HBASE_REGIONSERVER'
  53. },
  54. {
  55. serviceName: 'STORM',
  56. configName: 'supervisor_hosts',
  57. component: 'SUPERVISOR'
  58. }
  59. ],
  60. /**
  61. * map which depict connection between config and master component
  62. * in order to set component hosts to config value
  63. */
  64. masterComponentMap: [
  65. {
  66. serviceName: 'OOZIE',
  67. configName: 'oozie_servername',
  68. components: ['OOZIE_SERVER']
  69. },
  70. {
  71. serviceName: 'HIVE',
  72. configName: 'hive_metastore',
  73. components: ['HIVE_SERVER']
  74. },
  75. {
  76. serviceName: 'HIVE',
  77. configName: 'webhcatserver_host',
  78. components: ['WEBHCAT_SERVER']
  79. },
  80. {
  81. serviceName: 'NAGIOS',
  82. configName: 'nagios_server',
  83. components: ['NAGIOS_SERVER']
  84. },
  85. {
  86. serviceName: 'HDFS',
  87. configName: 'namenode_host',
  88. components: ['NAMENODE']
  89. },
  90. {
  91. serviceName: 'HDFS',
  92. configName: 'snamenode_host',
  93. components: ['SECONDARY_NAMENODE']
  94. },
  95. {
  96. serviceName: 'HDFS',
  97. configName: 'journalnode_hosts',
  98. components: ['JOURNALNODE']
  99. },
  100. {
  101. serviceName: 'MAPREDUCE',
  102. configName: 'jobtracker_host',
  103. components: ['JOBTRACKER']
  104. },
  105. {
  106. serviceName: 'MAPREDUCE',
  107. configName: 'jobhistoryserver_host',
  108. components: ['HISTORYSERVER']
  109. },
  110. {
  111. serviceName: 'MAPREDUCE2',
  112. configName: 'jobhistoryserver_host',
  113. components: ['HISTORYSERVER']
  114. },
  115. {
  116. serviceName: 'YARN',
  117. configName: 'resourcemanager_host',
  118. components: ['RESOURCEMANAGER']
  119. },
  120. {
  121. serviceName: 'HBASE',
  122. configName: 'hbasemaster_host',
  123. components: ['HBASE_MASTER']
  124. },
  125. {
  126. serviceName: 'ZOOKEEPER',
  127. configName: 'zookeeperserver_hosts',
  128. components: ['ZOOKEEPER_SERVER']
  129. },
  130. {
  131. serviceName: 'FALCON',
  132. configName: 'falcon_server_host',
  133. components: ['FALCON_SERVER']
  134. },
  135. {
  136. serviceName: 'STORM',
  137. configName: 'storm_host',
  138. components: ['STORM_UI_SERVER', 'NIMBUS', 'SUPERVISOR']
  139. },
  140. {
  141. serviceName: 'STORM',
  142. configName: 'nimbus_host',
  143. components: ['NIMBUS']
  144. },
  145. {
  146. serviceName: 'KNOX',
  147. configName: 'knox_gateway_hosts',
  148. components: ['KNOX_GATEWAY']
  149. }
  150. ],
  151. hostToPrincipalMap: [
  152. {
  153. serviceName: 'OOZIE',
  154. configName: 'oozie_servername',
  155. principalName: 'oozie_principal_name',
  156. primaryName: 'oozie/'
  157. },
  158. {
  159. serviceName: 'OOZIE',
  160. configName: 'oozie_servername',
  161. principalName: 'oozie_http_principal_name',
  162. primaryName: 'HTTP/'
  163. },
  164. {
  165. serviceName: 'FALCON',
  166. configName: 'falcon_server_host',
  167. principalName: 'falcon_principal_name',
  168. primaryName: 'falcon/'
  169. },
  170. {
  171. serviceName: 'FALCON',
  172. configName: 'falcon_server_host',
  173. principalName: 'falcon_http_principal_name',
  174. primaryName: 'HTTP/'
  175. },
  176. {
  177. serviceName: 'HIVE',
  178. configName: 'webhcatserver_host',
  179. principalName: 'webHCat_http_principal_name',
  180. primaryName: 'HTTP/'
  181. },
  182. {
  183. serviceName: 'NAGIOS',
  184. configName: 'nagios_server',
  185. principalName: 'nagios_principal_name',
  186. primaryName: 'nagios/'
  187. }
  188. ],
  189. isSubmitDisabled: function () {
  190. return !this.get('stepConfigs').filterProperty('showConfig').everyProperty('errorCount', 0);
  191. }.property('stepConfigs.@each.errorCount'),
  192. /**
  193. * clear info of step
  194. */
  195. clearStep: function () {
  196. this.get('stepConfigs').clear();
  197. this.get('securityUsers').clear();
  198. },
  199. /**
  200. * Function is called whenever the step is loaded
  201. */
  202. loadStep: function () {
  203. console.log("TRACE: Loading addSecurity step2: Configure Services");
  204. var versionNumber = App.get('currentStackVersionNumber');
  205. if( stringUtils.compareVersions(versionNumber, "2.2") >= 0){
  206. // Add Nimbus config options
  207. var masterComponentMap = this.get('masterComponentMap');
  208. masterComponentMap.filterProperty('configName', 'storm_host').components = ["SUPERVISOR", "STORM_UI_SERVER", "DRPC_SERVER", "STORM_REST_API"];
  209. masterComponentMap.pushObject({
  210. serviceName: 'STORM',
  211. configName: 'nimbus_host',
  212. components: ['NIMBUS']
  213. });
  214. this.get('hostToPrincipalMap').pushObject({
  215. serviceName: 'STORM',
  216. configName: 'nimbus_host',
  217. principalName: 'storm_principal_name',
  218. primaryName: 'storm'
  219. });
  220. }
  221. this.clearStep();
  222. this.loadUsers();
  223. this.addUserPrincipals(this.get('content.services'), this.get('securityUsers'));
  224. this.addMasterHostToConfigs();
  225. this.addHostPrincipals();
  226. this.addSlaveHostToConfigs();
  227. this.renderServiceConfigs(this.get('content.services'));
  228. this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
  229. this.setStoredConfigsValue(this.get('content.serviceConfigProperties'));
  230. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  231. },
  232. /**
  233. * set stored values to service configs
  234. * @param storedConfigProperties
  235. * @return {Boolean}
  236. */
  237. setStoredConfigsValue: function (storedConfigProperties) {
  238. if (!storedConfigProperties) return false;
  239. // for all services`
  240. this.get('stepConfigs').forEach(function (_content) {
  241. _content.get('configs').forEach(function (_config) {
  242. var configProperty = storedConfigProperties.findProperty('name', _config.get('name'));
  243. if (configProperty) {
  244. _config.set('value', configProperty.value);
  245. }
  246. }, this);
  247. }, this);
  248. return true;
  249. },
  250. /**
  251. * Render configs for active services
  252. * @param serviceConfigs
  253. */
  254. renderServiceConfigs: function (serviceConfigs) {
  255. serviceConfigs.forEach(function (_serviceConfig) {
  256. var serviceConfig = App.ServiceConfig.create({
  257. filename: _serviceConfig.filename,
  258. serviceName: _serviceConfig.serviceName,
  259. displayName: _serviceConfig.displayName,
  260. configCategories: _serviceConfig.configCategories,
  261. showConfig: true,
  262. configs: this.wrapConfigProperties(_serviceConfig)
  263. });
  264. this.get('stepConfigs').pushObject(serviceConfig);
  265. }, this);
  266. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig').objectAt(0));
  267. },
  268. /**
  269. * wrap configs into App.ServiceConfigProperty objects
  270. * @param _componentConfig
  271. */
  272. wrapConfigProperties: function (_componentConfig) {
  273. var configs = [];
  274. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  275. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  276. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  277. serviceConfigProperty.validate();
  278. configs.pushObject(serviceConfigProperty);
  279. }, this);
  280. return configs;
  281. },
  282. /**
  283. * fill config with hosts of component
  284. * @param serviceName
  285. * @param configName
  286. * @param componentNames
  287. * @return {Boolean}
  288. */
  289. setHostsToConfig: function (serviceName, configName, componentNames) {
  290. var service = this.get('content.services').findProperty('serviceName', serviceName);
  291. if (service) {
  292. var hosts = service.configs.findProperty('name', configName);
  293. if (hosts) {
  294. hosts.defaultValue = App.Service.find(service.serviceName)
  295. .get('hostComponents')
  296. .filter(function (component) {
  297. return componentNames.contains(component.get('componentName'));
  298. })
  299. .mapProperty('hostName')
  300. .uniq();
  301. return true;
  302. }
  303. return false;
  304. }
  305. return false;
  306. },
  307. /**
  308. * set principal default value based on config host and default primary name
  309. * @param serviceName
  310. * @param hostConfigName
  311. * @param principalConfigName
  312. * @param defaultPrimaryName
  313. * @return {Boolean}
  314. */
  315. setHostToPrincipal: function (serviceName, hostConfigName, principalConfigName, defaultPrimaryName) {
  316. var service = this.get('content.services').findProperty('serviceName', serviceName);
  317. if (service) {
  318. var host = service.configs.findProperty('name', hostConfigName);
  319. var principal = service.configs.findProperty('name', principalConfigName);
  320. var versionNumber = App.get('currentStackVersionNumber');
  321. if(principalConfigName == 'storm_principal_name' && stringUtils.compareVersions(versionNumber, "2.2") >= 0){
  322. principal.defaultValue = defaultPrimaryName;
  323. return true;
  324. } else if (host && principal) {
  325. var host_defaultValue = Array.isArray(host.defaultValue) ? host.defaultValue[0] : host.defaultValue;
  326. principal.defaultValue = defaultPrimaryName + host_defaultValue;
  327. return true;
  328. }
  329. return false;
  330. }
  331. return false;
  332. },
  333. /**
  334. * load services users
  335. */
  336. loadUsers: function () {
  337. var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  338. if (Em.isNone(securityUsers) || securityUsers.length === 0) {
  339. if (App.get('testMode')) {
  340. securityUsers = securityUsers || [];
  341. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  342. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  343. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  344. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  345. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  346. } else {
  347. securityUsers = App.db.getSecureUserInfo();
  348. }
  349. }
  350. this.set('securityUsers', securityUsers);
  351. },
  352. /**
  353. * set default values to user principals and control their visibility
  354. * @param serviceConfigs
  355. * @param securityUsers
  356. */
  357. addUserPrincipals: function (serviceConfigs, securityUsers) {
  358. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL').configs;
  359. this.setUserPrincipalValue(securityUsers.findProperty('name', 'smokeuser'), generalService.findProperty('name', 'smokeuser_principal_name'));
  360. var servicesWithUserPrincipals = ['HDFS', 'HBASE'];
  361. servicesWithUserPrincipals.forEach(function (serviceName) {
  362. var isServiceInstalled = serviceConfigs.someProperty('serviceName', serviceName);
  363. var userPrincipal = generalService.findProperty('name', serviceName.toLowerCase() + '_principal_name');
  364. var userKeytab = generalService.findProperty('name', serviceName.toLowerCase() + '_user_keytab');
  365. var userName = securityUsers.findProperty('name', serviceName.toLowerCase() + '_user');
  366. if (isServiceInstalled && this.setUserPrincipalValue(userName, userPrincipal)) {
  367. userPrincipal.isVisible = true;
  368. userKeytab.isVisible = true;
  369. }
  370. }, this);
  371. },
  372. /**
  373. * set default value of user principal
  374. * @param user
  375. * @param userPrincipal
  376. */
  377. setUserPrincipalValue: function (user, userPrincipal) {
  378. if (user && userPrincipal) {
  379. userPrincipal.defaultValue = user.value;
  380. return true;
  381. }
  382. return false;
  383. },
  384. /**
  385. * put hosts of slave component into defaultValue of configs
  386. */
  387. addSlaveHostToConfigs: function () {
  388. this.get('slaveComponentMap').forEach(function (service) {
  389. this.setHostsToConfig(service.serviceName, service.configName, [service.component]);
  390. }, this);
  391. },
  392. /**
  393. * put hosts of master component into defaultValue of configs
  394. */
  395. addMasterHostToConfigs: function () {
  396. this.get('masterComponentMap').forEach(function (item) {
  397. this.setHostsToConfig(item.serviceName, item.configName, item.components);
  398. }, this);
  399. },
  400. /**
  401. * put hosts to principal default values
  402. */
  403. addHostPrincipals: function () {
  404. this.get('hostToPrincipalMap').forEach(function (item) {
  405. this.setHostToPrincipal(item.serviceName, item.configName, item.principalName, item.primaryName);
  406. }, this);
  407. },
  408. /**
  409. * modify config categories depending on whether HA is enabled or not
  410. * @param serviceConfigs
  411. * @param stepConfigs
  412. */
  413. changeCategoryOnHa: function (serviceConfigs, stepConfigs) {
  414. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  415. if (hdfsService) {
  416. var properties = stepConfigs.findProperty('serviceName', 'HDFS').get('configs');
  417. var configCategories = hdfsService.configCategories;
  418. if ((App.get('testMode') && App.get('testNameNodeHA')) || (this.get('content.isNnHa') === 'true')) {
  419. this.removeConfigCategory(properties, configCategories, 'SNameNode');
  420. } else {
  421. this.removeConfigCategory(properties, configCategories, 'JournalNode');
  422. }
  423. return true;
  424. }
  425. return false;
  426. },
  427. /**
  428. * remove config category that belong to component and hide category configs
  429. * @param properties
  430. * @param configCategories
  431. * @param component
  432. */
  433. removeConfigCategory: function (properties, configCategories, component) {
  434. properties.filterProperty('category', component).forEach(function (_snConfig) {
  435. _snConfig.set('isVisible', false);
  436. }, this);
  437. var category = configCategories.findProperty('name', component);
  438. if (category) {
  439. configCategories.removeObject(category);
  440. }
  441. }
  442. });