step3.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. configMapping: require('data/secure_mapping'),
  22. stages: [],
  23. configs: [],
  24. noOfWaitingAjaxCalls: 0,
  25. secureServices: [],
  26. serviceConfigTags: [],
  27. globalProperties: [],
  28. isSubmitDisabled: true,
  29. isOozieSelected: function () {
  30. return this.get('content.services').someProperty('serviceName', 'OOZIE');
  31. }.property('content.services'),
  32. isWebHcatSelected: function () {
  33. return this.get('content.services').someProperty('serviceName', 'WEBHCAT');
  34. }.property('content.services'),
  35. serviceUsersBinding: 'App.router.mainAdminController.serviceUsers',
  36. hasHostPopup: true,
  37. services: [],
  38. serviceTimestamp: null,
  39. clearStep: function () {
  40. this.get('stages').clear();
  41. this.set('isSubmitDisabled', true);
  42. this.get('serviceConfigTags').clear();
  43. },
  44. loadStep: function () {
  45. this.clearStep();
  46. this.loadStages();
  47. this.addInfoToStages();
  48. this.prepareSecureConfigs();
  49. this.moveToNextStage();
  50. },
  51. enableSubmit: function () {
  52. if (this.get('stages').someProperty('isError', true) || this.get('stages').everyProperty('isSuccess', true)) {
  53. this.set('isSubmitDisabled', false);
  54. App.router.get('addSecurityController').setStepsEnable();
  55. }
  56. }.observes('stages.@each.isCompleted'),
  57. updateServices: function () {
  58. this.services.clear();
  59. var services = this.get("services");
  60. this.get("stages").forEach(function (stages) {
  61. var newService = Ember.Object.create({
  62. name: stages.label,
  63. hosts: []
  64. });
  65. var hostNames = stages.get("polledData").mapProperty('Tasks.host_name').uniq();
  66. hostNames.forEach(function (name) {
  67. newService.hosts.push({
  68. name: name,
  69. publicName: name,
  70. logTasks: stages.polledData.filterProperty("Tasks.host_name",name)
  71. });
  72. });
  73. services.push(newService);
  74. });
  75. this.set('serviceTimestamp', new Date().getTime());
  76. }.observes("stages.@each.polledData"),
  77. loadStages: function () {
  78. this.get('stages').pushObjects([
  79. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true}),
  80. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false}),
  81. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true})
  82. ]);
  83. },
  84. startStage: function () {
  85. var startedStages = this.get('stages').filterProperty('isStarted', true);
  86. if (startedStages.length) {
  87. var currentStage = startedStages.findProperty('isCompleted', false);
  88. if (currentStage && currentStage.get('isPolling') === true) {
  89. currentStage.start();
  90. } else if (currentStage && currentStage.get('stage') === 'stage3') {
  91. if (App.testMode) {
  92. currentStage.set('isSuccess', true);
  93. currentStage.set('isCompleted', true);
  94. this.moveToNextStage();
  95. } else {
  96. var self = this;
  97. window.setTimeout(function () {
  98. self.loadClusterConfigs();
  99. }, 12000);
  100. }
  101. }
  102. }
  103. }.observes('stages.@each.isStarted'),
  104. onCompleteStage: function () {
  105. var index = this.get('stages').filterProperty('isCompleted', true).length;
  106. if (index > 0) {
  107. var self = this;
  108. var lastCompletedStageResult = this.get('stages').objectAt(index - 1).get('isSuccess');
  109. if (lastCompletedStageResult) {
  110. window.setTimeout(function () {
  111. self.moveToNextStage();
  112. }, 50);
  113. }
  114. }
  115. }.observes('stages.@each.isCompleted'),
  116. moveToNextStage: function () {
  117. var nextStage = this.get('stages').findProperty('isStarted', false);
  118. if (nextStage) {
  119. nextStage.set('isStarted', true);
  120. }
  121. },
  122. addInfoToStages: function () {
  123. this.addInfoToStage2();
  124. this.addInfoToStage3();
  125. this.addInfoToStage4();
  126. },
  127. addInfoToStage1: function () {
  128. var stage1 = this.get('stages').findProperty('stage', 'stage1');
  129. if (App.testMode) {
  130. stage1.set('isSuccess', true);
  131. stage1.set('isStarted', true);
  132. stage1.set('isCompleted', true);
  133. }
  134. },
  135. addInfoToStage2: function () {
  136. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  137. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  138. var data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.stopAllServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  139. stage2.set('url', url);
  140. stage2.set('data', data);
  141. },
  142. addInfoToStage3: function () {
  143. },
  144. addInfoToStage4: function () {
  145. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  146. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  147. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.startAllServices') + '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  148. stage4.set('url', url);
  149. stage4.set('data', data);
  150. },
  151. loadUiSideConfigs: function () {
  152. var uiConfig = [];
  153. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  154. configs.forEach(function (_config) {
  155. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  156. uiConfig.pushObject({
  157. "id": "site property",
  158. "name": _config.name,
  159. "value": value,
  160. "filename": _config.filename
  161. });
  162. }, this);
  163. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  164. dependentConfig.forEach(function (_config) {
  165. this.setConfigValue(uiConfig, _config);
  166. uiConfig.pushObject({
  167. "id": "site property",
  168. "name": _config.name,
  169. "value": _config.value,
  170. "filename": _config.filename
  171. });
  172. }, this);
  173. return uiConfig;
  174. },
  175. appendInstanceName: function (name, property) {
  176. var newValue;
  177. if (this.get('globalProperties').someProperty('name', name)) {
  178. var globalProperty = this.get('globalProperties').findProperty('name', name);
  179. newValue = globalProperty.value;
  180. var isInstanceName = this.get('globalProperties').findProperty('name', 'instance_name');
  181. if (isInstanceName) {
  182. if (/primary_name?$/.test(globalProperty.name) && property !== 'hadoop.security.auth_to_local' && property !== 'oozie.authentication.kerberos.name.rules') {
  183. if (this.get('isOozieSelected') && (property === 'oozie.service.HadoopAccessorService.kerberos.principal' || property === 'oozie.authentication.kerberos.principal')) {
  184. var oozieServerName = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  185. newValue = newValue + '/' + oozieServerName;
  186. } else if (this.get('isWebHcatSelected') && property === 'templeton.kerberos.principal') {
  187. var webHcatName = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  188. newValue = newValue + '/' + webHcatName;
  189. } else {
  190. if (!/_HOST?$/.test(newValue)) {
  191. newValue = newValue + '/_HOST';
  192. }
  193. }
  194. }
  195. }
  196. } else {
  197. console.log("The template name does not exist in secure_properties file");
  198. newValue = null;
  199. }
  200. return newValue;
  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. if (this.get('globalProperties').someProperty('name', templateName[index])) {
  215. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  216. var globValue = this.appendInstanceName(templateName[index], name);
  217. console.log('The template value of templateName ' + '[' + index + ']' + ': ' + templateName[index] + ' is: ' + globValue);
  218. 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
  219. value = value.replace(_express, globValue);
  220. }
  221. } else {
  222. /*
  223. console.log("ERROR: The variable name is: " + templateName[index]);
  224. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  225. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  226. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  227. */
  228. value = null;
  229. }
  230. }, this);
  231. return value;
  232. },
  233. /**
  234. * Set all site property that are derived from other site-properties
  235. */
  236. setConfigValue: function (uiConfig, config) {
  237. if (config.value == null) {
  238. return;
  239. }
  240. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  241. if (fkValue) {
  242. fkValue.forEach(function (_fkValue) {
  243. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  244. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  245. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  246. config.value = config.value.replace(_fkValue, globalValue);
  247. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  248. var globalValue;
  249. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  250. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  251. } else {
  252. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  253. }
  254. config.value = config.value.replace(_fkValue, globalValue);
  255. }
  256. }, this);
  257. }
  258. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  259. fkValue.forEach(function (_fkValue) {
  260. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  261. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  262. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  263. config.name = config.name.replace(_fkValue, globalValue);
  264. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  265. var globalValue;
  266. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  267. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  268. } else {
  269. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  270. }
  271. config.name = config.name.replace(_fkValue, globalValue);
  272. }
  273. }, this);
  274. }
  275. //For properties in the configMapping file having foreignKey and templateName properties.
  276. var templateValue = config.value.match(/<(templateName.*?)>/g);
  277. if (templateValue) {
  278. templateValue.forEach(function (_value) {
  279. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  280. if (this.get('globalProperties').someProperty('name', config.templateName[index])) {
  281. var globValue = this.appendInstanceName(config.templateName[index]);
  282. config.value = config.value.replace(_value, globValue);
  283. } else {
  284. config.value = null;
  285. }
  286. }, this);
  287. }
  288. },
  289. prepareSecureConfigs: function () {
  290. this.loadGlobals();
  291. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  292. var uiConfigs = this.loadUiSideConfigs();
  293. this.set('configs', storedConfigs.concat(uiConfigs));
  294. },
  295. loadGlobals: function () {
  296. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  297. this.set('globalProperties', globals);
  298. this.loadUsersToGlobal();
  299. },
  300. loadUsersToGlobal: function () {
  301. if (!this.get('serviceUsers').length) {
  302. this.loadUsersFromServer();
  303. }
  304. App.router.get('mainAdminController.serviceUsers').forEach(function (_user) {
  305. this.get('globalProperties').pushObject(_user);
  306. }, this);
  307. },
  308. loadUsersFromServer: function () {
  309. var self = this;
  310. if (App.testMode) {
  311. var serviceUsers = this.get('serviceUsers');
  312. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  313. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  314. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  315. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  316. } else {
  317. App.router.get('mainAdminController').getSecurityStatusFromServer();
  318. }
  319. },
  320. loadClusterConfigs: function () {
  321. var self = this;
  322. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
  323. App.ajax.send({
  324. name: 'admin.security.add.cluster_configs',
  325. sender: this,
  326. success: 'loadClusterConfigsSuccessCallback',
  327. error: 'loadClusterConfigsErrorCallback'
  328. });
  329. },
  330. loadClusterConfigsSuccessCallback: function (data) {
  331. var self = this;
  332. //prepare tags to fetch all configuration for a service
  333. this.get('content.services').forEach(function (_secureService) {
  334. if (_secureService.serviceName !== 'GENERAL') {
  335. self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
  336. }
  337. });
  338. this.getAllConfigurations();
  339. },
  340. loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
  341. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  342. console.log("TRACE: error code status is: " + request.status);
  343. },
  344. /**
  345. * set tagnames for configuration of the *-site.xml
  346. */
  347. setServiceTagNames: function (secureService, configs) {
  348. console.log("TRACE: In setServiceTagNames function:");
  349. //var serviceConfigTags = this.get('serviceConfigTags');
  350. for (var index in configs) {
  351. if (secureService.sites && secureService.sites.contains(index)) {
  352. var serviceConfigObj = {
  353. siteName: index,
  354. tagName: configs[index].tag,
  355. newTagName: null,
  356. configs: {}
  357. };
  358. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  359. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  360. }
  361. }
  362. return serviceConfigObj;
  363. },
  364. applyConfigurationsToCluster: function () {
  365. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
  366. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  367. this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName, properties: _serviceConfig.configs});
  368. }, this);
  369. },
  370. applyConfigurationToCluster: function (data) {
  371. var clusterData = {
  372. Clusters: {
  373. desired_config: data
  374. }
  375. };
  376. App.ajax.send({
  377. name: 'admin.security.apply_configuration',
  378. sender: this,
  379. data: {
  380. clusterData: clusterData
  381. },
  382. success: 'applyConfigurationToClusterSuccessCallback',
  383. error: 'applyConfigurationToClusterErrorCallback'
  384. });
  385. },
  386. applyConfigurationToClusterSuccessCallback: function (data) {
  387. this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
  388. if (this.get('noOfWaitingAjaxCalls') == 0) {
  389. var currentStage = this.get('stages').findProperty('stage', 'stage3');
  390. currentStage.set('isSuccess', true);
  391. currentStage.set('isCompleted', true);
  392. }
  393. },
  394. applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
  395. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  396. },
  397. /**
  398. * gets site config properties from server and sets it for every configuration
  399. * @param serviceConfigTags
  400. */
  401. getAllConfigurations: function () {
  402. var urlParams = [];
  403. this.get('serviceConfigTags').forEach(function (_tag) {
  404. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  405. }, this);
  406. if (urlParams.length > 0) {
  407. App.ajax.send({
  408. name: 'admin.security.all_configurations',
  409. sender: this,
  410. data: {
  411. urlParams: urlParams.join('|')
  412. },
  413. success: 'getAllConfigurationsSuccessCallback',
  414. error: 'getAllConfigurationsErrorCallback'
  415. });
  416. }
  417. },
  418. getAllConfigurationsSuccessCallback: function (data) {
  419. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  420. this.get('serviceConfigTags').forEach(function (_tag) {
  421. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  422. });
  423. this.addSecureConfigs();
  424. this.applyConfigurationsToCluster();
  425. },
  426. getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
  427. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  428. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  429. console.log("TRACE: error code status is: " + request.status);
  430. },
  431. addSecureConfigs: function () {
  432. this.get('serviceConfigTags').forEach(function (_serviceConfigTags, index) {
  433. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  434. if (_serviceConfigTags.siteName === 'global') {
  435. this.get('globalProperties').forEach(function (_globalProperty) {
  436. _serviceConfigTags.configs[_globalProperty.name] = _globalProperty.value;
  437. }, this);
  438. }
  439. else {
  440. this.get('configs').filterProperty('id', 'site property').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  441. _serviceConfigTags.configs[_config.name] = _config.value;
  442. }, this);
  443. }
  444. }, this);
  445. }
  446. });