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