disable.js 14 KB

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