step2.js 13 KB

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