step2.js 13 KB

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