disable.js 13 KB

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