security_progress_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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.MainAdminSecurityProgressController = Em.Controller.extend({
  20. name: 'mainAdminSecurityProgressController',
  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. serviceConfigTags: [],
  38. globalProperties: [],
  39. totalSteps: 3,
  40. isSubmitDisabled: true,
  41. hasHostPopup: true,
  42. services: [],
  43. serviceTimestamp: null,
  44. retry: function () {
  45. var failedStage = this.get('stages').findProperty('isError', true);
  46. if (failedStage) {
  47. failedStage.set('isStarted', false);
  48. failedStage.set('isError', false);
  49. this.startStage(failedStage);
  50. }
  51. },
  52. updateServices: function () {
  53. this.services.clear();
  54. var services = this.get("services");
  55. this.get("stages").forEach(function (stage) {
  56. var newService = Ember.Object.create({
  57. name: stage.label,
  58. hosts: []
  59. });
  60. if (stage && stage.get("polledData")) {
  61. var hostNames = stage.get("polledData").mapProperty('Tasks.host_name').uniq();
  62. hostNames.forEach(function (name) {
  63. newService.hosts.push({
  64. name: name,
  65. publicName: name,
  66. logTasks: stage.polledData.filterProperty("Tasks.host_name", name)
  67. });
  68. });
  69. services.push(newService);
  70. }
  71. });
  72. this.set('serviceTimestamp', App.dateTime());
  73. }.observes('stages.@each.polledData'),
  74. loadStages: function () {
  75. this.get('stages').pushObjects([
  76. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true, name: 'STOP_SERVICES'}),
  77. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false, name: 'APPLY_CONFIGURATIONS'}),
  78. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true, name: 'START_SERVICES'})
  79. ]);
  80. },
  81. startStage: function (currentStage) {
  82. if (this.get('stages').length === this.totalSteps) {
  83. if (!currentStage) {
  84. var startedStages = this.get('stages').filterProperty('isStarted', true);
  85. currentStage = startedStages.findProperty('isCompleted', false);
  86. }
  87. if (currentStage && currentStage.get('isPolling') === true) {
  88. currentStage.set('isStarted', true);
  89. currentStage.start();
  90. } else if (currentStage && currentStage.get('name') === 'APPLY_CONFIGURATIONS') {
  91. currentStage.set('isStarted', true);
  92. if (App.testMode) {
  93. currentStage.set('isError', false);
  94. currentStage.set('isSuccess', true);
  95. } else {
  96. this.loadClusterConfigs();
  97. }
  98. } else if (currentStage && currentStage.get('name') === 'DELETE_ATS') {
  99. currentStage.set('isStarted', true);
  100. if (App.testMode) {
  101. currentStage.set('isError', false);
  102. currentStage.set('isSuccess', true);
  103. } else {
  104. var timeLineServer = App.Service.find('YARN').get('hostComponents').findProperty('componentName', 'APP_TIMELINE_SERVER');
  105. if (timeLineServer && !App.router.get('mainAdminSecurityController.securityEnabled')) {
  106. this.deleteComponents('APP_TIMELINE_SERVER', timeLineServer.get('host.hostName'));
  107. }
  108. }
  109. }
  110. }
  111. },
  112. onCompleteStage: function () {
  113. if (this.get('stages').length === this.totalSteps) {
  114. var index = this.get('stages').filterProperty('isSuccess', true).length;
  115. if (index > 0) {
  116. var lastCompletedStageResult = this.get('stages').objectAt(index - 1).get('isSuccess');
  117. if (lastCompletedStageResult) {
  118. var nextStage = this.get('stages').objectAt(index);
  119. this.moveToNextStage(nextStage);
  120. }
  121. }
  122. }
  123. },
  124. moveToNextStage: function (nextStage) {
  125. if (!nextStage) {
  126. nextStage = this.get('stages').findProperty('isStarted', false);
  127. }
  128. if (nextStage) {
  129. this.startStage(nextStage);
  130. }
  131. },
  132. addInfoToStages: function () {
  133. this.addInfoToStage2();
  134. this.addInfoToStage4();
  135. },
  136. addInfoToStage2: function () {
  137. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  138. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  139. var data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.stopAllServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  140. stage2.set('url', url);
  141. stage2.set('data', data);
  142. },
  143. addInfoToStage4: function () {
  144. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  145. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services?params/run_smoke_test=true';
  146. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.startAllServices') + '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  147. stage4.set('url', url);
  148. stage4.set('data', data);
  149. },
  150. loadClusterConfigs: function () {
  151. App.ajax.send({
  152. name: 'admin.security.add.cluster_configs',
  153. sender: this,
  154. success: 'loadClusterConfigsSuccessCallback',
  155. error: 'loadClusterConfigsErrorCallback'
  156. });
  157. },
  158. loadClusterConfigsSuccessCallback: function (data) {
  159. var self = this;
  160. //prepare tags to fetch all configuration for a service
  161. this.get('secureServices').forEach(function (_secureService) {
  162. self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
  163. },this);
  164. this.getAllConfigurations();
  165. },
  166. loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
  167. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  168. if (stage3) {
  169. stage3.set('isSuccess', false);
  170. stage3.set('isError', true);
  171. }
  172. console.log("TRACE: error code status is: " + request.status);
  173. },
  174. /**
  175. * set tagnames for configuration of the *-site.xml
  176. */
  177. setServiceTagNames: function (secureService, configs) {
  178. //var serviceConfigTags = this.get('serviceConfigTags');
  179. for (var index in configs) {
  180. if (secureService.sites && secureService.sites.contains(index)) {
  181. var serviceConfigObj = {
  182. siteName: index,
  183. tagName: configs[index].tag,
  184. newTagName: null,
  185. configs: {}
  186. };
  187. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  188. }
  189. }
  190. return serviceConfigObj;
  191. },
  192. applyConfigurationsToCluster: function () {
  193. var configData = [];
  194. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  195. var Clusters = {
  196. Clusters: {
  197. desired_config: {
  198. type: _serviceConfig.siteName,
  199. tag: _serviceConfig.newTagName,
  200. properties: _serviceConfig.configs
  201. }
  202. }
  203. };
  204. configData.pushObject(JSON.stringify(Clusters));
  205. }, this);
  206. var data = {
  207. configData: '[' + configData.toString() + ']'
  208. };
  209. App.ajax.send({
  210. name: 'admin.security.apply_configurations',
  211. sender: this,
  212. data: data,
  213. success: 'applyConfigurationToClusterSuccessCallback',
  214. error: 'applyConfigurationToClusterErrorCallback'
  215. });
  216. },
  217. applyConfigurationToClusterSuccessCallback: function (data) {
  218. var currentStage = this.get('stages').findProperty('stage', 'stage3');
  219. currentStage.set('isSuccess', true);
  220. currentStage.set('isError', false);
  221. },
  222. applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
  223. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  224. if (stage3) {
  225. stage3.set('isSuccess', false);
  226. stage3.set('isError', true);
  227. }
  228. },
  229. /**
  230. * gets site config properties from server and sets it for every configuration
  231. */
  232. getAllConfigurations: function () {
  233. var urlParams = [];
  234. this.get('serviceConfigTags').forEach(function (_tag) {
  235. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  236. }, this);
  237. if (urlParams.length > 0) {
  238. App.ajax.send({
  239. name: 'admin.get.all_configurations',
  240. sender: this,
  241. data: {
  242. urlParams: urlParams.join('|')
  243. },
  244. success: 'getAllConfigurationsSuccessCallback',
  245. error: 'getAllConfigurationsErrorCallback'
  246. });
  247. }
  248. },
  249. getAllConfigurationsSuccessCallback: function (data) {
  250. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  251. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  252. this.get('serviceConfigTags').forEach(function (_tag) {
  253. if (!data.items.someProperty('type', _tag.siteName)) {
  254. console.log("Error: Metadata for secure services (secure_configs.js) is having config tags that are not being retrieved from server");
  255. if (stage3) {
  256. stage3.set('isSuccess', false);
  257. stage3.set('isError', true);
  258. }
  259. }
  260. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  261. }, this);
  262. if (this.manageSecureConfigs()) {
  263. this.escapeXMLCharacters(this.get('serviceConfigTags'));
  264. this.applyConfigurationsToCluster();
  265. }
  266. },
  267. getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
  268. var stage3 = this.get('stages').findProperty('stage', 'stage3');
  269. if (stage3) {
  270. stage3.set('isSuccess', false);
  271. stage3.set('isError', true);
  272. }
  273. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  274. console.log("TRACE: error code status is: " + request.status);
  275. },
  276. /*
  277. Iterate over keys of all configurations and escape xml characters in their values
  278. */
  279. escapeXMLCharacters: function (serviceConfigTags) {
  280. serviceConfigTags.forEach(function (_serviceConfigTags) {
  281. var configs = _serviceConfigTags.configs;
  282. for (var key in configs) {
  283. configs[key] = App.config.escapeXMLCharacters(configs[key]);
  284. }
  285. }, this);
  286. },
  287. saveStagesOnRequestId: function () {
  288. this.saveStages();
  289. }.observes('stages.@each.requestId'),
  290. saveStagesOnCompleted: function () {
  291. this.saveStages();
  292. }.observes('stages.@each.isCompleted'),
  293. saveStages: function () {
  294. var stages = [];
  295. if (this.get('stages').length === this.totalSteps) {
  296. this.get('stages').forEach(function (_stage) {
  297. var stage = {
  298. name: _stage.get('name'),
  299. stage: _stage.get('stage'),
  300. label: _stage.get('label'),
  301. isPolling: _stage.get('isPolling'),
  302. isVisible: _stage.get('isVisible'),
  303. isStarted: _stage.get('isStarted'),
  304. requestId: _stage.get('requestId'),
  305. isSuccess: _stage.get('isSuccess'),
  306. isError: _stage.get('isError'),
  307. url: _stage.get('url'),
  308. polledData: _stage.get('polledData'),
  309. data: _stage.get('data')
  310. };
  311. stages.pushObject(stage);
  312. }, this);
  313. App.db.setSecurityDeployStages(stages);
  314. if (!App.testMode) {
  315. App.clusterStatus.setClusterStatus({
  316. clusterName: this.get('clusterName'),
  317. clusterState: 'ADD_SECURITY_STEP_4',
  318. wizardControllerName: App.router.get('addSecurityController.name'),
  319. localdb: App.db.data
  320. });
  321. }
  322. }
  323. }
  324. });