disable.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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.MainAdminSecurityDisableController = Em.Controller.extend({
  20. name: 'mainAdminSecurityDisableController',
  21. configMapping: require('data/secure_mapping').slice(0),
  22. stages: [],
  23. configs: [],
  24. noOfWaitingAjaxCalls: 0,
  25. secureServices: [],
  26. serviceConfigTags: [],
  27. globalProperties: [],
  28. clearStep: function () {
  29. this.get('stages').clear();
  30. this.get('secureServices').clear();
  31. },
  32. loadStep: function () {
  33. this.clearStep();
  34. this.loadStages();
  35. this.loadSecureServices();
  36. this.addInfoToStages();
  37. this.moveToNextStage();
  38. },
  39. loadStages: function () {
  40. this.get('stages').pushObjects([
  41. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true}),
  42. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false}),
  43. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true})
  44. ]);
  45. },
  46. startStage: function () {
  47. var startedStages = this.get('stages').filterProperty('isStarted', true);
  48. if (startedStages.length) {
  49. var currentStage = startedStages.findProperty('isCompleted', false);
  50. if (currentStage && currentStage.get('isPolling') === true) {
  51. currentStage.start();
  52. } else if (currentStage && currentStage.get('stage') === 'stage3') {
  53. if (App.testMode) {
  54. currentStage.set('isSuccess', true);
  55. currentStage.set('isCompleted', true);
  56. this.moveToNextStage();
  57. } else {
  58. this.loadConfigsForAllServices();
  59. }
  60. }
  61. }
  62. }.observes('stages.@each.isStarted'),
  63. onCompleteStage: function () {
  64. var index = this.get('stages').filterProperty('isSuccess', true).length;
  65. if (index > 0) {
  66. this.moveToNextStage();
  67. }
  68. }.observes('stages.@each.isSuccess'),
  69. addInfoToStages: function () {
  70. this.addInfoToStage2();
  71. this.addInfoToStage3();
  72. this.addInfoToStage4();
  73. },
  74. addInfoToStage1: function () {
  75. var stage1 = this.get('stages').findProperty('stage', 'stage1');
  76. if (App.testMode) {
  77. stage1.set('isSucces', true);
  78. stage1.set('isStarted', true);
  79. stage1.set('isCompleted', true);
  80. }
  81. },
  82. addInfoToStage2: function () {
  83. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  84. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  85. var data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  86. stage2.set('url', url);
  87. stage2.set('data', data);
  88. },
  89. addInfoToStage3: function () {
  90. },
  91. addInfoToStage4: function () {
  92. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  93. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  94. var data = '{"ServiceInfo": {"state": "STARTED"}}';
  95. stage4.set('url', url);
  96. stage4.set('data', data);
  97. },
  98. loadSecureServices: function() {
  99. var secureServices = require('data/secure_configs');
  100. var installedServices = App.Service.find().mapProperty('serviceName');
  101. //General (only non service tab) tab is always displayed
  102. installedServices.forEach(function (_service) {
  103. var secureService = secureServices.findProperty('serviceName', _service);
  104. if (secureService) {
  105. this.get('secureServices').push(secureService);
  106. }
  107. }, this);
  108. },
  109. /**
  110. * gets site config properties from server and sets it for every configuration
  111. * @param serviceConfigTags
  112. */
  113. getServiceConfigsFromServer: function (serviceConfigTags) {
  114. var self = this;
  115. var properties = {};
  116. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/configurations/?type=' + serviceConfigTags.siteName + '&tag=' + serviceConfigTags.tagName;
  117. $.ajax({
  118. type: 'GET',
  119. url: url,
  120. async: true,
  121. timeout: 10000,
  122. dataType: 'json',
  123. success: function (data) {
  124. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  125. console.log("TRACE: The url is: " + url);
  126. serviceConfigTags.configs = data.items.findProperty('tag', serviceConfigTags.tagName).properties;
  127. self.set('noOfWaitingAjaxCalls', self.get('noOfWaitingAjaxCalls') - 1);
  128. if (self.get('noOfWaitingAjaxCalls') == 0) {
  129. self.removeSecureConfigs();
  130. self.createConfigurations();
  131. }
  132. },
  133. error: function (request, ajaxOptions, error) {
  134. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  135. },
  136. statusCode: require('data/statusCodes')
  137. });
  138. },
  139. loadConfigsForAllServices: function () {
  140. this.set('noOfWaitingAjaxCalls', this.get('secureServices').length - 1);
  141. this.get('secureServices').forEach(function (_secureService, index) {
  142. if (_secureService.serviceName !== 'GENERAL' && _secureService.serviceName !== 'NAGIOS') {
  143. this.getConfigDetailsFromServer(_secureService, index);
  144. }
  145. }, this);
  146. },
  147. getConfigDetailsFromServer: function (secureService, id) {
  148. var self = this;
  149. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services/' + secureService.serviceName;
  150. $.ajax({
  151. type: 'GET',
  152. url: url,
  153. timeout: 10000,
  154. dataType: 'text',
  155. success: function (data) {
  156. console.log("TRACE: In success function for the GET getServciceConfigs call");
  157. console.log("TRACE: The url is: " + url);
  158. var jsonData = jQuery.parseJSON(data);
  159. //prepare tags to fetch all configuration for a service
  160. self.setServiceTagNames(secureService.serviceName, jsonData.ServiceInfo.desired_configs);
  161. self.set('noOfWaitingAjaxCalls', self.get('noOfWaitingAjaxCalls') - 1);
  162. if (self.get('noOfWaitingAjaxCalls') == 0) {
  163. self.getAllConfigsFromServer();
  164. }
  165. },
  166. error: function (request, ajaxOptions, error) {
  167. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  168. console.log("TRACE: In error function for the getServciceConfigs call");
  169. console.log("TRACE: value of the url is: " + url);
  170. console.log("TRACE: error code status is: " + request.status);
  171. },
  172. statusCode: require('data/statusCodes')
  173. });
  174. },
  175. /**
  176. * set tagnames for configuration of the *-site.xml
  177. */
  178. setServiceTagNames: function (secureServiceName, configs) {
  179. console.log("TRACE: In setServiceTagNames function:");
  180. //var serviceConfigTags = this.get('serviceConfigTags');
  181. for (var index in configs) {
  182. var serviceConfigObj = {
  183. serviceName: secureServiceName,
  184. siteName: index,
  185. tagName: configs[index],
  186. newTagName: null,
  187. configs: {}
  188. };
  189. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  190. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  191. }
  192. return serviceConfigObj;
  193. },
  194. getAllConfigsFromServer: function () {
  195. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length - 1);
  196. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  197. if (_serviceConfigTags.serviceName !== 'MAPREDUCE' || _serviceConfigTags.siteName !== 'core-site') { //skip MapReduce core-site configuration
  198. this.getServiceConfigsFromServer(_serviceConfigTags);
  199. }
  200. }, this);
  201. },
  202. createConfigurations: function () {
  203. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length - 1);
  204. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  205. if (_serviceConfigTags.serviceName !== 'MAPREDUCE' || _serviceConfigTags.siteName !== 'core-site') { //skip MapReduce core-site configuration
  206. this.createConfiguration(_serviceConfigTags);
  207. }
  208. }, this);
  209. },
  210. createConfiguration: function (serviceConfigTags) {
  211. var self = this;
  212. var clusterName = App.router.getClusterName();
  213. var url = App.apiPrefix + '/clusters/' + clusterName + '/configurations';
  214. var data = this.createConfigurationData(serviceConfigTags);
  215. $.ajax({
  216. type: 'POST',
  217. url: url,
  218. data: JSON.stringify(data),
  219. dataType: 'text',
  220. timeout: 5000,
  221. success: function (data) {
  222. var jsonData = jQuery.parseJSON(data);
  223. self.set('noOfWaitingAjaxCalls', self.get('noOfWaitingAjaxCalls') - 1);
  224. if (self.get('noOfWaitingAjaxCalls') == 0) {
  225. self.applyConfigurationToServices();
  226. }
  227. },
  228. error: function (request, ajaxOptions, error) {
  229. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  230. console.log('TRACE: In Error ');
  231. console.log('TRACE: Error message is: ' + request.responseText);
  232. console.log("TRACE: value of the url is: " + url);
  233. },
  234. statusCode: require('data/statusCodes')
  235. });
  236. },
  237. createConfigurationData: function (serviceConfigTags) {
  238. return {"type": serviceConfigTags.siteName, "tag": serviceConfigTags.newTagName, "properties": serviceConfigTags.configs};
  239. },
  240. applyConfigurationToServices: function () {
  241. this.applyHdfsCoretoMaprCore();
  242. this.set('noOfWaitingAjaxCalls', this.get('secureServices').length-1);
  243. this.get('secureServices').forEach(function (_service) {
  244. if (_service.serviceName !== 'GENERAL' && _service.serviceName !== 'NAGIOS') {
  245. var data = {config: {}};
  246. this.get('serviceConfigTags').filterProperty('serviceName', _service.serviceName).forEach(function (_serviceConfig) {
  247. data.config[_serviceConfig.siteName] = _serviceConfig.newTagName;
  248. }, this);
  249. this.applyConfToService(_service.serviceName, data);
  250. }
  251. }, this);
  252. },
  253. applyHdfsCoretoMaprCore: function () {
  254. this.get('serviceConfigTags').filterProperty('serviceName', 'MAPREDUCE').findProperty('siteName', 'core-site').newTagName = this.get('serviceConfigTags').filterProperty('serviceName', 'HDFS').findProperty('siteName', 'core-site').newTagName;
  255. },
  256. applyConfToService: function (serviceName, data) {
  257. var self = this;
  258. var clusterName = App.router.getClusterName();
  259. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + serviceName;
  260. $.ajax({
  261. type: 'PUT',
  262. url: url,
  263. async: false,
  264. dataType: 'text',
  265. data: JSON.stringify(data),
  266. timeout: 5000,
  267. success: function (data) {
  268. self.set('noOfWaitingAjaxCalls', self.get('noOfWaitingAjaxCalls') - 1);
  269. if (self.get('noOfWaitingAjaxCalls') == 0) {
  270. var currentStage = self.get('stages').findProperty('stage', 'stage3');
  271. currentStage.set('isSuccess', true);
  272. currentStage.set('isCompleted', true);
  273. }
  274. },
  275. error: function (request, ajaxOptions, error) {
  276. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  277. },
  278. statusCode: require('data/statusCodes')
  279. });
  280. console.log("Exiting applyCreatedConfToService");
  281. },
  282. moveToNextStage: function () {
  283. var nextStage = this.get('stages').findProperty('isStarted', false);
  284. if (nextStage) {
  285. nextStage.set('isStarted', true);
  286. } else {
  287. this.set('isSubmitDisabled', false);
  288. }
  289. },
  290. removeSecureConfigs: function () {
  291. this.get('serviceConfigTags').forEach(function (_serviceConfigTags, index) {
  292. if (_serviceConfigTags.siteName === 'global') {
  293. _serviceConfigTags.newTagName = 'version' + (new Date).getTime() + index;
  294. if ('security_enabled' in _serviceConfigTags.configs) {
  295. _serviceConfigTags.configs.security_enabled = false;
  296. }
  297. } else {
  298. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  299. this.get('configMapping').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  300. if (_config.name in _serviceConfigTags.configs) {
  301. delete _serviceConfigTags.configs[_config.name];
  302. }
  303. console.log("*******Not Deleted" + _config.name);
  304. }, this);
  305. }
  306. }, this);
  307. }
  308. });