disable.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. App.ajax.send({
  135. name: 'admin.security.cluster_configs',
  136. sender: this,
  137. success: 'loadClusterConfigsSuccessCallback',
  138. error: 'loadClusterConfigsErrorCallback'
  139. });
  140. },
  141. loadClusterConfigsSuccessCallback: function (jsonData) {
  142. var self = this;
  143. //prepare tags to fetch all configuration for a service
  144. this.get('secureServices').forEach(function (_secureService) {
  145. self.setServiceTagNames(_secureService, jsonData.Clusters.desired_configs);
  146. });
  147. this.getAllConfigurations();
  148. },
  149. loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
  150. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  151. console.log("TRACE: error code status is: " + request.status);
  152. },
  153. getAllConfigurations: function () {
  154. var urlParams = [];
  155. this.get('serviceConfigTags').forEach(function (_tag) {
  156. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  157. }, this);
  158. if (urlParams.length > 0) {
  159. App.ajax.send({
  160. name: 'admin.security.all_configurations',
  161. sender: this,
  162. data: {
  163. urlParams: urlParams.join('|')
  164. },
  165. success: 'getAllConfigurationsSuccessCallback',
  166. error: 'getAllConfigurationsErrorCallback'
  167. });
  168. }
  169. },
  170. getAllConfigurationsSuccessCallback: function(data) {
  171. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  172. this.get('serviceConfigTags').forEach(function (_tag) {
  173. _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
  174. });
  175. this.removeSecureConfigs();
  176. this.applyConfigurationsToCluster();
  177. },
  178. getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
  179. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  180. console.log("TRACE: In error function for the getServiceConfigsFromServer call");
  181. console.log("TRACE: error code status is: " + request.status);
  182. },
  183. loadSecureServices: function () {
  184. var secureServices = require('data/secure_configs');
  185. var installedServices = App.Service.find().mapProperty('serviceName');
  186. //General (only non service tab) tab is always displayed
  187. installedServices.forEach(function (_service) {
  188. var secureService = secureServices.findProperty('serviceName', _service);
  189. if (secureService) {
  190. this.get('secureServices').push(secureService);
  191. }
  192. }, this);
  193. },
  194. applyConfigurationsToCluster: function () {
  195. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
  196. this.get('serviceConfigTags').forEach(function (_serviceConfig) {
  197. this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName, properties: _serviceConfig.configs});
  198. }, this);
  199. },
  200. applyConfigurationToCluster: function (data) {
  201. var clusterData = {
  202. Clusters: {
  203. desired_config: data
  204. }
  205. };
  206. App.ajax.send({
  207. name: 'admin.security.apply_configuration',
  208. sender: this,
  209. data: {
  210. clusterData: clusterData
  211. },
  212. success: 'applyConfigurationToClusterSuccessCallback',
  213. error: 'applyConfigurationToClusterErrorCallback'
  214. });
  215. },
  216. applyConfigurationToClusterSuccessCallback: function (data) {
  217. this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
  218. if (this.get('noOfWaitingAjaxCalls') == 0) {
  219. var currentStage = this.get('stages').findProperty('stage', 'stage3');
  220. currentStage.set('isSuccess', true);
  221. currentStage.set('isCompleted', true);
  222. }
  223. },
  224. applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
  225. this.get('stages').findProperty('stage', 'stage3').set('isError', true);
  226. },
  227. getAllConfigsFromServer: function () {
  228. this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length - 1);
  229. this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
  230. if (_serviceConfigTags.serviceName !== 'MAPREDUCE' || _serviceConfigTags.siteName !== 'core-site') { //skip MapReduce core-site configuration
  231. this.getServiceConfigsFromServer(_serviceConfigTags);
  232. }
  233. }, this);
  234. },
  235. removeSecureConfigs: function () {
  236. this.get('serviceConfigTags').forEach(function (_serviceConfigTags, index) {
  237. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  238. if (_serviceConfigTags.siteName === 'global') {
  239. this.get('secureProperties').forEach(function (_config) {
  240. if (_config.name in _serviceConfigTags.configs) {
  241. delete _serviceConfigTags.configs[_config.name];
  242. }
  243. }, this);
  244. _serviceConfigTags.configs.security_enabled = false;
  245. } else {
  246. this.get('configMapping').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  247. var configName = _config.name;
  248. if (configName in _serviceConfigTags.configs) {
  249. switch (configName) {
  250. case 'dfs.datanode.address':
  251. _serviceConfigTags.configs[configName] = '0.0.0.0:50010';
  252. break;
  253. case 'dfs.datanode.http.address':
  254. _serviceConfigTags.configs[configName] = '0.0.0.0:50075';
  255. break;
  256. case 'hbase.security.authentication':
  257. _serviceConfigTags.configs[configName] = 'simple';
  258. break;
  259. case 'hbase.rpc.engine':
  260. _serviceConfigTags.configs[configName] = 'org.apache.hadoop.hbase.ipc.WritableRpcEngine';
  261. break;
  262. case 'hbase.security.authorization':
  263. _serviceConfigTags.configs[configName] = 'false';
  264. break;
  265. case 'hbase.coprocessor.master.classes':
  266. _serviceConfigTags.configs[configName] = 'org.apache.hadoop.hbase.security.access.AccessController';
  267. break;
  268. default:
  269. delete _serviceConfigTags.configs[configName];
  270. }
  271. }
  272. console.log("Not Deleted" + _config.name);
  273. }, this);
  274. }
  275. }, this);
  276. }
  277. });