step2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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: 'YARN',
  122. configName: 'apptimelineserver_host',
  123. components: ['APP_TIMELINE_SERVER']
  124. },
  125. {
  126. serviceName: 'HBASE',
  127. configName: 'hbasemaster_host',
  128. components: ['HBASE_MASTER']
  129. },
  130. {
  131. serviceName: 'ZOOKEEPER',
  132. configName: 'zookeeperserver_hosts',
  133. components: ['ZOOKEEPER_SERVER']
  134. },
  135. {
  136. serviceName: 'FALCON',
  137. configName: 'falcon_server_host',
  138. components: ['FALCON_SERVER']
  139. },
  140. {
  141. serviceName: 'STORM',
  142. configName: 'storm_host',
  143. components: ['STORM_UI_SERVER', 'NIMBUS', 'SUPERVISOR']
  144. },
  145. {
  146. serviceName: 'STORM',
  147. configName: 'nimbus_host',
  148. components: ['NIMBUS']
  149. },
  150. {
  151. serviceName: 'KNOX',
  152. configName: 'knox_gateway_hosts',
  153. components: ['KNOX_GATEWAY']
  154. }
  155. ],
  156. hostToPrincipalMap: [
  157. {
  158. serviceName: 'OOZIE',
  159. configName: 'oozie_servername',
  160. principalName: 'oozie_principal_name',
  161. primaryName: 'oozie/'
  162. },
  163. {
  164. serviceName: 'OOZIE',
  165. configName: 'oozie_servername',
  166. principalName: 'oozie_http_principal_name',
  167. primaryName: 'HTTP/'
  168. },
  169. {
  170. serviceName: 'FALCON',
  171. configName: 'falcon_server_host',
  172. principalName: 'falcon_principal_name',
  173. primaryName: 'falcon/'
  174. },
  175. {
  176. serviceName: 'FALCON',
  177. configName: 'falcon_server_host',
  178. principalName: 'falcon_http_principal_name',
  179. primaryName: 'HTTP/'
  180. },
  181. {
  182. serviceName: 'HIVE',
  183. configName: 'webhcatserver_host',
  184. principalName: 'webHCat_http_principal_name',
  185. primaryName: 'HTTP/'
  186. },
  187. {
  188. serviceName: 'NAGIOS',
  189. configName: 'nagios_server',
  190. principalName: 'nagios_principal_name',
  191. primaryName: 'nagios/'
  192. }
  193. ],
  194. isSubmitDisabled: function () {
  195. return !this.get('stepConfigs').filterProperty('showConfig').everyProperty('errorCount', 0);
  196. }.property('stepConfigs.@each.errorCount'),
  197. /**
  198. * clear info of step
  199. */
  200. clearStep: function () {
  201. this.get('stepConfigs').clear();
  202. this.get('securityUsers').clear();
  203. },
  204. /**
  205. * Function is called whenever the step is loaded
  206. */
  207. loadStep: function () {
  208. console.log("TRACE: Loading addSecurity step2: Configure Services");
  209. var versionNumber = App.get('currentStackVersionNumber');
  210. if( stringUtils.compareVersions(versionNumber, "2.2") >= 0){
  211. // Add Nimbus config options
  212. var masterComponentMap = this.get('masterComponentMap');
  213. masterComponentMap.filterProperty('configName', 'storm_host').components = ["SUPERVISOR", "STORM_UI_SERVER", "DRPC_SERVER", "STORM_REST_API"];
  214. masterComponentMap.pushObject({
  215. serviceName: 'STORM',
  216. configName: 'nimbus_host',
  217. components: ['NIMBUS']
  218. });
  219. this.get('hostToPrincipalMap').pushObject({
  220. serviceName: 'STORM',
  221. configName: 'nimbus_host',
  222. principalName: 'storm_principal_name',
  223. primaryName: 'storm'
  224. });
  225. }
  226. this.clearStep();
  227. this.loadUsers();
  228. this.addUserPrincipals(this.get('content.services'), this.get('securityUsers'));
  229. this.addMasterHostToConfigs();
  230. this.addHostPrincipals();
  231. this.addSlaveHostToConfigs();
  232. this.renderServiceConfigs(this.get('content.services'));
  233. this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
  234. this.setStoredConfigsValue(this.get('content.serviceConfigProperties'));
  235. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  236. },
  237. /**
  238. * set stored values to service configs
  239. * @param storedConfigProperties
  240. * @return {Boolean}
  241. */
  242. setStoredConfigsValue: function (storedConfigProperties) {
  243. if (!storedConfigProperties) return false;
  244. // for all services`
  245. this.get('stepConfigs').forEach(function (_content) {
  246. _content.get('configs').forEach(function (_config) {
  247. var configProperty = storedConfigProperties.findProperty('name', _config.get('name'));
  248. if (configProperty) {
  249. _config.set('value', configProperty.value);
  250. }
  251. }, this);
  252. }, this);
  253. return true;
  254. },
  255. /**
  256. * Render configs for active services
  257. * @param serviceConfigs
  258. */
  259. renderServiceConfigs: function (serviceConfigs) {
  260. serviceConfigs.forEach(function (_serviceConfig) {
  261. var serviceConfig = App.ServiceConfig.create({
  262. filename: _serviceConfig.filename,
  263. serviceName: _serviceConfig.serviceName,
  264. displayName: _serviceConfig.displayName,
  265. configCategories: _serviceConfig.configCategories,
  266. showConfig: true,
  267. configs: this.wrapConfigProperties(_serviceConfig)
  268. });
  269. this.get('stepConfigs').pushObject(serviceConfig);
  270. }, this);
  271. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig').objectAt(0));
  272. },
  273. /**
  274. * wrap configs into App.ServiceConfigProperty objects
  275. * @param _componentConfig
  276. */
  277. wrapConfigProperties: function (_componentConfig) {
  278. var configs = [];
  279. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  280. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  281. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  282. serviceConfigProperty.validate();
  283. configs.pushObject(serviceConfigProperty);
  284. }, this);
  285. return configs;
  286. },
  287. /**
  288. * fill config with hosts of component
  289. * @param serviceName
  290. * @param configName
  291. * @param componentNames
  292. * @return {Boolean}
  293. */
  294. setHostsToConfig: function (serviceName, configName, componentNames) {
  295. var service = this.get('content.services').findProperty('serviceName', serviceName);
  296. if (service) {
  297. var hosts = service.configs.findProperty('name', configName);
  298. if (hosts) {
  299. hosts.defaultValue = App.Service.find(service.serviceName)
  300. .get('hostComponents')
  301. .filter(function (component) {
  302. return componentNames.contains(component.get('componentName'));
  303. })
  304. .mapProperty('hostName')
  305. .uniq();
  306. return true;
  307. }
  308. return false;
  309. }
  310. return false;
  311. },
  312. /**
  313. * set principal default value based on config host and default primary name
  314. * @param serviceName
  315. * @param hostConfigName
  316. * @param principalConfigName
  317. * @param defaultPrimaryName
  318. * @return {Boolean}
  319. */
  320. setHostToPrincipal: function (serviceName, hostConfigName, principalConfigName, defaultPrimaryName) {
  321. var service = this.get('content.services').findProperty('serviceName', serviceName);
  322. if (service) {
  323. var host = service.configs.findProperty('name', hostConfigName);
  324. var principal = service.configs.findProperty('name', principalConfigName);
  325. var versionNumber = App.get('currentStackVersionNumber');
  326. var special22ConfigsMap = {
  327. storm_principal_name: defaultPrimaryName,
  328. oozie_http_principal_name: defaultPrimaryName + '_HOST'
  329. };
  330. if (stringUtils.compareVersions(versionNumber, "2.2") >= 0 && special22ConfigsMap[principalConfigName]) {
  331. principal.defaultValue = special22ConfigsMap[principalConfigName];
  332. return true;
  333. }
  334. if (host && principal) {
  335. var host_defaultValue = Array.isArray(host.defaultValue) ? host.defaultValue[0] : host.defaultValue;
  336. principal.defaultValue = defaultPrimaryName + host_defaultValue;
  337. return true;
  338. }
  339. return false;
  340. }
  341. return false;
  342. },
  343. /**
  344. * load services users
  345. */
  346. loadUsers: function () {
  347. var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  348. if (Em.isNone(securityUsers) || securityUsers.length === 0) {
  349. if (App.get('testMode')) {
  350. securityUsers = securityUsers || [];
  351. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  352. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  353. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  354. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  355. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  356. } else {
  357. securityUsers = App.db.getSecureUserInfo();
  358. }
  359. }
  360. this.set('securityUsers', securityUsers);
  361. },
  362. /**
  363. * set default values to user principals and control their visibility
  364. * @param serviceConfigs
  365. * @param securityUsers
  366. */
  367. addUserPrincipals: function (serviceConfigs, securityUsers) {
  368. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL').configs;
  369. this.setUserPrincipalValue(securityUsers.findProperty('name', 'smokeuser'), generalService.findProperty('name', 'smokeuser_principal_name'));
  370. var servicesWithUserPrincipals = ['HDFS', 'HBASE'];
  371. servicesWithUserPrincipals.forEach(function (serviceName) {
  372. var isServiceInstalled = serviceConfigs.someProperty('serviceName', serviceName);
  373. var userPrincipal = generalService.findProperty('name', serviceName.toLowerCase() + '_principal_name');
  374. var userKeytab = generalService.findProperty('name', serviceName.toLowerCase() + '_user_keytab');
  375. var userName = securityUsers.findProperty('name', serviceName.toLowerCase() + '_user');
  376. if (isServiceInstalled && this.setUserPrincipalValue(userName, userPrincipal)) {
  377. userPrincipal.isVisible = true;
  378. userKeytab.isVisible = true;
  379. }
  380. }, this);
  381. },
  382. /**
  383. * set default value of user principal
  384. * @param user
  385. * @param userPrincipal
  386. */
  387. setUserPrincipalValue: function (user, userPrincipal) {
  388. if (user && userPrincipal) {
  389. userPrincipal.defaultValue = user.value;
  390. return true;
  391. }
  392. return false;
  393. },
  394. /**
  395. * put hosts of slave component into defaultValue of configs
  396. */
  397. addSlaveHostToConfigs: function () {
  398. this.get('slaveComponentMap').forEach(function (service) {
  399. this.setHostsToConfig(service.serviceName, service.configName, [service.component]);
  400. }, this);
  401. },
  402. /**
  403. * put hosts of master component into defaultValue of configs
  404. */
  405. addMasterHostToConfigs: function () {
  406. this.get('masterComponentMap').forEach(function (item) {
  407. this.setHostsToConfig(item.serviceName, item.configName, item.components);
  408. }, this);
  409. },
  410. /**
  411. * put hosts to principal default values
  412. */
  413. addHostPrincipals: function () {
  414. this.get('hostToPrincipalMap').forEach(function (item) {
  415. this.setHostToPrincipal(item.serviceName, item.configName, item.principalName, item.primaryName);
  416. }, this);
  417. },
  418. /**
  419. * modify config categories depending on whether HA is enabled or not
  420. * @param serviceConfigs
  421. * @param stepConfigs
  422. */
  423. changeCategoryOnHa: function (serviceConfigs, stepConfigs) {
  424. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  425. if (hdfsService) {
  426. var properties = stepConfigs.findProperty('serviceName', 'HDFS').get('configs');
  427. var configCategories = hdfsService.configCategories;
  428. if ((App.get('testMode') && App.get('testNameNodeHA')) || (this.get('content.isNnHa') === 'true')) {
  429. this.removeConfigCategory(properties, configCategories, 'SNameNode');
  430. } else {
  431. this.removeConfigCategory(properties, configCategories, 'JournalNode');
  432. }
  433. return true;
  434. }
  435. return false;
  436. },
  437. /**
  438. * remove config category that belong to component and hide category configs
  439. * @param properties
  440. * @param configCategories
  441. * @param component
  442. */
  443. removeConfigCategory: function (properties, configCategories, component) {
  444. properties.filterProperty('category', component).forEach(function (_snConfig) {
  445. _snConfig.set('isVisible', false);
  446. }, this);
  447. var category = configCategories.findProperty('name', component);
  448. if (category) {
  449. configCategories.removeObject(category);
  450. }
  451. }
  452. });