disable.js 14 KB

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