security_progress_controller.js 13 KB

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