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: 'MAPREDUCE',
  41. configName: 'tasktracker_hosts',
  42. component: 'TASKTRACKER'
  43. },
  44. {
  45. serviceName: 'YARN',
  46. configName: 'nodemanager_host',
  47. component: 'NODEMANAGER'
  48. },
  49. {
  50. serviceName: 'HBASE',
  51. configName: 'regionserver_hosts',
  52. component: 'HBASE_REGIONSERVER'
  53. },
  54. {
  55. serviceName: 'STORM',
  56. configName: 'supervisor_hosts',
  57. component: 'SUPERVISOR'
  58. }
  59. ],
  60. /**
  61. * map which depict connection between config and master component
  62. * in order to set component hosts to config value
  63. */
  64. masterComponentMap: [
  65. {
  66. serviceName: 'OOZIE',
  67. configName: 'oozie_servername',
  68. components: ['OOZIE_SERVER']
  69. },
  70. {
  71. serviceName: 'HIVE',
  72. configName: 'hive_metastore',
  73. components: ['HIVE_SERVER']
  74. },
  75. {
  76. serviceName: 'HIVE',
  77. configName: 'webhcatserver_host',
  78. components: ['WEBHCAT_SERVER']
  79. },
  80. {
  81. serviceName: 'NAGIOS',
  82. configName: 'nagios_server',
  83. components: ['NAGIOS_SERVER']
  84. },
  85. {
  86. serviceName: 'HDFS',
  87. configName: 'namenode_host',
  88. components: ['NAMENODE']
  89. },
  90. {
  91. serviceName: 'HDFS',
  92. configName: 'snamenode_host',
  93. components: ['SECONDARY_NAMENODE']
  94. },
  95. {
  96. serviceName: 'HDFS',
  97. configName: 'journalnode_hosts',
  98. components: ['JOURNALNODE']
  99. },
  100. {
  101. serviceName: 'MAPREDUCE',
  102. configName: 'jobtracker_host',
  103. components: ['JOBTRACKER']
  104. },
  105. {
  106. serviceName: 'MAPREDUCE',
  107. configName: 'jobhistoryserver_host',
  108. components: ['HISTORYSERVER']
  109. },
  110. {
  111. serviceName: 'MAPREDUCE2',
  112. configName: 'jobhistoryserver_host',
  113. components: ['HISTORYSERVER']
  114. },
  115. {
  116. serviceName: 'YARN',
  117. configName: 'resourcemanager_host',
  118. components: ['RESOURCEMANAGER']
  119. },
  120. {
  121. serviceName: 'HBASE',
  122. configName: 'hbasemaster_host',
  123. components: ['HBASE_MASTER']
  124. },
  125. {
  126. serviceName: 'ZOOKEEPER',
  127. configName: 'zookeeperserver_hosts',
  128. components: ['ZOOKEEPER_SERVER']
  129. },
  130. {
  131. serviceName: 'FALCON',
  132. configName: 'falcon_server_host',
  133. components: ['FALCON_SERVER']
  134. },
  135. {
  136. serviceName: 'STORM',
  137. configName: 'storm_host',
  138. components: ['STORM_UI_SERVER', 'NIMBUS', 'SUPERVISOR']
  139. },
  140. {
  141. serviceName: 'STORM',
  142. configName: 'nimbus_host',
  143. components: ['NIMBUS']
  144. }
  145. ],
  146. hostToPrincipalMap: [
  147. {
  148. serviceName: 'OOZIE',
  149. configName: 'oozie_servername',
  150. principalName: 'oozie_principal_name',
  151. primaryName: 'oozie/'
  152. },
  153. {
  154. serviceName: 'OOZIE',
  155. configName: 'oozie_servername',
  156. principalName: 'oozie_http_principal_name',
  157. primaryName: 'HTTP/'
  158. },
  159. {
  160. serviceName: 'FALCON',
  161. configName: 'falcon_server_host',
  162. principalName: 'falcon_principal_name',
  163. primaryName: 'falcon/'
  164. },
  165. {
  166. serviceName: 'FALCON',
  167. configName: 'falcon_server_host',
  168. principalName: 'falcon_http_principal_name',
  169. primaryName: 'HTTP/'
  170. },
  171. {
  172. serviceName: 'HIVE',
  173. configName: 'webhcatserver_host',
  174. principalName: 'webHCat_http_principal_name',
  175. primaryName: 'HTTP/'
  176. },
  177. {
  178. serviceName: 'NAGIOS',
  179. configName: 'nagios_server',
  180. principalName: 'nagios_principal_name',
  181. primaryName: 'nagios/'
  182. }
  183. ],
  184. isSubmitDisabled: function () {
  185. return !this.get('stepConfigs').filterProperty('showConfig').everyProperty('errorCount', 0);
  186. }.property('stepConfigs.@each.errorCount'),
  187. /**
  188. * clear info of step
  189. */
  190. clearStep: function () {
  191. this.get('stepConfigs').clear();
  192. this.get('securityUsers').clear();
  193. },
  194. /**
  195. * Function is called whenever the step is loaded
  196. */
  197. loadStep: function () {
  198. console.log("TRACE: Loading addSecurity step2: Configure Services");
  199. var versionNumber = App.get('currentStackVersionNumber');
  200. if( stringUtils.compareVersions(versionNumber, "2.2") >= 0){
  201. // Add Nimbus config options
  202. var masterComponentMap = this.get('masterComponentMap');
  203. masterComponentMap.filterProperty('configName', 'storm_host').components = ["SUPERVISOR", "STORM_UI_SERVER", "DRPC_SERVER", "STORM_REST_API"];
  204. masterComponentMap.pushObject({
  205. serviceName: 'STORM',
  206. configName: 'nimbus_host',
  207. components: ['NIMBUS']
  208. });
  209. this.get('hostToPrincipalMap').pushObject({
  210. serviceName: 'STORM',
  211. configName: 'nimbus_host',
  212. principalName: 'storm_principal_name',
  213. primaryName: 'storm'
  214. });
  215. }
  216. this.clearStep();
  217. this.loadUsers();
  218. this.addUserPrincipals(this.get('content.services'), this.get('securityUsers'));
  219. this.addMasterHostToConfigs();
  220. this.addHostPrincipals();
  221. this.addSlaveHostToConfigs();
  222. this.renderServiceConfigs(this.get('content.services'));
  223. this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
  224. this.setStoredConfigsValue(this.get('content.serviceConfigProperties'));
  225. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  226. },
  227. /**
  228. * set stored values to service configs
  229. * @param storedConfigProperties
  230. * @return {Boolean}
  231. */
  232. setStoredConfigsValue: function (storedConfigProperties) {
  233. if (!storedConfigProperties) return false;
  234. // for all services`
  235. this.get('stepConfigs').forEach(function (_content) {
  236. _content.get('configs').forEach(function (_config) {
  237. var configProperty = storedConfigProperties.findProperty('name', _config.get('name'));
  238. if (configProperty) {
  239. _config.set('value', configProperty.value);
  240. }
  241. }, this);
  242. }, this);
  243. return true;
  244. },
  245. /**
  246. * Render configs for active services
  247. * @param serviceConfigs
  248. */
  249. renderServiceConfigs: function (serviceConfigs) {
  250. serviceConfigs.forEach(function (_serviceConfig) {
  251. var serviceConfig = App.ServiceConfig.create({
  252. filename: _serviceConfig.filename,
  253. serviceName: _serviceConfig.serviceName,
  254. displayName: _serviceConfig.displayName,
  255. configCategories: _serviceConfig.configCategories,
  256. showConfig: true,
  257. configs: this.wrapConfigProperties(_serviceConfig)
  258. });
  259. this.get('stepConfigs').pushObject(serviceConfig);
  260. }, this);
  261. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig').objectAt(0));
  262. },
  263. /**
  264. * wrap configs into App.ServiceConfigProperty objects
  265. * @param _componentConfig
  266. */
  267. wrapConfigProperties: function (_componentConfig) {
  268. var configs = [];
  269. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  270. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  271. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  272. serviceConfigProperty.validate();
  273. configs.pushObject(serviceConfigProperty);
  274. }, this);
  275. return configs;
  276. },
  277. /**
  278. * fill config with hosts of component
  279. * @param serviceName
  280. * @param configName
  281. * @param componentNames
  282. * @return {Boolean}
  283. */
  284. setHostsToConfig: function (serviceName, configName, componentNames) {
  285. var service = this.get('content.services').findProperty('serviceName', serviceName);
  286. if (service) {
  287. var hosts = service.configs.findProperty('name', configName);
  288. if (hosts) {
  289. hosts.defaultValue = App.Service.find(service.serviceName)
  290. .get('hostComponents')
  291. .filter(function (component) {
  292. return componentNames.contains(component.get('componentName'));
  293. })
  294. .mapProperty('hostName')
  295. .uniq();
  296. return true;
  297. }
  298. return false;
  299. }
  300. return false;
  301. },
  302. /**
  303. * set principal default value based on config host and default primary name
  304. * @param serviceName
  305. * @param hostConfigName
  306. * @param principalConfigName
  307. * @param defaultPrimaryName
  308. * @return {Boolean}
  309. */
  310. setHostToPrincipal: function (serviceName, hostConfigName, principalConfigName, defaultPrimaryName) {
  311. var service = this.get('content.services').findProperty('serviceName', serviceName);
  312. if (service) {
  313. var host = service.configs.findProperty('name', hostConfigName);
  314. var principal = service.configs.findProperty('name', principalConfigName);
  315. var versionNumber = App.get('currentStackVersionNumber');
  316. if(principalConfigName == 'storm_principal_name' && stringUtils.compareVersions(versionNumber, "2.2") >= 0){
  317. principal.defaultValue = defaultPrimaryName;
  318. return true;
  319. } else 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. });