step2.js 14 KB

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