security.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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.MainAdminSecurityController = Em.Controller.extend({
  20. name: 'mainAdminSecurityController',
  21. isSubmitDisabled: false,
  22. securityEnabled: false,
  23. dataIsLoaded: false,
  24. serviceUsers: [],
  25. tag: {},
  26. getAddSecurityWizardStatus: function () {
  27. return App.db.getSecurityWizardStatus();
  28. },
  29. setAddSecurityWizardStatus: function (status) {
  30. App.db.setSecurityWizardStatus(status);
  31. },
  32. setDisableSecurityStatus: function (status) {
  33. App.db.setDisableSecurityStatus(status);
  34. },
  35. getDisableSecurityStatus: function (status) {
  36. return App.db.getDisableSecurityStatus();
  37. },
  38. notifySecurityOff: false,
  39. notifySecurityAdd: false,
  40. stepConfigs: [],
  41. desiredConfigs: [],
  42. securityUsers: [],
  43. serviceConfigTags: [],
  44. selectedService: null,
  45. isNotEditable: true,
  46. services: function(){
  47. var secureServices;
  48. var services = [];
  49. if(App.get('isHadoop2Stack')) {
  50. secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
  51. } else {
  52. secureServices = $.extend(true, [], require('data/secure_configs'));
  53. }
  54. var installedServices = App.Service.find().mapProperty('serviceName');
  55. //General (only non service tab) tab is always displayed
  56. services.push(secureServices.findProperty('serviceName', 'GENERAL'));
  57. installedServices.forEach(function (_service) {
  58. var secureService = secureServices.findProperty('serviceName', _service);
  59. if (secureService) {
  60. services.push(secureService);
  61. }
  62. }, this);
  63. return services;
  64. }.property(),
  65. loadStep: function(){
  66. var step2Controller = App.router.get('mainAdminSecurityAddStep2Controller');
  67. var services = this.get('services');
  68. this.get('stepConfigs').clear();
  69. this.get('securityUsers').clear();
  70. this.get('serviceConfigTags').clear();
  71. this.loadSecurityUsers();
  72. //loadSecurityUsers - desired configs fetched from server
  73. step2Controller.addUserPrincipals(services, this.get('securityUsers'));
  74. step2Controller.addMasterHostToGlobals(services);
  75. step2Controller.addSlaveHostToGlobals(services);
  76. this.renderServiceConfigs(services);
  77. step2Controller.changeCategoryOnHa(services, this.get('stepConfigs'));
  78. services.forEach(function (_secureService) {
  79. this.setServiceTagNames(_secureService, this.get('desiredConfigs'));
  80. }, this);
  81. var serverConfigs = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
  82. this.setConfigValuesFromServer(this.get('stepConfigs'), serverConfigs);
  83. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  84. },
  85. /**
  86. * get actual values of configurations from server
  87. * @param stepConfigs
  88. * @param serverConfigs
  89. */
  90. setConfigValuesFromServer: function(stepConfigs, serverConfigs){
  91. var allConfigs = {};
  92. serverConfigs.mapProperty('properties').forEach(function(_properties){
  93. allConfigs = $.extend(allConfigs, _properties);
  94. }, this);
  95. // for all services`
  96. stepConfigs.forEach(function (_content) {
  97. //for all components
  98. _content.get('configs').forEach(function (_config) {
  99. var componentVal = allConfigs[_config.get('name')];
  100. //if we have config for specified component
  101. if (componentVal) {
  102. //set it
  103. _config.set('value', componentVal);
  104. }
  105. }, this);
  106. }, this);
  107. },
  108. /**
  109. * set tag names according to installed services and desired configs
  110. * @param secureService
  111. * @param configs
  112. * @return {Object}
  113. */
  114. setServiceTagNames: function (secureService, configs) {
  115. //var serviceConfigTags = this.get('serviceConfigTags');
  116. for (var index in configs) {
  117. if (secureService.sites && secureService.sites.contains(index)) {
  118. var serviceConfigObj = {
  119. siteName: index,
  120. tagName: configs[index].tag,
  121. newTagName: null,
  122. configs: {}
  123. };
  124. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  125. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  126. }
  127. }
  128. return serviceConfigObj;
  129. },
  130. loadSecurityUsers: function () {
  131. var securityUsers = this.get('serviceUsers');
  132. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  133. if (App.testMode) {
  134. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  135. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  136. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  137. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  138. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  139. } else {
  140. this.setSecurityStatus();
  141. securityUsers = this.get('serviceUsers');
  142. }
  143. }
  144. this.set('securityUsers', securityUsers);
  145. },
  146. /**
  147. * fill config with hosts of component
  148. * @param service
  149. * @param configName
  150. * @param componentName
  151. */
  152. setHostsToConfig: function (service, configName, componentName) {
  153. if (service) {
  154. var hosts = service.configs.findProperty('name', configName);
  155. if (hosts) {
  156. hosts.defaultValue = App.Service.find(service.serviceName)
  157. .get('hostComponents')
  158. .filterProperty('componentName', componentName)
  159. .mapProperty('host.hostName');
  160. }
  161. }
  162. },
  163. /**
  164. * Load child components to service config object
  165. * @param _componentConfig
  166. * @param componentConfig
  167. */
  168. loadComponentConfigs: function (_componentConfig, componentConfig) {
  169. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  170. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  171. componentConfig.configs.pushObject(serviceConfigProperty);
  172. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  173. serviceConfigProperty.validate();
  174. }, this);
  175. },
  176. /**
  177. * Render configs for active services
  178. * @param serviceConfigs
  179. */
  180. renderServiceConfigs: function (serviceConfigs) {
  181. serviceConfigs.forEach(function (_serviceConfig) {
  182. var serviceConfig = App.ServiceConfig.create({
  183. filename: _serviceConfig.filename,
  184. serviceName: _serviceConfig.serviceName,
  185. displayName: _serviceConfig.displayName,
  186. configCategories: _serviceConfig.configCategories,
  187. showConfig: true,
  188. configs: []
  189. });
  190. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  191. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  192. this.get('stepConfigs').pushObject(serviceConfig);
  193. }, this);
  194. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  195. },
  196. notifySecurityOffPopup: function () {
  197. var self = this;
  198. if (!this.get('isSubmitDisabled')) {
  199. App.ModalPopup.show({
  200. header: Em.I18n.t('popup.confirmation.commonHeader'),
  201. primary: Em.I18n.t('ok'),
  202. onPrimary: function () {
  203. App.db.setSecurityDeployStages(undefined);
  204. self.setDisableSecurityStatus("RUNNING");
  205. App.router.transitionTo('disableSecurity');
  206. this.hide();
  207. },
  208. bodyClass: Ember.View.extend({
  209. isMapReduceInstalled: App.Service.find().mapProperty('serviceName').contains('MAPREDUCE'),
  210. template: Ember.Handlebars.compile([
  211. '<div class="alert">',
  212. '{{t admin.security.disable.popup.body}}',
  213. '{{#if view.isMapReduceInstalled}}',
  214. '<br>',
  215. '{{t admin.security.disable.popup.body.warning}}',
  216. '{{/if}}',
  217. '</div>'
  218. ].join('\n'))
  219. })
  220. })
  221. }
  222. },
  223. getUpdatedSecurityStatus: function () {
  224. this.setSecurityStatus();
  225. return this.get('securityEnabled');
  226. },
  227. setSecurityStatus: function () {
  228. if (App.testMode) {
  229. this.set('securityEnabled', !App.testEnableSecurity);
  230. this.set('dataIsLoaded', true);
  231. } else {
  232. //get Security Status From Server
  233. App.ajax.send({
  234. name: 'admin.security_status',
  235. sender: this,
  236. success: 'getSecurityStatusFromServerSuccessCallback',
  237. error: 'errorCallback'
  238. });
  239. }
  240. },
  241. errorCallback: function () {
  242. this.set('dataIsLoaded', true);
  243. this.showSecurityErrorPopup();
  244. },
  245. getSecurityStatusFromServerSuccessCallback: function (data) {
  246. var configs = data.Clusters.desired_configs;
  247. this.set('desiredConfigs', configs);
  248. if ('global' in configs && 'hdfs-site' in configs) {
  249. this.set('tag.global', configs['global'].tag);
  250. this.set('tag.hdfs-site', configs['hdfs-site'].tag);
  251. this.getServiceConfigsFromServer();
  252. }
  253. else {
  254. this.showSecurityErrorPopup();
  255. }
  256. },
  257. getServiceConfigsFromServer: function () {
  258. var urlParams = [];
  259. urlParams.push('(type=global&tag=' + this.get('tag.global') + ')');
  260. urlParams.push('(type=hdfs-site&tag=' + this.get('tag.hdfs-site') + ')');
  261. App.ajax.send({
  262. name: 'admin.security.all_configurations',
  263. sender: this,
  264. data: {
  265. urlParams: urlParams.join('|')
  266. },
  267. success: 'getServiceConfigsFromServerSuccessCallback',
  268. error: 'errorCallback'
  269. });
  270. },
  271. getServiceConfigsFromServerSuccessCallback: function (data) {
  272. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  273. var configs = data.items.findProperty('tag', this.get('tag.global')).properties;
  274. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  275. this.set('securityEnabled', true);
  276. }
  277. else {
  278. this.set('securityEnabled', false);
  279. var hdfsConfigs = data.items.findProperty('tag', this.get('tag.hdfs-site')).properties;
  280. this.setNnHaStatus(hdfsConfigs);
  281. }
  282. this.loadUsers(configs);
  283. this.set('dataIsLoaded', true);
  284. },
  285. setNnHaStatus: function(hdfsConfigs) {
  286. var nnHaStatus = hdfsConfigs && hdfsConfigs['dfs.nameservices'];
  287. var namenodesKey;
  288. if (nnHaStatus) {
  289. namenodesKey = 'dfs.ha.namenodes.' + hdfsConfigs['dfs.nameservices'];
  290. }
  291. if(nnHaStatus && hdfsConfigs[namenodesKey]) {
  292. App.db.setIsNameNodeHa('true');
  293. } else {
  294. App.db.setIsNameNodeHa('false');
  295. }
  296. },
  297. loadUsers: function (configs) {
  298. var serviceUsers = this.get('serviceUsers');
  299. serviceUsers.pushObject({
  300. id: 'puppet var',
  301. name: 'hdfs_user',
  302. value: configs['hdfs_user'] ? configs['hdfs_user'] : 'hdfs'
  303. });
  304. serviceUsers.pushObject({
  305. id: 'puppet var',
  306. name: 'yarn_user',
  307. value: configs['yarn_user'] ? configs['yarn_user'] : 'yarn'
  308. });
  309. serviceUsers.pushObject({
  310. id: 'puppet var',
  311. name: 'mapred_user',
  312. value: configs['mapred_user'] ? configs['mapred_user'] : 'mapred'
  313. });
  314. serviceUsers.pushObject({
  315. id: 'puppet var',
  316. name: 'hbase_user',
  317. value: configs['hbase_user'] ? configs['hbase_user'] : 'hbase'
  318. });
  319. serviceUsers.pushObject({
  320. id: 'puppet var',
  321. name: 'hive_user',
  322. value: configs['hive_user'] ? configs['hive_user'] : 'hive'
  323. });
  324. serviceUsers.pushObject({
  325. id: 'puppet var',
  326. name: 'proxyuser_group',
  327. value: configs['proxyuser_group'] ? configs['proxyuser_group'] : 'users'
  328. });
  329. serviceUsers.pushObject({
  330. id: 'puppet var',
  331. name: 'smokeuser',
  332. value: configs['smokeuser'] ? configs['smokeuser'] : 'ambari-qa'
  333. });
  334. serviceUsers.pushObject({
  335. id: 'puppet var',
  336. name: 'zk_user',
  337. value: configs['zk_user'] ? configs['zk_user'] : 'zookeeper'
  338. });
  339. serviceUsers.pushObject({
  340. id: 'puppet var',
  341. name: 'oozie_user',
  342. value: configs['oozie_user'] ? configs['oozie_user'] : 'oozie'
  343. });
  344. serviceUsers.pushObject({
  345. id: 'puppet var',
  346. name: 'nagios_user',
  347. value: configs['nagios_user'] ? configs['nagios_user'] : 'nagios'
  348. });
  349. serviceUsers.pushObject({
  350. id: 'puppet var',
  351. name: 'user_group',
  352. value: configs['user_group'] ? configs['user_group'] : 'hadoop'
  353. });
  354. },
  355. showSecurityErrorPopup: function () {
  356. App.ModalPopup.show({
  357. header: Em.I18n.t('common.error'),
  358. secondary: false,
  359. onPrimary: function () {
  360. this.hide();
  361. },
  362. bodyClass: Ember.View.extend({
  363. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  364. })
  365. });
  366. }
  367. });