disable.js 17 KB

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