step3.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
  20. name: 'mainAdminSecurityAddStep3Controller',
  21. secureMapping: require('data/secure_mapping'),
  22. stages: [],
  23. configs: [],
  24. noOfWaitingAjaxCalls: 0,
  25. secureServices: [],
  26. serviceConfigTags: [],
  27. globalProperties: [],
  28. isSubmitDisabled: true,
  29. isBackBtnDisabled: true,
  30. isOozieSelected: function () {
  31. return this.get('content.services').someProperty('serviceName', 'OOZIE');
  32. }.property('content.services'),
  33. isWebHcatSelected: function () {
  34. var installedServices = App.Service.find().mapProperty('serviceName');
  35. return installedServices.contains('WEBHCAT');
  36. },
  37. serviceUsersBinding: 'App.router.mainAdminSecurityController.serviceUsers',
  38. hasHostPopup: true,
  39. services: [],
  40. serviceTimestamp: null,
  41. isSecurityApplied: function () {
  42. return this.get('stages').someProperty('stage', 'stage3') && this.get('stages').findProperty('stage', 'stage3').get('isSuccess');
  43. }.property('stages.@each.isCompleted'),
  44. clearStep: function () {
  45. this.get('stages').clear();
  46. this.set('isSubmitDisabled', true);
  47. this.set('isBackBtnDisabled', true);
  48. this.get('serviceConfigTags').clear();
  49. },
  50. loadStep: function () {
  51. this.set('secureMapping', require('data/secure_mapping').slice(0));
  52. this.clearStep();
  53. var stages = App.db.getSecurityDeployStages();
  54. this.prepareSecureConfigs();
  55. if (stages && stages.length > 0) {
  56. stages.forEach(function (_stage, index) {
  57. stages[index] = App.Poll.create(_stage);
  58. }, this);
  59. if (stages.someProperty('isError', true)) {
  60. var failedStages = stages.filterProperty('isError', true);
  61. failedStages.setEach('isError', false);
  62. failedStages.setEach('isStarted', false);
  63. } else if (stages.filterProperty('isStarted', true).someProperty('isCompleted', false)) {
  64. var runningStage = stages.filterProperty('isStarted', true).findProperty('isCompleted', false);
  65. runningStage.set('isStarted', false);
  66. }
  67. this.get('stages').pushObjects(stages);
  68. } else {
  69. this.loadStages();
  70. this.addInfoToStages();
  71. var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
  72. var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
  73. var stopStage = this.get('stages').findProperty('name', 'STOP_SERVICES');
  74. if (stopStage.get('name') === 'STOP_SERVICES' && stopAllOperation) {
  75. stopStage.set('requestId', stopAllOperation.get('id'));
  76. }
  77. }
  78. this.moveToNextStage();
  79. },
  80. enableSubmit: function () {
  81. if (this.get('stages').someProperty('isError', true) || this.get('stages').everyProperty('isSuccess', true)) {
  82. this.set('isSubmitDisabled', false);
  83. if (this.get('stages').someProperty('isError', true)) {
  84. this.set('isBackBtnDisabled', false);
  85. App.router.get('addSecurityController').setStepsEnable();
  86. }
  87. } else {
  88. this.set('isSubmitDisabled', true);
  89. }
  90. }.observes('stages.@each.isCompleted'),
  91. updateServices: function () {
  92. this.services.clear();
  93. var services = this.get("services");
  94. this.get("stages").forEach(function (stage) {
  95. var newService = Ember.Object.create({
  96. name: stage.label,
  97. hosts: []
  98. });
  99. if (stage && stage.get("polledData")) {
  100. var hostNames = stage.get("polledData").mapProperty('Tasks.host_name').uniq();
  101. hostNames.forEach(function (name) {
  102. newService.hosts.push({
  103. name: name,
  104. publicName: name,
  105. logTasks: stage.polledData.filterProperty("Tasks.host_name", name)
  106. });
  107. });
  108. services.push(newService);
  109. }
  110. });
  111. this.set('serviceTimestamp', new Date().getTime());
  112. }.observes('stages.@each.polledData'),
  113. loadStages: function () {
  114. this.get('stages').pushObjects([
  115. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true, name: 'STOP_SERVICES'}),
  116. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false, name: 'APPLY_CONFIGURATIONS'}),
  117. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true, name: 'START_SERVICES'})
  118. ]);
  119. },
  120. startStage: function () {
  121. var startedStages = this.get('stages').filterProperty('isStarted', true);
  122. if (startedStages.length) {
  123. var currentStage = startedStages.findProperty('isCompleted', false);
  124. if (currentStage && currentStage.get('isPolling') === true) {
  125. currentStage.start();
  126. } else if (currentStage && currentStage.get('stage') === 'stage3') {
  127. if (App.testMode) {
  128. currentStage.set('isSuccess', true);
  129. App.router.get('mainAdminSecurityController').setAddSecurityWizardStatus(null);
  130. } else {
  131. this.loadClusterConfigs()
  132. }
  133. }
  134. }
  135. }.observes('stages.@each.isStarted'),
  136. onCompleteStage: function () {
  137. var index = this.get('stages').filterProperty('isCompleted', true).length;
  138. if (index > 0) {
  139. var lastCompletedStageResult = this.get('stages').objectAt(index - 1).get('isSuccess');
  140. if (lastCompletedStageResult) {
  141. this.moveToNextStage();
  142. }
  143. }
  144. }.observes('stages.@each.isCompleted'),
  145. moveToNextStage: function () {
  146. var leftStages = this.get('stages').filterProperty('isStarted', false);
  147. var nextStage = leftStages.findProperty('isCompleted', false);
  148. if (nextStage) {
  149. nextStage.set('isStarted', true);
  150. }
  151. },
  152. addInfoToStages: function () {
  153. this.addInfoToStage2();
  154. this.addInfoToStage4();
  155. },
  156. addInfoToStage1: function () {
  157. var stage1 = this.get('stages').findProperty('stage', 'stage1');
  158. if (App.testMode) {
  159. stage1.set('isSuccess', true);
  160. stage1.set('isStarted', true);
  161. stage1.set('isCompleted', true);
  162. }
  163. },
  164. addInfoToStage2: function () {
  165. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  166. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  167. var data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.stopAllServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  168. stage2.set('url', url);
  169. stage2.set('data', data);
  170. },
  171. addInfoToStage4: function () {
  172. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  173. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services?params/run_smoke_test=true';
  174. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.startAllServices') + '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  175. stage4.set('url', url);
  176. stage4.set('data', data);
  177. },
  178. loadUiSideConfigs: function () {
  179. var uiConfig = [];
  180. var configs = this.get('secureMapping').filterProperty('foreignKey', null);
  181. configs.forEach(function (_config) {
  182. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  183. uiConfig.pushObject({
  184. "id": "site property",
  185. "name": _config.name,
  186. "value": value,
  187. "filename": _config.filename
  188. });
  189. }, this);
  190. var dependentConfig = this.get('secureMapping').filterProperty('foreignKey');
  191. dependentConfig.forEach(function (_config) {
  192. this.setConfigValue(uiConfig, _config);
  193. uiConfig.pushObject({
  194. "id": "site property",
  195. "name": _config._name || _config.name,
  196. "value": _config.value,
  197. "filename": _config.filename
  198. });
  199. }, this);
  200. return uiConfig;
  201. },
  202. /**
  203. * Set all site property that are derived from other puppet-variable
  204. */
  205. getGlobConfigValue: function (templateName, expression, name) {
  206. var express = expression.match(/<(.*?)>/g);
  207. var value = expression;
  208. if (express == null) {
  209. return expression;
  210. }
  211. express.forEach(function (_express) {
  212. //console.log("The value of template is: " + _express);
  213. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  214. var globValue = this.get('globalProperties').findProperty('name', templateName[index]);
  215. if (globValue) {
  216. console.log('The template value of templateName ' + '[' + index + ']' + ': ' + templateName[index] + ' is: ' + globValue);
  217. 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
  218. value = value.replace(_express, globValue.value);
  219. }
  220. } else {
  221. /*
  222. console.log("ERROR: The variable name is: " + templateName[index]);
  223. console.log("ERROR: mapped config from secureMapping file has no corresponding variable in " +
  224. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  225. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  226. */
  227. value = null;
  228. }
  229. }, this);
  230. return value;
  231. },
  232. /**
  233. * Set all site property that are derived from other site-properties
  234. */
  235. setConfigValue: function (uiConfig, config) {
  236. if (config.value == null) {
  237. return;
  238. }
  239. var fkValue = config.name.match(/<(foreignKey.*?)>/g);
  240. if (fkValue) {
  241. fkValue.forEach(function (_fkValue) {
  242. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  243. var globalValue;
  244. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  245. globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  246. config._name = config.name.replace(_fkValue, globalValue);
  247. } else if (this.get('globalProperties').someProperty('name', config.foreignKey[index])) {
  248. globalValue = this.get('globalProperties').findProperty('name', config.foreignKey[index]).value;
  249. config._name = config.name.replace(_fkValue, globalValue);
  250. }
  251. }, this);
  252. }
  253. //For properties in the configMapping file having foreignKey and templateName properties.
  254. var templateValue = config.value.match(/<(templateName.*?)>/g);
  255. if (templateValue) {
  256. templateValue.forEach(function (_value) {
  257. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  258. var globValue = this.get('globalProperties').findProperty('name', config.templateName[index]);
  259. if (globValue) {
  260. config.value = config.value.replace(_value, globValue.value);
  261. } else {
  262. config.value = null;
  263. }
  264. }, this);
  265. }
  266. },
  267. prepareSecureConfigs: function () {
  268. this.loadGlobals();
  269. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  270. var uiConfigs = this.loadUiSideConfigs();
  271. this.set('configs', storedConfigs.concat(uiConfigs));
  272. },
  273. loadGlobals: function () {
  274. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  275. this.set('globalProperties', globals);
  276. this.loadStaticGlobal(); //Hack for properties which are declared in config_properties.js and not able to retrieve values declared in secure_properties.js
  277. this.loadUsersToGlobal();
  278. this.loadHostNamesToGlobal();
  279. this.loadPrimaryNamesToGlobals();
  280. },
  281. loadUsersToGlobal: function () {
  282. if (!this.get('serviceUsers').length) {
  283. this.loadUsersFromServer();
  284. }
  285. App.router.get('mainAdminSecurityController.serviceUsers').forEach(function (_user) {
  286. this.get('globalProperties').pushObject(_user);
  287. }, this);
  288. },
  289. loadHostNamesToGlobal: function () {
  290. if (this.get('isOozieSelected')) {
  291. var oozieHostName = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  292. this.get('globalProperties').pushObject({
  293. id: 'puppet var',
  294. name: 'oozieserver_host',
  295. value: oozieHostName
  296. });
  297. }
  298. if (App.Service.find('HIVE')) {
  299. var hiveHostName = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_METASTORE').get('host.hostName');
  300. this.get('globalProperties').pushObject({
  301. id: 'puppet var',
  302. name: 'hivemetastore_host',
  303. value: hiveHostName
  304. });
  305. }
  306. },
  307. loadStaticGlobal: function () {
  308. var globalProperties = this.get('globalProperties');
  309. this.get('globalProperties').forEach(function (_property) {
  310. switch (_property.name) {
  311. case 'security_enabled':
  312. _property.value = 'true';
  313. break;
  314. case 'dfs_datanode_address':
  315. _property.value = '1019';
  316. break;
  317. case 'dfs_datanode_http_address':
  318. _property.value = '1022';
  319. break;
  320. }
  321. }, this);
  322. },
  323. loadPrimaryNamesToGlobals: function () {
  324. var principalProperties = this.getPrincipalNames();
  325. principalProperties.forEach(function (_principalProperty) {
  326. var name = _principalProperty.name.replace('principal', 'primary');
  327. var value = _principalProperty.value.split('/')[0];
  328. this.get('globalProperties').pushObject({name:name,value:value});
  329. }, this);
  330. },
  331. getPrincipalNames: function () {
  332. var principalNames = [];
  333. this.get('globalProperties').forEach(function (_globalProperty) {
  334. if (/principal_name?$/.test(_globalProperty.name)) {
  335. principalNames.pushObject(_globalProperty);
  336. }
  337. }, this);
  338. return principalNames;
  339. },
  340. loadUsersFromServer: function () {
  341. if (App.testMode) {
  342. var serviceUsers = this.get('serviceUsers');
  343. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  344. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  345. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  346. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  347. } else {
  348. App.router.get('mainAdminSecurityController').setSecurityStatus();
  349. }
  350. },
  351. loadClusterConfigs: function () {
  352. var self = this;
  353. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
  354. App.ajax.send({
  355. name: 'admin.security.add.cluster_configs',
  356. sender: this,
  357. success: 'loadClusterConfigsSuccessCallback',
  358. error: 'loadClusterConfigsErrorCallback'
  359. });
  360. },
  361. loadClusterConfigsSuccessCallback: function (data) {
  362. var self = this;
  363. //prepare tags to fetch all configuration for a service
  364. this.get('content.services').forEach(function (_secureService) {
  365. self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
  366. });
  367. this.getAllConfigurations();
  368. },
  369. loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
  370. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  371. console.log("TRACE: error code status is: " + request.status);
  372. },
  373. /**
  374. * set tagnames for configuration of the *-site.xml
  375. */
  376. setServiceTagNames: function (secureService, configs) {
  377. //var serviceConfigTags = this.get('serviceConfigTags');
  378. for (var index in configs) {
  379. if (secureService.sites && secureService.sites.contains(index)) {
  380. var serviceConfigObj = {
  381. siteName: index,
  382. tagName: configs[index].tag,
  383. newTagName: null,
  384. configs: {}
  385. };
  386. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  387. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  388. }
  389. }
  390. return serviceConfigObj;
  391. },
  392. applyConfigurationsToCluster: function () {
  393. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
  394. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  395. this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName, properties: _serviceConfig.configs});
  396. }, this);
  397. },
  398. applyConfigurationToCluster: function (data) {
  399. var clusterData = {
  400. Clusters: {
  401. desired_config: data
  402. }
  403. };
  404. App.ajax.send({
  405. name: 'admin.security.apply_configuration',
  406. sender: this,
  407. data: {
  408. clusterData: clusterData
  409. },
  410. success: 'applyConfigurationToClusterSuccessCallback',
  411. error: 'applyConfigurationToClusterErrorCallback'
  412. });
  413. },
  414. applyConfigurationToClusterSuccessCallback: function (data) {
  415. this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
  416. if (this.get('noOfWaitingAjaxCalls') == 0) {
  417. var currentStage = this.get('stages').findProperty('stage', 'stage3');
  418. currentStage.set('isSuccess', true);
  419. }
  420. },
  421. applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
  422. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  423. },
  424. /**
  425. * gets site config properties from server and sets it for every configuration
  426. * @param serviceConfigTags
  427. */
  428. getAllConfigurations: function () {
  429. var urlParams = [];
  430. this.get('serviceConfigTags').forEach(function (_tag) {
  431. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  432. }, this);
  433. if (urlParams.length > 0) {
  434. App.ajax.send({
  435. name: 'admin.security.all_configurations',
  436. sender: this,
  437. data: {
  438. urlParams: urlParams.join('|')
  439. },
  440. success: 'getAllConfigurationsSuccessCallback',
  441. error: 'getAllConfigurationsErrorCallback'
  442. });
  443. }
  444. },
  445. getAllConfigurationsSuccessCallback: function (data) {
  446. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  447. this.get('serviceConfigTags').forEach(function (_tag) {
  448. if (!data.items.someProperty('type', _tag.siteName)) {
  449. console.log("Error: Metadata for secure services (secure_configs.js) is having config tags that are not being retrieved from server");
  450. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  451. }
  452. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  453. }, this);
  454. this.addSecureConfigs();
  455. this.applyConfigurationsToCluster();
  456. },
  457. getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
  458. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  459. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  460. console.log("TRACE: error code status is: " + request.status);
  461. },
  462. addSecureConfigs: function () {
  463. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  464. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  465. if (_serviceConfigTags.siteName === 'global') {
  466. var nagiosPrincipalName = this.get('globalProperties').findProperty('name','nagios_principal_name');
  467. var zkPrincipalName = this.get('globalProperties').findProperty('name','zookeeper_principal_name');
  468. var realmName = this.get('globalProperties').findProperty('name','kerberos_domain');
  469. nagiosPrincipalName.value = nagiosPrincipalName.value + '@' + realmName.value;
  470. zkPrincipalName.value = zkPrincipalName.value + '@' + realmName.value;
  471. this.get('globalProperties').forEach(function (_globalProperty) {
  472. _serviceConfigTags.configs[_globalProperty.name] = _globalProperty.value;
  473. }, this);
  474. }
  475. else {
  476. this.get('configs').filterProperty('id', 'site property').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  477. _serviceConfigTags.configs[_config.name] = _config.value;
  478. }, this);
  479. }
  480. }, this);
  481. },
  482. saveStages: function () {
  483. var stages = [];
  484. this.get('stages').forEach(function (_stage) {
  485. var stage = {
  486. name: _stage.get('name'),
  487. stage: _stage.get('stage'),
  488. label: _stage.get('label'),
  489. isPolling: _stage.get('isPolling'),
  490. isStarted: _stage.get('isStarted'),
  491. requestId: _stage.get('requestId'),
  492. isSuccess: _stage.get('isSuccess'),
  493. isError: _stage.get('isError'),
  494. url: _stage.get('url'),
  495. polledData: _stage.get('polledData'),
  496. data: _stage.get('data')
  497. };
  498. stages.pushObject(stage);
  499. }, this);
  500. App.db.setSecurityDeployStages(stages);
  501. }.observes('stages.@each.requestId', 'stages.@each.isStarted', 'stages.@each.isCompleted')
  502. });