step3.js 18 KB

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