disable.js 15 KB

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