step4_controller.js 13 KB

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