step2.js 13 KB

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