step4.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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 = Em.Controller.extend({
  20. name: 'mainAdminSecurityAddStep4Controller',
  21. secureMapping: function () {
  22. if (App.get('isHadoop2Stack')) {
  23. return require('data/HDP2/secure_mapping');
  24. } else {
  25. return require('data/secure_mapping');
  26. }
  27. }.property(App.isHadoop2Stack),
  28. secureProperties: function () {
  29. if (App.get('isHadoop2Stack')) {
  30. return require('data/HDP2/secure_properties').configProperties;
  31. } else {
  32. return require('data/secure_properties').configProperties;
  33. }
  34. }.property(App.isHadoop2Stack),
  35. stages: [],
  36. configs: [],
  37. noOfWaitingAjaxCalls: 0,
  38. secureServices: [],
  39. serviceUsersBinding: 'App.router.mainAdminSecurityController.serviceUsers',
  40. serviceConfigTags: [],
  41. globalProperties: [],
  42. totalSteps: 3,
  43. isSubmitDisabled: true,
  44. isBackBtnDisabled: function () {
  45. return !this.get('stages').someProperty('isError', true);
  46. }.property('stages.@each.isCompleted'),
  47. isOozieSelected: function () {
  48. return this.get('content.services').someProperty('serviceName', 'OOZIE');
  49. }.property('content.services'),
  50. isHiveSelected: function () {
  51. return this.get('content.services').someProperty('serviceName', 'HIVE');
  52. }.property('content.services'),
  53. isNagiosSelected: function () {
  54. return this.get('content.services').someProperty('serviceName', 'NAGIOS');
  55. }.property('content.services'),
  56. isZkSelected: function () {
  57. return this.get('content.services').someProperty('serviceName', 'ZOOKEEPER');
  58. }.property('content.services'),
  59. isWebHcatSelected: function () {
  60. var installedServices = App.Service.find().mapProperty('serviceName');
  61. return installedServices.contains('WEBHCAT');
  62. },
  63. hasHostPopup: true,
  64. services: [],
  65. serviceTimestamp: null,
  66. isSecurityApplied: function () {
  67. return this.get('stages').someProperty('stage', 'stage3') && this.get('stages').findProperty('stage', 'stage3').get('isSuccess');
  68. }.property('stages.@each.isCompleted'),
  69. clearStep: function () {
  70. this.get('stages').clear();
  71. this.set('isSubmitDisabled', true);
  72. this.set('isBackBtnDisabled', true);
  73. this.get('serviceConfigTags').clear();
  74. },
  75. retry: function () {
  76. var failedStage = this.get('stages').findProperty('isError', true);
  77. if (failedStage) {
  78. failedStage.set('isStarted', false);
  79. failedStage.set('isError', false);
  80. this.startStage(failedStage);
  81. }
  82. },
  83. loadStep: function () {
  84. this.set('secureMapping', require('data/secure_mapping').slice(0));
  85. this.clearStep();
  86. var stages = App.db.getSecurityDeployStages();
  87. this.prepareSecureConfigs();
  88. if (stages && stages.length > 0) {
  89. stages.forEach(function (_stage, index) {
  90. stages[index] = App.Poll.create(_stage);
  91. }, this);
  92. if (stages.someProperty('isError', true)) {
  93. this.get('stages').pushObjects(stages);
  94. this.addObserver('stages.@each.isSuccess', this, 'onCompleteStage');
  95. return;
  96. } else if (stages.filterProperty('isStarted', true).someProperty('isCompleted', false)) {
  97. var runningStage = stages.filterProperty('isStarted', true).findProperty('isCompleted', false);
  98. runningStage.set('isStarted', false);
  99. this.get('stages').pushObjects(stages);
  100. } else {
  101. this.get('stages').pushObjects(stages);
  102. }
  103. } else {
  104. this.loadStages();
  105. this.addInfoToStages();
  106. var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
  107. var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
  108. var stopStage = this.get('stages').findProperty('name', 'STOP_SERVICES');
  109. if (stopStage.get('name') === 'STOP_SERVICES' && stopAllOperation) {
  110. stopStage.set('requestId', stopAllOperation.get('id'));
  111. }
  112. }
  113. this.addObserver('stages.@each.isSuccess', this, 'onCompleteStage');
  114. this.moveToNextStage();
  115. },
  116. enableSubmit: function () {
  117. var addSecurityController = App.router.get('addSecurityController');
  118. if (this.get('stages').someProperty('isError', true) || this.get('stages').everyProperty('isSuccess', true)) {
  119. this.set('isSubmitDisabled', false);
  120. if (this.get('stages').someProperty('isError', true)) {
  121. addSecurityController.setStepsEnable();
  122. }
  123. } else {
  124. this.set('isSubmitDisabled', true);
  125. addSecurityController.setLowerStepsDisable(4);
  126. }
  127. }.observes('stages.@each.isCompleted'),
  128. updateServices: function () {
  129. this.services.clear();
  130. var services = this.get("services");
  131. this.get("stages").forEach(function (stage) {
  132. var newService = Ember.Object.create({
  133. name: stage.label,
  134. hosts: []
  135. });
  136. if (stage && stage.get("polledData")) {
  137. var hostNames = stage.get("polledData").mapProperty('Tasks.host_name').uniq();
  138. hostNames.forEach(function (name) {
  139. newService.hosts.push({
  140. name: name,
  141. publicName: name,
  142. logTasks: stage.polledData.filterProperty("Tasks.host_name", name)
  143. });
  144. });
  145. services.push(newService);
  146. }
  147. });
  148. this.set('serviceTimestamp', new Date().getTime());
  149. }.observes('stages.@each.polledData'),
  150. loadStages: function () {
  151. this.get('stages').pushObjects([
  152. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true, name: 'STOP_SERVICES'}),
  153. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false, name: 'APPLY_CONFIGURATIONS'}),
  154. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true, name: 'START_SERVICES'})
  155. ]);
  156. },
  157. startStage: function (currentStage) {
  158. if (this.get('stages').length === this.totalSteps) {
  159. if (!currentStage) {
  160. var startedStages = this.get('stages').filterProperty('isStarted', true);
  161. currentStage = startedStages.findProperty('isCompleted', false);
  162. }
  163. if (currentStage && currentStage.get('isPolling') === true) {
  164. currentStage.set('isStarted', true);
  165. currentStage.start();
  166. } else if (currentStage && currentStage.get('stage') === 'stage3') {
  167. currentStage.set('isStarted', true);
  168. if (App.testMode) {
  169. currentStage.set('isError', false);
  170. currentStage.set('isSuccess', true);
  171. } else {
  172. this.loadClusterConfigs();
  173. }
  174. }
  175. }
  176. },
  177. onCompleteStage: function () {
  178. if (this.get('stages').length === this.totalSteps) {
  179. var index = this.get('stages').filterProperty('isSuccess', true).length;
  180. if (index > 0) {
  181. var lastCompletedStageResult = this.get('stages').objectAt(index - 1).get('isSuccess');
  182. if (lastCompletedStageResult) {
  183. var nextStage = this.get('stages').objectAt(index);
  184. this.moveToNextStage(nextStage);
  185. }
  186. }
  187. }
  188. },
  189. moveToNextStage: function (nextStage) {
  190. if (!nextStage) {
  191. nextStage = this.get('stages').findProperty('isStarted', false);
  192. }
  193. if (nextStage) {
  194. this.startStage(nextStage);
  195. }
  196. },
  197. addInfoToStages: function () {
  198. this.addInfoToStage2();
  199. this.addInfoToStage4();
  200. },
  201. addInfoToStage1: function () {
  202. var stage1 = this.get('stages').findProperty('stage', 'stage1');
  203. if (App.testMode) {
  204. stage1.set('isSuccess', true);
  205. stage1.set('isStarted', true);
  206. stage1.set('isCompleted', true);
  207. }
  208. },
  209. addInfoToStage2: function () {
  210. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  211. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  212. var data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.stopAllServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  213. stage2.set('url', url);
  214. stage2.set('data', data);
  215. },
  216. addInfoToStage4: function () {
  217. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  218. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services?params/run_smoke_test=true';
  219. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.startAllServices') + '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  220. stage4.set('url', url);
  221. stage4.set('data', data);
  222. },
  223. loadUiSideConfigs: function () {
  224. var uiConfig = [];
  225. var configs = this.get('secureMapping').filterProperty('foreignKey', null);
  226. configs.forEach(function (_config) {
  227. var value = _config.value;
  228. if (_config.hasOwnProperty('dependedServiceName')) {
  229. value = this.checkServiceForConfigValue(value, _config.dependedServiceName);
  230. }
  231. value = this.getGlobConfigValue(_config.templateName, value, _config.name);
  232. uiConfig.pushObject({
  233. "id": "site property",
  234. "name": _config.name,
  235. "value": value,
  236. "filename": _config.filename
  237. });
  238. }, this);
  239. var dependentConfig = this.get('secureMapping').filterProperty('foreignKey');
  240. dependentConfig.forEach(function (_config) {
  241. if (App.Service.find().mapProperty('serviceName').contains(_config.serviceName)) {
  242. this.setConfigValue(uiConfig, _config);
  243. uiConfig.pushObject({
  244. "id": "site property",
  245. "name": _config._name || _config.name,
  246. "value": _config.value,
  247. "filename": _config.filename
  248. });
  249. }
  250. }, this);
  251. return uiConfig;
  252. },
  253. checkServiceForConfigValue: function (value, serviceNames) {
  254. serviceNames.forEach(function (_serviceName) {
  255. if (!App.Service.find().mapProperty('serviceName').contains(_serviceName.name)) {
  256. value = value.replace(_serviceName.replace, '');
  257. }
  258. }, this);
  259. return value;
  260. },
  261. /**
  262. * Set all site property that are derived from other puppet-variable
  263. */
  264. getGlobConfigValue: function (templateName, expression, name) {
  265. var express = expression.match(/<(.*?)>/g);
  266. var value = expression;
  267. if (express == null) {
  268. return expression;
  269. }
  270. express.forEach(function (_express) {
  271. //console.log("The value of template is: " + _express);
  272. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  273. var globValue = this.get('globalProperties').findProperty('name', templateName[index]);
  274. if (globValue) {
  275. console.log('The template value of templateName ' + '[' + index + ']' + ': ' + templateName[index] + ' is: ' + globValue);
  276. 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
  277. value = value.replace(_express, globValue.value);
  278. }
  279. } else {
  280. /*
  281. console.log("ERROR: The variable name is: " + templateName[index]);
  282. console.log("ERROR: mapped config from secureMapping file has no corresponding variable in " +
  283. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  284. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  285. */
  286. value = null;
  287. }
  288. }, this);
  289. return value;
  290. },
  291. /**
  292. * Set all site property that are derived from other site-properties
  293. */
  294. setConfigValue: function (uiConfig, config) {
  295. if (config.value == null) {
  296. return;
  297. }
  298. var fkValue = config.name.match(/<(foreignKey.*?)>/g);
  299. if (fkValue) {
  300. fkValue.forEach(function (_fkValue) {
  301. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  302. var globalValue;
  303. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  304. globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  305. config._name = config.name.replace(_fkValue, globalValue);
  306. } else if (this.get('globalProperties').someProperty('name', config.foreignKey[index])) {
  307. globalValue = this.get('globalProperties').findProperty('name', config.foreignKey[index]).value;
  308. config._name = config.name.replace(_fkValue, globalValue);
  309. }
  310. }, this);
  311. }
  312. //For properties in the configMapping file having foreignKey and templateName properties.
  313. var templateValue = config.value.match(/<(templateName.*?)>/g);
  314. if (templateValue) {
  315. templateValue.forEach(function (_value) {
  316. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  317. var globValue = this.get('globalProperties').findProperty('name', config.templateName[index]);
  318. if (globValue) {
  319. config.value = config.value.replace(_value, globValue.value);
  320. } else {
  321. config.value = null;
  322. }
  323. }, this);
  324. }
  325. },
  326. prepareSecureConfigs: function () {
  327. this.loadGlobals();
  328. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  329. var uiConfigs = this.loadUiSideConfigs();
  330. this.set('configs', storedConfigs.concat(uiConfigs));
  331. },
  332. loadGlobals: function () {
  333. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  334. this.set('globalProperties', globals);
  335. this.loadStaticGlobal(); //Hack for properties which are declared in global_properties.js and not able to retrieve values declared in secure_properties.js
  336. this.loadUsersToGlobal();
  337. this.loadHostNamesToGlobal();
  338. this.loadPrimaryNamesToGlobals();
  339. },
  340. loadUsersToGlobal: function () {
  341. if (!this.get('serviceUsers').length) {
  342. this.loadUsersFromServer();
  343. }
  344. App.router.get('mainAdminSecurityController.serviceUsers').forEach(function (_user) {
  345. this.get('globalProperties').pushObject(_user);
  346. }, this);
  347. },
  348. loadHostNamesToGlobal: function () {
  349. var oozieHostComponent = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER');
  350. if (this.get('isOozieSelected') && oozieHostComponent) {
  351. var oozieHostName = oozieHostComponent.get('host.hostName');
  352. this.get('globalProperties').pushObject({
  353. id: 'puppet var',
  354. name: 'oozieserver_host',
  355. value: oozieHostName
  356. });
  357. }
  358. var hiveHostComponent = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_METASTORE');
  359. if (this.get('isHiveSelected') && hiveHostComponent) {
  360. var hiveHostName = hiveHostComponent.get('host.hostName');
  361. this.get('globalProperties').pushObject({
  362. id: 'puppet var',
  363. name: 'hivemetastore_host',
  364. value: hiveHostName
  365. });
  366. }
  367. var webHcatComponent = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER');
  368. if (this.isWebHcatSelected() && webHcatComponent) {
  369. var webHcatHostName = webHcatComponent.get('host.hostName');
  370. this.get('globalProperties').pushObject({
  371. id: 'puppet var',
  372. name: 'webhcat_server',
  373. value: webHcatHostName
  374. });
  375. }
  376. },
  377. loadStaticGlobal: function () {
  378. var globalProperties = this.get('globalProperties');
  379. this.get('globalProperties').forEach(function (_property) {
  380. switch (_property.name) {
  381. case 'security_enabled':
  382. _property.value = 'true';
  383. break;
  384. }
  385. }, this);
  386. },
  387. loadPrimaryNamesToGlobals: function () {
  388. var principalProperties = this.getPrincipalNames();
  389. principalProperties.forEach(function (_principalProperty) {
  390. var name = _principalProperty.name.replace('principal', 'primary');
  391. var value = _principalProperty.value.split('/')[0];
  392. this.get('globalProperties').pushObject({name: name, value: value});
  393. }, this);
  394. },
  395. getPrincipalNames: function () {
  396. var principalNames = [];
  397. var allPrincipalNames = [];
  398. this.get('globalProperties').forEach(function (_globalProperty) {
  399. if (/principal_name?$/.test(_globalProperty.name)) {
  400. principalNames.pushObject(_globalProperty);
  401. }
  402. }, this);
  403. this.get('secureProperties').forEach(function (_secureProperty) {
  404. if (/principal_name?$/.test(_secureProperty.name)) {
  405. var principalName = principalNames.findProperty('name', _secureProperty.name);
  406. if (!principalName) {
  407. _secureProperty.value = _secureProperty.defaultValue;
  408. principalNames.pushObject(_secureProperty);
  409. }
  410. }
  411. }, this);
  412. return principalNames;
  413. },
  414. loadUsersFromServer: function () {
  415. if (App.testMode) {
  416. var serviceUsers = this.get('serviceUsers');
  417. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  418. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  419. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  420. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  421. } else {
  422. App.router.set('mainAdminSecurityController.serviceUsers', App.db.getSecureUserInfo());
  423. }
  424. },
  425. loadClusterConfigs: function () {
  426. App.ajax.send({
  427. name: 'admin.security.add.cluster_configs',
  428. sender: this,
  429. success: 'loadClusterConfigsSuccessCallback',
  430. error: 'loadClusterConfigsErrorCallback'
  431. });
  432. },
  433. loadClusterConfigsSuccessCallback: function (data) {
  434. var self = this;
  435. //prepare tags to fetch all configuration for a service
  436. this.get('content.services').forEach(function (_secureService) {
  437. self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
  438. });
  439. this.getAllConfigurations();
  440. },
  441. loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
  442. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  443. if (stage3) {
  444. stage3.set('isSuccess', false);
  445. stage3.set('isError', true);
  446. }
  447. console.log("TRACE: error code status is: " + request.status);
  448. },
  449. /**
  450. * set tagnames for configuration of the *-site.xml
  451. */
  452. setServiceTagNames: function (secureService, configs) {
  453. //var serviceConfigTags = this.get('serviceConfigTags');
  454. for (var index in configs) {
  455. if (secureService.sites && secureService.sites.contains(index)) {
  456. var serviceConfigObj = {
  457. siteName: index,
  458. tagName: configs[index].tag,
  459. newTagName: null,
  460. configs: {}
  461. };
  462. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  463. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  464. }
  465. }
  466. return serviceConfigObj;
  467. },
  468. applyConfigurationsToCluster: function () {
  469. var configData = [];
  470. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  471. var Clusters = {
  472. Clusters: {
  473. desired_config: {
  474. type: _serviceConfig.siteName,
  475. tag: _serviceConfig.newTagName,
  476. properties: _serviceConfig.configs
  477. }
  478. }
  479. };
  480. configData.pushObject(JSON.stringify(Clusters));
  481. }, this);
  482. var data = {
  483. configData: '[' + configData.toString() + ']'
  484. };
  485. App.ajax.send({
  486. name: 'admin.security.apply_configurations',
  487. sender: this,
  488. data: data,
  489. success: 'applyConfigurationToClusterSuccessCallback',
  490. error: 'applyConfigurationToClusterErrorCallback'
  491. });
  492. },
  493. applyConfigurationToClusterSuccessCallback: function (data) {
  494. var currentStage = this.get('stages').findProperty('stage', 'stage3');
  495. currentStage.set('isSuccess', true);
  496. currentStage.set('isError', false);
  497. },
  498. applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
  499. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  500. if (stage3) {
  501. stage3.set('isSuccess', false);
  502. stage3.set('isError', true);
  503. }
  504. },
  505. /**
  506. * gets site config properties from server and sets it for every configuration
  507. * @param serviceConfigTags
  508. */
  509. getAllConfigurations: function () {
  510. var urlParams = [];
  511. this.get('serviceConfigTags').forEach(function (_tag) {
  512. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  513. }, this);
  514. if (urlParams.length > 0) {
  515. App.ajax.send({
  516. name: 'admin.security.all_configurations',
  517. sender: this,
  518. data: {
  519. urlParams: urlParams.join('|')
  520. },
  521. success: 'getAllConfigurationsSuccessCallback',
  522. error: 'getAllConfigurationsErrorCallback'
  523. });
  524. }
  525. },
  526. getAllConfigurationsSuccessCallback: function (data) {
  527. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  528. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  529. this.get('serviceConfigTags').forEach(function (_tag) {
  530. if (!data.items.someProperty('type', _tag.siteName)) {
  531. console.log("Error: Metadata for secure services (secure_configs.js) is having config tags that are not being retrieved from server");
  532. if (stage3) {
  533. stage3.set('isSuccess', false);
  534. stage3.set('isError', true);
  535. }
  536. }
  537. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  538. }, this);
  539. if (this.addSecureConfigs()) {
  540. this.escapeXMLCharacters(this.get('serviceConfigTags'));
  541. this.applyConfigurationsToCluster();
  542. }
  543. },
  544. getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
  545. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  546. if (stage3) {
  547. stage3.set('isSuccess', false);
  548. stage3.set('isError', true);
  549. }
  550. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  551. console.log("TRACE: error code status is: " + request.status);
  552. },
  553. /*
  554. Iterate over keys of all configurations and escape xml characters in their values
  555. */
  556. escapeXMLCharacters: function (serviceConfigTags) {
  557. serviceConfigTags.forEach(function (_serviceConfigTags) {
  558. var configs = _serviceConfigTags.configs;
  559. for (var key in configs) {
  560. configs[key] = App.config.escapeXMLCharacters(configs[key]);
  561. }
  562. }, this);
  563. },
  564. addSecureConfigs: function () {
  565. try {
  566. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  567. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  568. if (_serviceConfigTags.siteName === 'global') {
  569. var realmName = this.get('globalProperties').findProperty('name', 'kerberos_domain');
  570. if (this.get('isNagiosSelected')) {
  571. var nagiosPrincipalName = this.get('globalProperties').findProperty('name', 'nagios_principal_name');
  572. nagiosPrincipalName.value = nagiosPrincipalName.value + '@' + realmName.value;
  573. }
  574. if (this.get('isZkSelected')) {
  575. var zkPrincipalName = this.get('globalProperties').findProperty('name', 'zookeeper_principal_name');
  576. zkPrincipalName.value = zkPrincipalName.value + '@' + realmName.value;
  577. }
  578. this.get('globalProperties').forEach(function (_globalProperty) {
  579. if (!/_hosts?$/.test(_globalProperty.name)) {
  580. _serviceConfigTags.configs[_globalProperty.name] = _globalProperty.value;
  581. }
  582. }, this);
  583. }
  584. else {
  585. this.get('configs').filterProperty('id', 'site property').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  586. _serviceConfigTags.configs[_config.name] = _config.value;
  587. }, this);
  588. }
  589. }, this);
  590. } catch (err) {
  591. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  592. if (stage3) {
  593. stage3.set('isSuccess', false);
  594. stage3.set('isError', true);
  595. }
  596. if (err) {
  597. console.log("Error: Error occurred while applying secure configs to the server. Error message: " + err);
  598. }
  599. this.onJsError();
  600. return false;
  601. }
  602. return true;
  603. },
  604. onJsError: function () {
  605. App.ModalPopup.show({
  606. header: Em.I18n.t('common.error'),
  607. secondary: false,
  608. onPrimary: function () {
  609. this.hide();
  610. },
  611. bodyClass: Ember.View.extend({
  612. template: Ember.Handlebars.compile('<p>{{t admin.security.apply.configuration.error}}</p>')
  613. })
  614. });
  615. },
  616. saveStagesOnRequestId: function () {
  617. this.saveStages();
  618. }.observes('stages.@each.requestId'),
  619. saveStagesOnCompleted: function () {
  620. this.saveStages();
  621. }.observes('stages.@each.isCompleted'),
  622. saveStages: function () {
  623. var stages = [];
  624. if (this.get('stages').length === this.totalSteps) {
  625. this.get('stages').forEach(function (_stage) {
  626. var stage = {
  627. name: _stage.get('name'),
  628. stage: _stage.get('stage'),
  629. label: _stage.get('label'),
  630. isPolling: _stage.get('isPolling'),
  631. isStarted: _stage.get('isStarted'),
  632. requestId: _stage.get('requestId'),
  633. isSuccess: _stage.get('isSuccess'),
  634. isError: _stage.get('isError'),
  635. url: _stage.get('url'),
  636. polledData: _stage.get('polledData'),
  637. data: _stage.get('data')
  638. };
  639. stages.pushObject(stage);
  640. }, this);
  641. App.db.setSecurityDeployStages(stages);
  642. if (!App.testMode) {
  643. App.clusterStatus.setClusterStatus({
  644. clusterName: this.get('clusterName'),
  645. clusterState: 'ADD_SECURITY_STEP_4',
  646. wizardControllerName: App.router.get('addSecurityController.name'),
  647. localdb: App.db.data.AddSecurity
  648. });
  649. }
  650. }
  651. }
  652. });