disable.js 14 KB

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