disable.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. this.get('serviceConfigTags').clear();
  33. },
  34. loadStep: function () {
  35. this.clearStep();
  36. this.loadStages();
  37. this.loadSecureServices();
  38. this.addInfoToStages();
  39. this.moveToNextStage();
  40. },
  41. loadStages: function () {
  42. this.get('stages').pushObjects([
  43. App.Poll.create({stage: 'stage2', label: Em.I18n.translations['admin.addSecurity.apply.stage2'], isPolling: true}),
  44. App.Poll.create({stage: 'stage3', label: Em.I18n.translations['admin.addSecurity.apply.stage3'], isPolling: false}),
  45. App.Poll.create({stage: 'stage4', label: Em.I18n.translations['admin.addSecurity.apply.stage4'], isPolling: true})
  46. ]);
  47. },
  48. moveToNextStage: function () {
  49. var nextStage = this.get('stages').findProperty('isStarted', false);
  50. if (nextStage) {
  51. nextStage.set('isStarted', true);
  52. } else {
  53. this.set('isSubmitDisabled', false);
  54. }
  55. },
  56. startStage: function () {
  57. var startedStages = this.get('stages').filterProperty('isStarted', true);
  58. if (startedStages.length) {
  59. var currentStage = startedStages.findProperty('isCompleted', false);
  60. if (currentStage && currentStage.get('isPolling') === true) {
  61. currentStage.start();
  62. } else if (currentStage && currentStage.get('stage') === 'stage3') {
  63. if (App.testMode) {
  64. currentStage.set('isSuccess', true);
  65. currentStage.set('isCompleted', true);
  66. this.moveToNextStage();
  67. } else {
  68. var self = this;
  69. window.setTimeout(function () {
  70. self.loadClusterConfigs();
  71. }, 12000);
  72. }
  73. }
  74. }
  75. }.observes('stages.@each.isStarted'),
  76. onCompleteStage: function () {
  77. var index = this.get('stages').filterProperty('isCompleted', true).length;
  78. if (index > 0) {
  79. var self = this;
  80. var lastCompletedStageResult = this.get('stages').objectAt(index - 1).get('isSuccess');
  81. if (lastCompletedStageResult) {
  82. self.moveToNextStage();
  83. }
  84. }
  85. }.observes('stages.@each.isCompleted'),
  86. addInfoToStages: function () {
  87. this.addInfoToStage2();
  88. this.addInfoToStage3();
  89. this.addInfoToStage4();
  90. },
  91. addInfoToStage1: function () {
  92. var stage1 = this.get('stages').findProperty('stage', 'stage1');
  93. if (App.testMode) {
  94. stage1.set('isSucces', true);
  95. stage1.set('isStarted', true);
  96. stage1.set('isCompleted', true);
  97. }
  98. },
  99. addInfoToStage2: function () {
  100. var stage2 = this.get('stages').findProperty('stage', 'stage2');
  101. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  102. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.stopAllServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  103. stage2.set('url', url);
  104. stage2.set('data', data);
  105. },
  106. addInfoToStage3: function () {
  107. },
  108. addInfoToStage4: function () {
  109. var stage4 = this.get('stages').findProperty('stage', 'stage4');
  110. var url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services';
  111. var data = '{"RequestInfo": {"context": "' + Em.I18n.t('requestInfo.startAllServices') + '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  112. stage4.set('url', url);
  113. stage4.set('data', data);
  114. },
  115. /**
  116. * set tagnames for configuration of the *-site.xml
  117. */
  118. setServiceTagNames: function (secureService, configs) {
  119. for (var index in configs) {
  120. if (secureService.sites && secureService.sites.contains(index)) {
  121. var serviceConfigObj = {
  122. siteName: index,
  123. tagName: configs[index].tag,
  124. newTagName: null,
  125. configs: {}
  126. };
  127. console.log("The value of serviceConfigTags[index]: " + configs[index]);
  128. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  129. }
  130. }
  131. return serviceConfigObj;
  132. },
  133. loadClusterConfigs: function () {
  134. var self = this;
  135. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
  136. $.ajax({
  137. type: 'GET',
  138. url: url,
  139. timeout: 10000,
  140. dataType: 'text',
  141. success: function (data) {
  142. var jsonData = jQuery.parseJSON(data);
  143. //prepare tags to fetch all configuration for a service
  144. self.get('secureServices').forEach(function (_secureService) {
  145. self.setServiceTagNames(_secureService, jsonData.Clusters.desired_configs);
  146. });
  147. self.getAllConfigurations();
  148. },
  149. error: function (request, ajaxOptions, error) {
  150. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  151. console.log("TRACE: error code status is: " + request.status);
  152. },
  153. statusCode: require('data/statusCodes')
  154. });
  155. },
  156. getAllConfigurations: function () {
  157. var self = this;
  158. var urlParams = [];
  159. this.get('serviceConfigTags').forEach(function (_tag) {
  160. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  161. }, this);
  162. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/configurations?' + urlParams.join('|');
  163. if (urlParams.length > 0) {
  164. $.ajax({
  165. type: 'GET',
  166. url: url,
  167. async: true,
  168. timeout: 10000,
  169. dataType: 'json',
  170. success: function (data) {
  171. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  172. console.log("TRACE: The url is: " + url);
  173. self.get('serviceConfigTags').forEach(function (_tag) {
  174. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  175. });
  176. self.removeSecureConfigs();
  177. self.applyConfigurationsToCluster();
  178. },
  179. error: function (request, ajaxOptions, error) {
  180. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  181. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  182. console.log("TRACE: value of the url is: " + url);
  183. console.log("TRACE: error code status is: " + request.status);
  184. },
  185. statusCode: require('data/statusCodes')
  186. });
  187. }
  188. },
  189. loadSecureServices: function () {
  190. var secureServices = require('data/secure_configs');
  191. var installedServices = App.Service.find().mapProperty('serviceName');
  192. //General (only non service tab) tab is always displayed
  193. installedServices.forEach(function (_service) {
  194. var secureService = secureServices.findProperty('serviceName', _service);
  195. if (secureService) {
  196. this.get('secureServices').push(secureService);
  197. }
  198. }, this);
  199. },
  200. applyConfigurationsToCluster: function () {
  201. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
  202. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  203. this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName, properties: _serviceConfig.configs});
  204. }, this);
  205. },
  206. applyConfigurationToCluster: function (data) {
  207. var self = this;
  208. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
  209. var clusterData = {
  210. Clusters: {
  211. desired_config: data
  212. }
  213. };
  214. $.ajax({
  215. type: 'PUT',
  216. url: url,
  217. async: false,
  218. dataType: 'text',
  219. data: JSON.stringify(clusterData),
  220. timeout: 5000,
  221. success: function (data) {
  222. self.set('noOfWaitingAjaxCalls', self.get('noOfWaitingAjaxCalls') - 1);
  223. if (self.get('noOfWaitingAjaxCalls') == 0) {
  224. var currentStage = self.get('stages').findProperty('stage', 'stage3');
  225. currentStage.set('isSuccess', true);
  226. currentStage.set('isCompleted', true);
  227. }
  228. },
  229. error: function (request, ajaxOptions, error) {
  230. self.get('stages').findProperty('stage', 'stage3').set('isError', true);
  231. },
  232. statusCode: require('data/statusCodes')
  233. });
  234. },
  235. getAllConfigsFromServer: function () {
  236. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length - 1);
  237. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  238. if (_serviceConfigTags.serviceName !== 'MAPREDUCE' || _serviceConfigTags.siteName !== 'core-site') { //skip MapReduce core-site configuration
  239. this.getServiceConfigsFromServer(_serviceConfigTags);
  240. }
  241. }, this);
  242. },
  243. removeSecureConfigs: function () {
  244. this.get('serviceConfigTags').forEach(function (_serviceConfigTags, index) {
  245. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  246. if (_serviceConfigTags.siteName === 'global') {
  247. this.get('secureProperties').forEach(function (_config) {
  248. if (_config.name in _serviceConfigTags.configs) {
  249. delete _serviceConfigTags.configs[_config.name];
  250. }
  251. }, this);
  252. _serviceConfigTags.configs.security_enabled = false;
  253. } else {
  254. this.get('configMapping').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  255. var configName = _config.name;
  256. if (configName in _serviceConfigTags.configs) {
  257. switch (configName) {
  258. case 'dfs.datanode.address':
  259. _serviceConfigTags.configs[configName] = '0.0.0.0:50010';
  260. break;
  261. case 'dfs.datanode.http.address':
  262. _serviceConfigTags.configs[configName] = '0.0.0.0:50075';
  263. break;
  264. case 'hbase.security.authentication':
  265. _serviceConfigTags.configs[configName] = 'simple';
  266. break;
  267. case 'hbase.rpc.engine':
  268. _serviceConfigTags.configs[configName] = 'org.apache.hadoop.hbase.ipc.WritableRpcEngine';
  269. break;
  270. case 'hbase.security.authorization':
  271. _serviceConfigTags.configs[configName] = 'false';
  272. break;
  273. case 'hbase.coprocessor.master.classes':
  274. _serviceConfigTags.configs[configName] = 'org.apache.hadoop.hbase.security.access.AccessController';
  275. break;
  276. default:
  277. delete _serviceConfigTags.configs[configName];
  278. }
  279. }
  280. console.log("Not Deleted" + _config.name);
  281. }, this);
  282. }
  283. }, this);
  284. }
  285. });