security_progress_controller.js 12 KB

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