step4_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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.ReassignMasterWizardStep4Controller = App.HighAvailabilityProgressPageController.extend({
  20. isReassign: true,
  21. commands: ['stopServices', 'createHostComponents', 'putHostComponentsInMaintenanceMode', 'reconfigure', 'installHostComponents', 'startZooKeeperServers', 'startNameNode', 'deleteHostComponents', 'startServices'],
  22. clusterDeployState: 'REASSIGN_MASTER_INSTALLING',
  23. multiTaskCounter: 0,
  24. hostComponents: [],
  25. loadStep: function () {
  26. if (this.get('content.reassign.component_name') === 'NAMENODE' && !App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE')) {
  27. this.set('hostComponents', ['NAMENODE', 'ZKFC']);
  28. } else {
  29. this.set('hostComponents', [this.get('content.reassign.component_name')]);
  30. }
  31. this.set('serviceName', [this.get('content.reassign.service_id')]);
  32. this._super();
  33. },
  34. initializeTasks: function () {
  35. var commands = this.get('commands');
  36. var currentStep = App.router.get('reassignMasterController.currentStep');
  37. var hostComponentsNames = '';
  38. this.get('hostComponents').forEach(function (comp, index) {
  39. hostComponentsNames += index ? '+' : '';
  40. hostComponentsNames += comp === 'ZKFC' ? comp : App.format.role(comp);
  41. }, this);
  42. for (var i = 0; i < commands.length; i++) {
  43. var TaskLabel = i === 3 ? this.get('serviceName') : hostComponentsNames; //For Reconfigure task, show serviceName
  44. var title = Em.I18n.t('services.reassign.step4.task' + i + '.title').format(TaskLabel);
  45. this.get('tasks').pushObject(Ember.Object.create({
  46. title: title,
  47. status: 'PENDING',
  48. id: i,
  49. command: commands[i],
  50. showRetry: false,
  51. showRollback: false,
  52. name: title,
  53. displayName: title,
  54. progress: 0,
  55. isRunning: false,
  56. hosts: []
  57. }));
  58. }
  59. if (this.get('content.hasManualSteps')) {
  60. if (App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE')) {
  61. this.get('tasks').splice(5, 4);
  62. } else {
  63. this.get('tasks').splice(7, 2);
  64. }
  65. } else {
  66. this.get('tasks').splice(5, 2);
  67. }
  68. },
  69. hideRollbackButton: function () {
  70. var failedTask = this.get('tasks').findProperty('showRollback');
  71. if (failedTask) {
  72. failedTask.set('showRollback', false)
  73. }
  74. }.observes('tasks.@each.showRollback'),
  75. onComponentsTasksSuccess: function () {
  76. this.set('multiTaskCounter', this.get('multiTaskCounter') + 1);
  77. if (this.get('multiTaskCounter') >= this.get('hostComponents').length) {
  78. this.onTaskCompleted();
  79. }
  80. },
  81. stopServices: function () {
  82. App.ajax.send({
  83. name: 'reassign.stop_services',
  84. sender: this,
  85. success: 'startPolling',
  86. error: 'onTaskError'
  87. });
  88. },
  89. createHostComponents: function () {
  90. this.set('multiTaskCounter', 0);
  91. var hostComponents = this.get('hostComponents');
  92. var hostName = this.get('content.reassignHosts.target');
  93. for (var i = 0; i < hostComponents.length; i++) {
  94. this.createComponent(hostComponents[i], hostName);
  95. }
  96. },
  97. onCreateComponent: function () {
  98. this.onComponentsTasksSuccess();
  99. },
  100. putHostComponentsInMaintenanceMode: function () {
  101. this.set('multiTaskCounter', 0);
  102. var hostComponents = this.get('hostComponents');
  103. var hostName = this.get('content.reassignHosts.source');
  104. for (var i = 0; i < hostComponents.length; i++) {
  105. App.ajax.send({
  106. name: 'reassign.maintenance_mode',
  107. sender: this,
  108. data: {
  109. hostName: hostName,
  110. componentName: hostComponents[i]
  111. },
  112. success: 'onComponentsTasksSuccess',
  113. error: 'onTaskError'
  114. });
  115. }
  116. },
  117. installHostComponents: function () {
  118. this.set('multiTaskCounter', 0);
  119. var hostComponents = this.get('hostComponents');
  120. var hostName = this.get('content.reassignHosts.target');
  121. for (var i = 0; i < hostComponents.length; i++) {
  122. this.installComponent(hostComponents[i], hostName, hostComponents.length);
  123. }
  124. },
  125. reconfigure: function () {
  126. this.loadConfigsTags();
  127. },
  128. loadConfigsTags: function () {
  129. App.ajax.send({
  130. name: 'config.tags',
  131. sender: this,
  132. success: 'onLoadConfigsTags',
  133. error: 'onTaskError'
  134. });
  135. },
  136. onLoadConfigsTags: function (data) {
  137. var componentName = this.get('content.reassign.component_name');
  138. var urlParams = [];
  139. switch (componentName) {
  140. case 'NAMENODE':
  141. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  142. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  143. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  144. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  145. }
  146. break;
  147. case 'SECONDARY_NAMENODE':
  148. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  149. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  150. break;
  151. case 'JOBTRACKER':
  152. urlParams.push('(type=mapred-site&tag=' + data.Clusters.desired_configs['mapred-site'].tag + ')');
  153. break;
  154. case 'RESOURCEMANAGER':
  155. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  156. break;
  157. }
  158. App.ajax.send({
  159. name: 'reassign.load_configs',
  160. sender: this,
  161. data: {
  162. urlParams: urlParams.join('|')
  163. },
  164. success: 'onLoadConfigs',
  165. error: 'onTaskError'
  166. });
  167. },
  168. configsSitesCount: null,
  169. configsSitesNumber: null,
  170. onLoadConfigs: function (data) {
  171. var isHadoop2Stack = App.get('isHadoop2Stack');
  172. var securityEnabled = this.get('content.securityEnabled');
  173. var componentName = this.get('content.reassign.component_name');
  174. var targetHostName = this.get('content.reassignHosts.target');
  175. var sourceHostName = this.get('content.reassignHosts.source');
  176. var configs = {};
  177. var componentDir = '';
  178. var secureConfigs = [];
  179. this.set('configsSitesNumber', data.items.length);
  180. this.set('configsSitesCount', 0);
  181. data.items.forEach(function (item) {
  182. configs[item.type] = item.properties;
  183. }, this);
  184. switch (componentName) {
  185. case 'NAMENODE':
  186. if (isHadoop2Stack) {
  187. if (!App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE')) {
  188. var nameServices = configs['hdfs-site']['dfs.nameservices'];
  189. if (configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] === sourceHostName + ':50070') {
  190. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] = targetHostName + ':50070';
  191. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn1'] = targetHostName + ':8020';
  192. } else {
  193. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn2'] = targetHostName + ':50070';
  194. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn2'] = targetHostName + ':8020';
  195. }
  196. } else {
  197. configs['hdfs-site']['dfs.namenode.http-address'] = targetHostName + ':50070';
  198. configs['hdfs-site']['dfs.namenode.https-address'] = targetHostName + ':50470';
  199. configs['core-site']['fs.defaultFS'] = 'hdfs://' + targetHostName + ':8020';
  200. }
  201. componentDir = configs['hdfs-site']['dfs.namenode.name.dir'];
  202. } else {
  203. componentDir = configs['hdfs-site']['dfs.name.dir'];
  204. configs['hdfs-site']['dfs.http.address'] = targetHostName + ':50070';
  205. configs['hdfs-site']['dfs.https.address'] = targetHostName + ':50470';
  206. configs['core-site']['fs.default.name'] = 'hdfs://' + targetHostName + ':8020';
  207. }
  208. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  209. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName);
  210. }
  211. if (securityEnabled) {
  212. secureConfigs.push({keytab: configs['hdfs-site']['dfs.namenode.keytab.file'], principal: configs['hdfs-site']['dfs.namenode.kerberos.principal']});
  213. secureConfigs.push({keytab: configs['hdfs-site']['dfs.web.authentication.kerberos.keytab'], principal: configs['hdfs-site']['dfs.web.authentication.kerberos.principal']});
  214. }
  215. break;
  216. case 'SECONDARY_NAMENODE':
  217. if (isHadoop2Stack) {
  218. componentDir = configs['hdfs-site']['dfs.namenode.checkpoint.dir'];
  219. configs['hdfs-site']['dfs.namenode.secondary.http-address'] = targetHostName + ':50090';
  220. } else {
  221. componentDir = configs['core-site']['fs.checkpoint.dir'];
  222. configs['hdfs-site']['dfs.secondary.http.address'] = targetHostName + ':50090';
  223. }
  224. if (securityEnabled) {
  225. secureConfigs.push({keytab: configs['hdfs-site']['dfs.secondary.namenode.keytab.file'], principal: configs['hdfs-site']['dfs.secondary.namenode.kerberos.principal']});
  226. secureConfigs.push({keytab: configs['hdfs-site']['dfs.web.authentication.kerberos.keytab'], principal: configs['hdfs-site']['dfs.web.authentication.kerberos.principal']});
  227. }
  228. break;
  229. case 'JOBTRACKER':
  230. configs['mapred-site']['mapreduce.history.server.http.address'] = targetHostName + ':51111';
  231. configs['mapred-site']['mapred.job.tracker.http.address'] = targetHostName + ':50030';
  232. configs['mapred-site']['mapred.job.tracker'] = targetHostName + ':50300';
  233. if (securityEnabled) {
  234. secureConfigs.push({keytab: configs['mapred-site']['mapreduce.jobtracker.keytab.file'], principal: configs['mapred-site']['mapreduce.jobtracker.kerberos.principal']});
  235. }
  236. break;
  237. case 'RESOURCEMANAGER':
  238. configs['yarn-site']['yarn.resourcemanager.address'] = targetHostName + ':8050';
  239. configs['yarn-site']['yarn.resourcemanager.admin.address'] = targetHostName + ':8141';
  240. configs['yarn-site']['yarn.resourcemanager.resource-tracker.address'] = targetHostName + ':8025';
  241. configs['yarn-site']['yarn.resourcemanager.scheduler.address'] = targetHostName + ':8030';
  242. configs['yarn-site']['yarn.resourcemanager.webapp.address'] = targetHostName + ':8088';
  243. configs['yarn-site']['yarn.resourcemanager.hostname'] = targetHostName;
  244. if (securityEnabled) {
  245. secureConfigs.push({keytab: configs['yarn-site']['yarn.resourcemanager.keytab'], principal: configs['yarn-site']['yarn.resourcemanager.principal']});
  246. secureConfigs.push({keytab: configs['yarn-site']['yarn.resourcemanager.webapp.spnego-keytab-file'], principal: configs['yarn-site']['yarn.resourcemanager.webapp.spnego-principal']});
  247. }
  248. break;
  249. }
  250. if (componentDir || secureConfigs.length) {
  251. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  252. App.router.get(this.get('content.controllerName')).saveSecureConfigs(secureConfigs);
  253. App.clusterStatus.setClusterStatus({
  254. clusterName: this.get('content.cluster.name'),
  255. clusterState: this.get('clusterDeployState'),
  256. wizardControllerName: this.get('content.controllerName'),
  257. localdb: App.db.data
  258. });
  259. }
  260. for (var site in configs) {
  261. if (!configs.hasOwnProperty(site)) continue;
  262. App.ajax.send({
  263. name: 'reassign.save_configs',
  264. sender: this,
  265. data: {
  266. siteName: site,
  267. properties: configs[site]
  268. },
  269. success: 'onSaveConfigs',
  270. error: 'onTaskError'
  271. });
  272. }
  273. },
  274. onSaveConfigs: function () {
  275. this.set('configsSitesCount', this.get('configsSitesCount') + 1);
  276. if (this.get('configsSitesCount') === this.get('configsSitesNumber')) {
  277. this.onTaskCompleted();
  278. }
  279. },
  280. startZooKeeperServers: function () {
  281. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  282. this.startComponent('ZOOKEEPER_SERVER', hostNames);
  283. },
  284. startNameNode: function () {
  285. var hostName = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName').without(this.get('content.reassignHosts.target'));
  286. this.startComponent('NAMENODE', hostName);
  287. },
  288. startServices: function () {
  289. App.ajax.send({
  290. name: 'reassign.start_services',
  291. sender: this,
  292. success: 'startPolling',
  293. error: 'onTaskError'
  294. });
  295. },
  296. deleteHostComponents: function () {
  297. this.set('multiTaskCounter', 0);
  298. var hostComponents = this.get('hostComponents');
  299. var hostName = this.get('content.reassignHosts.source');
  300. for (var i = 0; i < hostComponents.length; i++) {
  301. App.ajax.send({
  302. name: 'reassign.remove_component',
  303. sender: this,
  304. data: {
  305. hostName: hostName,
  306. componentName: hostComponents[i]
  307. },
  308. success: 'onComponentsTasksSuccess',
  309. error: 'onTaskError'
  310. });
  311. }
  312. },
  313. done: function () {
  314. if (!this.get('isSubmitDisabled')) {
  315. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  316. if (this.get('content.hasManualSteps')) {
  317. App.router.send('next');
  318. } else {
  319. App.router.send('complete');
  320. }
  321. }
  322. }
  323. });