disable.js 12 KB

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