disable.js 16 KB

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