step2.js 15 KB

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