step2.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. stepConfigs: [],
  23. installedServices: [],
  24. selectedService: null,
  25. isSubmitDisabled: function () {
  26. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  27. }.property('stepConfigs.@each.errorCount'),
  28. clearStep: function () {
  29. this.get('stepConfigs').clear();
  30. },
  31. /**
  32. * Function is called whenever the step is loaded
  33. */
  34. loadStep: function () {
  35. console.log("TRACE: Loading addSecurity step2: Configure Services");
  36. this.clearStep();
  37. this.addMasterHostToGlobals(this.get('content.services'));
  38. this.addSlaveHostToGlobals(this.get('content.services'));
  39. this.renderServiceConfigs(this.get('content.services'));
  40. var storedServices = this.get('content.serviceConfigProperties');
  41. if (storedServices) {
  42. var configs = new Ember.Set();
  43. // for all services`
  44. this.get('stepConfigs').forEach(function (_content) {
  45. //for all components
  46. _content.get('configs').forEach(function (_config) {
  47. var componentVal = storedServices.findProperty('name', _config.get('name'));
  48. //if we have config for specified component
  49. if (componentVal) {
  50. //set it
  51. _config.set('value', componentVal.value);
  52. }
  53. }, this);
  54. }, this);
  55. }
  56. //
  57. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  58. console.log("The services are: " + this.get('installedServices'));
  59. //
  60. },
  61. /**
  62. * Render configs for active services
  63. * @param serviceConfigs
  64. */
  65. renderServiceConfigs: function (serviceConfigs) {
  66. serviceConfigs.forEach(function (_serviceConfig) {
  67. var serviceConfig = App.ServiceConfig.create({
  68. filename: _serviceConfig.filename,
  69. serviceName: _serviceConfig.serviceName,
  70. displayName: _serviceConfig.displayName,
  71. configCategories: _serviceConfig.configCategories,
  72. showConfig: true,
  73. configs: []
  74. });
  75. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  76. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  77. this.get('stepConfigs').pushObject(serviceConfig);
  78. }, this);
  79. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  80. },
  81. /**
  82. * Load child components to service config object
  83. * @param _componentConfig
  84. * @param componentConfig
  85. */
  86. loadComponentConfigs: function (_componentConfig, componentConfig) {
  87. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  88. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  89. componentConfig.configs.pushObject(serviceConfigProperty);
  90. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  91. serviceConfigProperty.validate();
  92. }, this);
  93. },
  94. /**
  95. * fill config with hosts of component
  96. * @param service
  97. * @param configName
  98. * @param componentName
  99. */
  100. setHostsToConfig: function(service, configName, componentName){
  101. if(service){
  102. var hosts = service.configs.findProperty('name', configName);
  103. if(hosts){
  104. hosts.defaultValue = App.Service.find(service.serviceName)
  105. .get('hostComponents')
  106. .filterProperty('componentName', componentName)
  107. .mapProperty('host.hostName');
  108. }
  109. }
  110. },
  111. addSlaveHostToGlobals: function(serviceConfigs){
  112. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  113. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  114. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  115. this.setHostsToConfig(hdfsService, 'datanode_hosts', 'DATANODE');
  116. this.setHostsToConfig(mapReduceService, 'tasktracker_hosts', 'TASKTRACKER');
  117. this.setHostsToConfig(hbaseService, 'regionserver_hosts', 'HBASE_REGIONSERVER');
  118. },
  119. addMasterHostToGlobals: function (serviceConfigs) {
  120. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  121. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  122. var webHcatService = App.Service.find().mapProperty('serviceName').contains('WEBHCAT');
  123. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  124. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  125. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  126. var zooKeeperService = serviceConfigs.findProperty('serviceName', 'ZOOKEEPER');
  127. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  128. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  129. if (oozieService) {
  130. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  131. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  132. var oozieSpnegoPrincipal = generalService.configs.findProperty('name', 'oozie_http_principal_name');
  133. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  134. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  135. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue;
  136. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue;
  137. oozieSpnegoPrincipal.isVisible = true;
  138. }
  139. }
  140. if (hiveService) {
  141. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  142. if (hiveServerHost) {
  143. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  144. }
  145. }
  146. if(webHcatService) {
  147. var webHcatHost = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  148. var webHcatSpnegoPrincipal = generalService.configs.findProperty('name', 'webHCat_http_principal_name');
  149. if(webHcatHost && webHcatSpnegoPrincipal) {
  150. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost;
  151. webHcatSpnegoPrincipal.isVisible = true;
  152. }
  153. }
  154. if(nagiosService) {
  155. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  156. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  157. if (nagiosServerHost && nagiosServerPrincipal) {
  158. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  159. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue;
  160. }
  161. }
  162. if(hdfsService){
  163. var namenodeHost = hdfsService.configs.findProperty('name', 'namenode_host');
  164. var sNamenodeHost = hdfsService.configs.findProperty('name', 'snamenode_host');
  165. if (namenodeHost && sNamenodeHost) {
  166. namenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('host.hostName');
  167. sNamenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
  168. }
  169. }
  170. if(mapReduceService){
  171. var jobTrackerHost = mapReduceService.configs.findProperty('name', 'jobtracker_host');
  172. if (jobTrackerHost) {
  173. jobTrackerHost.defaultValue = App.Service.find('MAPREDUCE').get('hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  174. }
  175. }
  176. this.setHostsToConfig(hbaseService, 'hbasemaster_host', 'HBASE_MASTER');
  177. this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
  178. },
  179. showHostPrincipalKeytabList: function(){
  180. App.ModalPopup.show({
  181. self: this,
  182. header: Em.I18n.t('admin.security.step2.popup.header'),
  183. primary: Em.I18n.t('common.proceed'),
  184. downloadCsv: Em.I18n.t('admin.security.step2.popup.downloadCSV'),
  185. classNames: ['sixty-percent-width-modal'],
  186. csvContent: [],
  187. onDownloadCsv: function(){
  188. var blob = new Blob([this.get('csvContent')], {type: "text/csv;charset=utf-8"});
  189. saveAs(blob, "host-principal-keytab-list.csv");
  190. },
  191. onPrimary: function(){
  192. this.hide();
  193. App.router.send('next');
  194. },
  195. buildCsvContent: function(data){
  196. this.set('csvContent', stringUtils.arrayToCSV(data));
  197. },
  198. bodyClass: Em.View.extend({
  199. componentsToDisplay: ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  200. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER'],
  201. hostComponents: function(){
  202. var componentsToDisplay = this.get('componentsToDisplay');
  203. var configs = this.get('parentView.self.stepConfigs');
  204. var hosts = App.Host.find();
  205. var result = [];
  206. hosts.forEach(function(host){
  207. host.get('hostComponents').forEach(function(hostComponent){
  208. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  209. var serviceConfigs = configs.findProperty('serviceName', hostComponent.get('service.serviceName')).get('configs');
  210. var principal, keytab;
  211. serviceConfigs.forEach(function(config){
  212. if (config.get('component') && config.get('component') === hostComponent.get('componentName')) {
  213. if (config.get('name').substr(-15, 15) === '_principal_name') {
  214. principal = config.get('value').replace('_HOST', host.get('hostName')) + config.get('unit');
  215. } else if (config.get('name').substr(-7, 7) === '_keytab' || config.get('name').substr(-12, 12) === '_keytab_path') {
  216. keytab = config.get('value');
  217. }
  218. } else if (config.get('components') && config.get('components').contains(hostComponent.get('componentName'))) {
  219. if (config.get('name').substr(-15, 15) === '_principal_name') {
  220. principal = config.get('value').replace('_HOST', host.get('hostName')) + config.get('unit');
  221. } else if (config.get('name').substr(-7, 7) === '_keytab' || config.get('name').substr(-12, 12) === '_keytab_path') {
  222. keytab = config.get('value');
  223. }
  224. }
  225. });
  226. result.push({
  227. host: host.get('hostName'),
  228. component: hostComponent.get('displayName'),
  229. principal: principal,
  230. keytab: keytab
  231. });
  232. }
  233. });
  234. });
  235. this.get('parentView').buildCsvContent(result);
  236. return result;
  237. }.property(),
  238. template: Em.Handlebars.compile([
  239. '<div class="alert alert-info">{{t admin.security.step2.popup.notice}}</div>',
  240. '<div class="long-popup-list">',
  241. '<table class="table table-bordered table-striped">',
  242. '<thead>',
  243. '<tr>',
  244. '<th>{{t common.host}}</th>',
  245. '<th>{{t common.component}}</th>',
  246. '<th>{{t admin.security.step2.popup.table.principal}}</th>',
  247. '<th>{{t admin.security.step2.popup.table.keytab}}</th>',
  248. '</tr>',
  249. '</thead>',
  250. '<tbody>',
  251. '{{#each hostComponent in view.hostComponents}}',
  252. '<tr>',
  253. '<td>{{hostComponent.host}}</td>',
  254. '<td>{{hostComponent.component}}</td>',
  255. '<td>{{hostComponent.principal}}</td>',
  256. '<td>{{hostComponent.keytab}}</td>',
  257. '</tr>',
  258. '{{/each}}',
  259. '</tbody>',
  260. '</table>',
  261. '</div>'
  262. ].join(''))
  263. }),
  264. footerClass: Em.View.extend({
  265. classNames: ['modal-footer'],
  266. template: Em.Handlebars.compile([
  267. '{{#if view.parentView.downloadCsv}}<a class="btn btn-info" {{action onDownloadCsv target="view.parentView"}}>{{view.parentView.downloadCsv}}</a>&nbsp;{{/if}}',
  268. '{{#if view.parentView.secondary}}<a class="btn" {{action onSecondary target="view.parentView"}}>{{view.parentView.secondary}}</a>&nbsp;{{/if}}',
  269. '{{#if view.parentView.primary}}<a class="btn btn-success" {{action onPrimary target="view.parentView"}}>{{view.parentView.primary}}</a>{{/if}}'
  270. ].join(''))
  271. })
  272. });
  273. },
  274. /**
  275. * submit and move to step3
  276. */
  277. submit: function () {
  278. if (!this.get('isSubmitDisabled')) {
  279. this.showHostPrincipalKeytabList();
  280. }
  281. },
  282. doDownloadCsv: function(){
  283. var blob = new Blob([this.buildCvsContent()], {type: "text/csv;charset=utf-8"});
  284. saveAs(blob, "host-principal-keytab-list.csv");
  285. },
  286. buildCvsContent: function() {
  287. var configs = this.get('stepConfigs');
  288. var hosts = App.Host.find();
  289. var result = [];
  290. var componentsToDisplay = ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  291. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER'];
  292. var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  293. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  294. if (App.testMode) {
  295. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  296. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  297. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  298. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  299. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  300. } else {
  301. App.router.get('mainAdminSecurityController').setSecurityStatus();
  302. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  303. }
  304. }
  305. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  306. var generalConfigs = configs.findProperty('serviceName', 'GENERAL').configs;
  307. var realm = generalConfigs.findProperty('name', 'kerberos_domain').get('value');
  308. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  309. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  310. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  311. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  312. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  313. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  314. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  315. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  316. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  317. var smokeUser = smokeUserId + '@' + realm;
  318. var hdfsUser = hdfsUserId + '@' + realm;
  319. var hbaseUser = hbaseUserId + '@' + realm;
  320. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').get('value');
  321. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'keytab_path').get('value') + "/hdfs.headless.keytab";
  322. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'keytab_path').get('value') + "/hbase.headless.keytab";
  323. var httpPrincipal = generalConfigs.findProperty('name', 'hadoop_http_principal_name');
  324. var httpKeytabPath = generalConfigs.findProperty('name', 'hadoop_http_keytab').get('value');
  325. var componentToOwnerMap = {
  326. 'NAMENODE': hdfsUserId,
  327. 'SECONDARY_NAMENODE': hdfsUserId,
  328. 'DATANODE': hdfsUserId,
  329. 'TASKTRACKER': mapredUserId,
  330. 'JOBTRACKER': mapredUserId,
  331. 'ZOOKEEPER_SERVER': zkUserId,
  332. 'HIVE_SERVER': hiveUserId,
  333. 'OOZIE_SERVER': oozieUserId,
  334. 'NAGIOS_SERVER': nagiosUserId,
  335. 'HBASE_MASTER': hbaseUserId,
  336. 'HBASE_REGIONSERVER': hbaseUserId
  337. };
  338. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  339. hosts.forEach(function(host){
  340. result.push({
  341. host: host.get('hostName'),
  342. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  343. principal: smokeUser,
  344. keytab: smokeUserKeytabPath,
  345. owner: smokeUserId,
  346. group: hadoopGroupId,
  347. acl: '440'
  348. });
  349. result.push({
  350. host: host.get('hostName'),
  351. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  352. principal: hdfsUser,
  353. keytab: hdfsUserKeytabPath,
  354. owner: hdfsUserId,
  355. group: hadoopGroupId,
  356. acl: '440'
  357. });
  358. if (isHbaseInstalled) {
  359. result.push({
  360. host: host.get('hostName'),
  361. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  362. principal: hbaseUser,
  363. keytab: hbaseUserKeytabPath,
  364. owner: hbaseUserId,
  365. group: hadoopGroupId,
  366. acl: '440'
  367. });
  368. }
  369. if(host.get('hostComponents').someProperty('componentName', 'NAMENODE') ||
  370. host.get('hostComponents').someProperty('componentName', 'SECONDARY_NAMENODE') ||
  371. host.get('hostComponents').someProperty('componentName', 'WEBHCAT_SERVER') ||
  372. host.get('hostComponents').someProperty('componentName', 'OOZIE_SERVER')){
  373. result.push({
  374. host: host.get('hostName'),
  375. component: Em.I18n.t('admin.addSecurity.user.httpUser'),
  376. principal: httpPrincipal.get('value').replace('_HOST', host.get('hostName')) + httpPrincipal.get('unit'),
  377. keytab: httpKeytabPath,
  378. owner: 'root',
  379. group: hadoopGroupId,
  380. acl: '440'
  381. });
  382. }
  383. host.get('hostComponents').forEach(function(hostComponent){
  384. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  385. var serviceConfigs = configs.findProperty('serviceName', hostComponent.get('service.serviceName')).get('configs');
  386. var principal, keytab;
  387. serviceConfigs.forEach(function(config){
  388. if (config.get('component') && config.get('component') === hostComponent.get('componentName')) {
  389. if (config.get('name').endsWith('_principal_name')) {
  390. principal = config.get('value').replace('_HOST', host.get('hostName')) + config.get('unit');
  391. } else if (config.get('name').endsWith('_keytab') || config.get('name').endsWith('_keytab_path')) {
  392. keytab = config.get('value');
  393. }
  394. } else if (config.get('components') && config.get('components').contains(hostComponent.get('componentName'))) {
  395. if (config.get('name').endsWith('_principal_name')) {
  396. principal = config.get('value').replace('_HOST', host.get('hostName')) + config.get('unit');
  397. } else if (config.get('name').endsWith('_keytab') || config.get('name').endsWith('_keytab_path')) {
  398. keytab = config.get('value');
  399. }
  400. }
  401. });
  402. var key = host.get('hostName') + "--" + principal;
  403. if (!addedPrincipalsHost[key]) {
  404. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  405. if(!owner){
  406. owner = '';
  407. }
  408. result.push({
  409. host: host.get('hostName'),
  410. component: hostComponent.get('displayName'),
  411. principal: principal,
  412. keytab: keytab,
  413. owner: owner,
  414. group: hadoopGroupId,
  415. acl: '400'
  416. });
  417. addedPrincipalsHost[key] = true;
  418. }
  419. }
  420. });
  421. });
  422. return stringUtils.arrayToCSV(result);
  423. }
  424. });