step4.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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.MainAdminSecurityAddStep4Controller = App.MainAdminSecurityProgressController.extend({
  20. name: 'mainAdminSecurityAddStep4Controller',
  21. serviceUsersBinding: 'App.router.mainAdminSecurityController.serviceUsers',
  22. secureServices: function() {
  23. return this.get('content.services');
  24. }.property('content.services'),
  25. isBackBtnDisabled: function () {
  26. return !this.get('commands').someProperty('isError', true);
  27. }.property('commands.@each.isCompleted'),
  28. isOozieSelected: function () {
  29. return this.get('secureServices').someProperty('serviceName', 'OOZIE');
  30. }.property('secureServices'),
  31. isHiveSelected: function () {
  32. return this.get('secureServices').someProperty('serviceName', 'HIVE');
  33. }.property('secureServices'),
  34. isNagiosSelected: function () {
  35. return this.get('secureServices').someProperty('serviceName', 'NAGIOS');
  36. }.property('secureServices'),
  37. isZkSelected: function () {
  38. return this.get('secureServices').someProperty('serviceName', 'ZOOKEEPER');
  39. }.property('secureServices'),
  40. isWebHcatSelected: function () {
  41. var installedServices = App.Service.find().mapProperty('serviceName');
  42. return installedServices.contains('WEBHCAT');
  43. },
  44. isSecurityApplied: function () {
  45. return this.get('commands').someProperty('name', 'START_SERVICES') && this.get('commands').findProperty('name', 'START_SERVICES').get('isSuccess');
  46. }.property('commands.@each.isCompleted'),
  47. clearStep: function () {
  48. this.set('commands',[]);
  49. this.set('isSubmitDisabled', true);
  50. this.set('isBackBtnDisabled', true);
  51. this.get('serviceConfigTags').clear();
  52. },
  53. loadCommands: function () {
  54. this._super();
  55. // no need to remove ATS component if YARN and ATS are not installed
  56. if (this.get('secureServices').findProperty('serviceName', 'YARN') && App.Service.find('YARN').get('hostComponents').someProperty('componentName', 'APP_TIMELINE_SERVER')) {
  57. this.get('commands').splice(2, 0, App.Poll.create({name: 'DELETE_ATS', label: Em.I18n.translations['admin.addSecurity.apply.delete.ats'], isPolling: false}));
  58. }
  59. },
  60. loadStep: function () {
  61. this.set('secureMapping', require('data/secure_mapping').slice(0));
  62. this.clearStep();
  63. var commands = App.db.getSecurityDeployCommands();
  64. this.prepareSecureConfigs();
  65. if (commands && commands.length > 0) {
  66. commands.forEach(function (_command, index) {
  67. commands[index] = App.Poll.create(_command);
  68. }, this);
  69. if (commands.someProperty('isError', true)) {
  70. this.get('commands').pushObjects(commands);
  71. this.addObserverToCommands();
  72. return;
  73. } else if (commands.filterProperty('isStarted', true).someProperty('isCompleted', false)) {
  74. var runningCommand = commands.filterProperty('isStarted', true).findProperty('isCompleted', false);
  75. runningCommand.set('isStarted', false);
  76. this.get('commands').pushObjects(commands);
  77. } else {
  78. this.get('commands').pushObjects(commands);
  79. }
  80. } else {
  81. this.loadCommands();
  82. this.addInfoToCommands();
  83. var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
  84. var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
  85. var stopCommand = this.get('commands').findProperty('name', 'STOP_SERVICES');
  86. if (stopCommand.get('name') === 'STOP_SERVICES' && stopAllOperation) {
  87. stopCommand.set('requestId', stopAllOperation.get('id'));
  88. }
  89. }
  90. this.addObserverToCommands();
  91. this.moveToNextCommand();
  92. },
  93. enableSubmit: function () {
  94. var addSecurityController = App.router.get('addSecurityController');
  95. if (this.get('commands').someProperty('isError', true) || this.get('commands').everyProperty('isSuccess', true)) {
  96. this.set('isSubmitDisabled', false);
  97. if (this.get('commands').someProperty('isError', true)) {
  98. addSecurityController.setStepsEnable();
  99. }
  100. } else {
  101. this.set('isSubmitDisabled', true);
  102. addSecurityController.setLowerStepsDisable(4);
  103. }
  104. }.observes('commands.@each.isCompleted'),
  105. loadUiSideConfigs: function () {
  106. var uiConfig = [];
  107. var configs = this.get('secureMapping').filterProperty('foreignKey', null);
  108. configs.forEach(function (_config) {
  109. var value = _config.value;
  110. if (_config.hasOwnProperty('dependedServiceName')) {
  111. value = this.checkServiceForConfigValue(value, _config.dependedServiceName);
  112. }
  113. value = this.getGlobConfigValue(_config.templateName, value, _config.name);
  114. uiConfig.pushObject({
  115. "id": "site property",
  116. "name": _config.name,
  117. "value": value,
  118. "filename": _config.filename
  119. });
  120. }, this);
  121. var dependentConfig = this.get('secureMapping').filterProperty('foreignKey');
  122. dependentConfig.forEach(function (_config) {
  123. if (App.Service.find().mapProperty('serviceName').contains(_config.serviceName)) {
  124. this.setConfigValue(uiConfig, _config);
  125. uiConfig.pushObject({
  126. "id": "site property",
  127. "name": _config._name || _config.name,
  128. "value": _config.value,
  129. "filename": _config.filename
  130. });
  131. }
  132. }, this);
  133. return uiConfig;
  134. },
  135. checkServiceForConfigValue: function (value, serviceNames) {
  136. serviceNames.forEach(function (_serviceName) {
  137. if (!App.Service.find().mapProperty('serviceName').contains(_serviceName.name)) {
  138. value = value.replace(_serviceName.replace, '');
  139. }
  140. }, this);
  141. return value;
  142. },
  143. /**
  144. * Set all site property that are derived from other puppet-variable
  145. */
  146. getGlobConfigValue: function (templateName, expression, name) {
  147. var express = expression.match(/<(.*?)>/g);
  148. var value = expression;
  149. if (express == null) {
  150. return expression;
  151. }
  152. express.forEach(function (_express) {
  153. //console.log("The value of template is: " + _express);
  154. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  155. var globValue = this.get('globalProperties').findProperty('name', templateName[index]);
  156. if (globValue) {
  157. console.log('The template value of templateName ' + '[' + index + ']' + ': ' + templateName[index] + ' is: ' + globValue);
  158. if (value !== null) { // if the property depends on more than one template name like <templateName[0]>/<templateName[1]> then don't proceed to the next if the prior is null or not found in the global configs
  159. value = value.replace(_express, globValue.value);
  160. }
  161. } else {
  162. /*
  163. console.log("ERROR: The variable name is: " + templateName[index]);
  164. console.log("ERROR: mapped config from secureMapping file has no corresponding variable in " +
  165. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  166. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  167. */
  168. value = null;
  169. }
  170. }, this);
  171. return value;
  172. },
  173. /**
  174. * Set all site property that are derived from other site-properties
  175. */
  176. setConfigValue: function (uiConfig, config) {
  177. if (config.value == null) {
  178. return;
  179. }
  180. var fkValue = config.name.match(/<(foreignKey.*?)>/g);
  181. if (fkValue) {
  182. fkValue.forEach(function (_fkValue) {
  183. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  184. var globalValue;
  185. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  186. globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  187. config._name = config.name.replace(_fkValue, globalValue);
  188. } else if (this.get('globalProperties').someProperty('name', config.foreignKey[index])) {
  189. globalValue = this.get('globalProperties').findProperty('name', config.foreignKey[index]).value;
  190. config._name = config.name.replace(_fkValue, globalValue);
  191. }
  192. }, this);
  193. }
  194. //For properties in the configMapping file having foreignKey and templateName properties.
  195. var templateValue = config.value.match(/<(templateName.*?)>/g);
  196. if (templateValue) {
  197. templateValue.forEach(function (_value) {
  198. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  199. var globValue = this.get('globalProperties').findProperty('name', config.templateName[index]);
  200. if (globValue) {
  201. config.value = config.value.replace(_value, globValue.value);
  202. } else {
  203. config.value = null;
  204. }
  205. }, this);
  206. }
  207. },
  208. prepareSecureConfigs: function () {
  209. this.loadGlobals();
  210. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  211. var uiConfigs = this.loadUiSideConfigs();
  212. this.set('configs', storedConfigs.concat(uiConfigs));
  213. },
  214. loadGlobals: function () {
  215. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  216. this.set('globalProperties', globals);
  217. this.loadStaticGlobal(); //Hack for properties which are declared in global_properties.js and not able to retrieve values declared in secure_properties.js
  218. this.loadUsersToGlobal();
  219. this.loadHostNamesToGlobal();
  220. this.loadPrimaryNamesToGlobals();
  221. },
  222. loadUsersToGlobal: function () {
  223. if (!this.get('serviceUsers').length) {
  224. this.loadUsersFromServer();
  225. }
  226. App.router.get('mainAdminSecurityController.serviceUsers').forEach(function (_user) {
  227. this.get('globalProperties').pushObject(_user);
  228. }, this);
  229. },
  230. loadHostNamesToGlobal: function () {
  231. var oozieHostComponent = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER');
  232. if (this.get('isOozieSelected') && oozieHostComponent) {
  233. var oozieHostName = oozieHostComponent.get('host.hostName');
  234. this.get('globalProperties').pushObject({
  235. id: 'puppet var',
  236. name: 'oozieserver_host',
  237. value: oozieHostName
  238. });
  239. }
  240. var hiveHostComponent = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_METASTORE');
  241. if (this.get('isHiveSelected') && hiveHostComponent) {
  242. var hiveHostName = hiveHostComponent.get('host.hostName');
  243. this.get('globalProperties').pushObject({
  244. id: 'puppet var',
  245. name: 'hivemetastore_host',
  246. value: hiveHostName
  247. });
  248. }
  249. var webHcatComponent = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER');
  250. if (this.isWebHcatSelected() && webHcatComponent) {
  251. var webHcatHostName = webHcatComponent.get('host.hostName');
  252. this.get('globalProperties').pushObject({
  253. id: 'puppet var',
  254. name: 'webhcat_server',
  255. value: webHcatHostName
  256. });
  257. }
  258. },
  259. loadStaticGlobal: function () {
  260. var globalProperties = this.get('globalProperties');
  261. this.get('globalProperties').forEach(function (_property) {
  262. switch (_property.name) {
  263. case 'security_enabled':
  264. _property.value = 'true';
  265. break;
  266. }
  267. }, this);
  268. },
  269. loadPrimaryNamesToGlobals: function () {
  270. var principalProperties = this.getPrincipalNames();
  271. principalProperties.forEach(function (_principalProperty) {
  272. var name = _principalProperty.name.replace('principal', 'primary');
  273. var value = _principalProperty.value.split('/')[0];
  274. this.get('globalProperties').pushObject({name: name, value: value});
  275. }, this);
  276. },
  277. getPrincipalNames: function () {
  278. var principalNames = [];
  279. var allPrincipalNames = [];
  280. this.get('globalProperties').forEach(function (_globalProperty) {
  281. if (/principal_name?$/.test(_globalProperty.name)) {
  282. principalNames.pushObject(_globalProperty);
  283. }
  284. }, this);
  285. this.get('secureProperties').forEach(function (_secureProperty) {
  286. if (/principal_name?$/.test(_secureProperty.name)) {
  287. var principalName = principalNames.findProperty('name', _secureProperty.name);
  288. if (!principalName) {
  289. _secureProperty.value = _secureProperty.defaultValue;
  290. principalNames.pushObject(_secureProperty);
  291. }
  292. }
  293. }, this);
  294. return principalNames;
  295. },
  296. loadUsersFromServer: function () {
  297. if (App.testMode) {
  298. var serviceUsers = this.get('serviceUsers');
  299. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  300. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  301. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  302. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  303. } else {
  304. App.router.set('mainAdminSecurityController.serviceUsers', App.db.getSecureUserInfo());
  305. }
  306. },
  307. manageSecureConfigs: function () {
  308. try {
  309. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  310. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  311. if (_serviceConfigTags.siteName === 'global') {
  312. var realmName = this.get('globalProperties').findProperty('name', 'kerberos_domain');
  313. if (this.get('isNagiosSelected')) {
  314. var nagiosPrincipalName = this.get('globalProperties').findProperty('name', 'nagios_principal_name');
  315. nagiosPrincipalName.value = nagiosPrincipalName.value + '@' + realmName.value;
  316. }
  317. if (this.get('isZkSelected')) {
  318. var zkPrincipalName = this.get('globalProperties').findProperty('name', 'zookeeper_principal_name');
  319. zkPrincipalName.value = zkPrincipalName.value + '@' + realmName.value;
  320. }
  321. if (this.get('secureServices').someProperty('serviceName', 'STORM')) {
  322. var stormPrincipalName = this.get('globalProperties').findProperty('name', 'storm_principal_name');
  323. stormPrincipalName.value = stormPrincipalName.value + '@' + realmName.value;
  324. }
  325. this.get('globalProperties').forEach(function (_globalProperty) {
  326. if (!/_hosts?$/.test(_globalProperty.name)) {
  327. _serviceConfigTags.configs[_globalProperty.name] = _globalProperty.value;
  328. }
  329. }, this);
  330. }
  331. else {
  332. this.get('configs').filterProperty('id', 'site property').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  333. _serviceConfigTags.configs[_config.name] = _config.value;
  334. }, this);
  335. }
  336. }, this);
  337. } catch (err) {
  338. var command = this.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS');
  339. command.set('isSuccess', false);
  340. command.set('isError', true);
  341. if (err) {
  342. console.log("Error: Error occurred while applying secure configs to the server. Error message: " + err);
  343. }
  344. this.onJsError();
  345. return false;
  346. }
  347. return true;
  348. },
  349. deleteComponents: function(componentName, hostName) {
  350. App.ajax.send({
  351. name: 'admin.delete_component',
  352. sender: this,
  353. data: {
  354. componentName: componentName,
  355. hostName: hostName
  356. },
  357. success: 'onDeleteComplete',
  358. error: 'onDeleteError'
  359. });
  360. },
  361. onDeleteComplete: function () {
  362. var deleteAtsCommand = this.get('commands').findProperty('name', 'DELETE_ATS');
  363. console.warn('APP_TIMELINE_SERVER doesn\'t support security mode. It has been removed from YARN service ');
  364. deleteAtsCommand.set('isError', false);
  365. deleteAtsCommand.set('isSuccess', true);
  366. },
  367. onDeleteError: function () {
  368. console.warn('Error: Can\'t delete APP_TIMELINE_SERVER');
  369. },
  370. onJsError: function () {
  371. App.ModalPopup.show({
  372. header: Em.I18n.t('common.error'),
  373. secondary: false,
  374. bodyClass: Ember.View.extend({
  375. template: Ember.Handlebars.compile('<p>{{t admin.security.apply.configuration.error}}</p>')
  376. })
  377. });
  378. }
  379. });