security_progress_controller.js 13 KB

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