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