security_progress_controller.js 12 KB

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