step4_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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', '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. this.get('tasks').splice(5, 2);
  59. }
  60. },
  61. hideRollbackButton: function () {
  62. var failedTask = this.get('tasks').findProperty('showRollback');
  63. if (failedTask) {
  64. failedTask.set('showRollback', false)
  65. }
  66. }.observes('tasks.@each.showRollback'),
  67. onComponentsTasksSuccess: function () {
  68. this.set('multiTaskCounter', this.get('multiTaskCounter') + 1);
  69. if (this.get('multiTaskCounter') >= this.get('hostComponents').length) {
  70. this.onTaskCompleted();
  71. }
  72. },
  73. stopServices: function () {
  74. App.ajax.send({
  75. name: 'reassign.stop_services',
  76. sender: this,
  77. success: 'startPolling',
  78. error: 'onTaskError'
  79. });
  80. },
  81. createHostComponents: function () {
  82. this.set('multiTaskCounter', 0);
  83. var hostComponents = this.get('hostComponents');
  84. var hostName = this.get('content.reassignHosts.target');
  85. for (var i = 0; i < hostComponents.length; i++) {
  86. this.createComponent(hostComponents[i], hostName);
  87. }
  88. },
  89. onCreateComponent: function () {
  90. this.onComponentsTasksSuccess();
  91. },
  92. putHostComponentsInMaintenanceMode: function () {
  93. this.set('multiTaskCounter', 0);
  94. var hostComponents = this.get('hostComponents');
  95. var hostName = this.get('content.reassignHosts.source');
  96. for (var i = 0; i < hostComponents.length; i++) {
  97. App.ajax.send({
  98. name: 'reassign.maintenance_mode',
  99. sender: this,
  100. data: {
  101. hostName: hostName,
  102. componentName: hostComponents[i]
  103. },
  104. success: 'onComponentsTasksSuccess',
  105. error: 'onTaskError'
  106. });
  107. }
  108. },
  109. installHostComponents: function () {
  110. this.set('multiTaskCounter', 0);
  111. var hostComponents = this.get('hostComponents');
  112. var hostName = this.get('content.reassignHosts.target');
  113. for (var i = 0; i < hostComponents.length; i++) {
  114. this.installComponent(hostComponents[i], hostName, hostComponents.length);
  115. }
  116. },
  117. reconfigure: function () {
  118. this.loadConfigsTags();
  119. },
  120. loadConfigsTags: function () {
  121. App.ajax.send({
  122. name: 'config.tags',
  123. sender: this,
  124. success: 'onLoadConfigsTags',
  125. error: 'onTaskError'
  126. });
  127. },
  128. onLoadConfigsTags: function (data) {
  129. var componentName = this.get('content.reassign.component_name');
  130. var urlParams = [];
  131. switch (componentName) {
  132. case 'NAMENODE':
  133. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  134. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  135. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  136. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  137. }
  138. break;
  139. case 'SECONDARY_NAMENODE':
  140. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  141. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  142. break;
  143. case 'JOBTRACKER':
  144. urlParams.push('(type=mapred-site&tag=' + data.Clusters.desired_configs['mapred-site'].tag + ')');
  145. break;
  146. case 'RESOURCEMANAGER':
  147. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  148. break;
  149. }
  150. App.ajax.send({
  151. name: 'reassign.load_configs',
  152. sender: this,
  153. data: {
  154. urlParams: urlParams.join('|')
  155. },
  156. success: 'onLoadConfigs',
  157. error: 'onTaskError'
  158. });
  159. },
  160. configsSitesCount: null,
  161. configsSitesNumber: null,
  162. onLoadConfigs: function (data) {
  163. var isHadoop2Stack = App.get('isHadoop2Stack');
  164. var componentName = this.get('content.reassign.component_name');
  165. var targetHostName = this.get('content.reassignHosts.target');
  166. var sourceHostName = this.get('content.reassignHosts.source');
  167. var configs = {};
  168. var componentDir = '';
  169. this.set('configsSitesNumber', data.items.length);
  170. this.set('configsSitesCount', 0);
  171. data.items.forEach(function (item) {
  172. configs[item.type] = item.properties;
  173. }, this);
  174. switch (componentName) {
  175. case 'NAMENODE':
  176. if (isHadoop2Stack) {
  177. if (!App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE')) {
  178. var nameServices = configs['hdfs-site']['dfs.nameservices'];
  179. if (configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] === sourceHostName + ':50070') {
  180. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] = targetHostName + ':50070';
  181. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn1'] = targetHostName + ':8020';
  182. } else {
  183. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn2'] = targetHostName + ':50070';
  184. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn2'] = targetHostName + ':8020';
  185. }
  186. } else {
  187. configs['hdfs-site']['dfs.namenode.http-address'] = targetHostName + ':50070';
  188. configs['hdfs-site']['dfs.namenode.https-address'] = targetHostName + ':50470';
  189. configs['core-site']['fs.defaultFS'] = 'hdfs://' + targetHostName + ':8020';
  190. }
  191. componentDir = configs['hdfs-site']['dfs.namenode.name.dir'];
  192. } else {
  193. componentDir = configs['hdfs-site']['dfs.name.dir'];
  194. configs['hdfs-site']['dfs.http.address'] = targetHostName + ':50070';
  195. configs['hdfs-site']['dfs.https.address'] = targetHostName + ':50470';
  196. configs['core-site']['fs.default.name'] = 'hdfs://' + targetHostName + ':8020';
  197. }
  198. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  199. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName);
  200. }
  201. break;
  202. case 'SECONDARY_NAMENODE':
  203. if (isHadoop2Stack) {
  204. componentDir = configs['hdfs-site']['dfs.namenode.checkpoint.dir'];
  205. configs['hdfs-site']['dfs.namenode.secondary.http-address'] = targetHostName + ':50090';
  206. } else {
  207. componentDir = configs['core-site']['fs.checkpoint.dir'];
  208. configs['hdfs-site']['dfs.secondary.http.address'] = targetHostName + ':50090';
  209. }
  210. break;
  211. case 'JOBTRACKER':
  212. componentDir = configs['mapred-site']['mapred.local.dir'];
  213. configs['mapred-site']['mapreduce.history.server.http.address'] = targetHostName + ':51111';
  214. configs['mapred-site']['mapred.job.tracker.http.address'] = targetHostName + ':50030';
  215. configs['mapred-site']['mapred.job.tracker'] = targetHostName + ':50300';
  216. break;
  217. case 'RESOURCEMANAGER':
  218. configs['yarn-site']['yarn.resourcemanager.address'] = targetHostName + ':8050';
  219. configs['yarn-site']['yarn.resourcemanager.admin.address'] = targetHostName + ':8141';
  220. configs['yarn-site']['yarn.resourcemanager.resource-tracker.address'] = targetHostName + ':8025';
  221. configs['yarn-site']['yarn.resourcemanager.scheduler.address'] = targetHostName + ':8030';
  222. configs['yarn-site']['yarn.resourcemanager.webapp.address'] = targetHostName + ':8088';
  223. configs['yarn-site']['yarn.resourcemanager.hostname'] = targetHostName;
  224. break;
  225. }
  226. if (componentDir) {
  227. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  228. App.clusterStatus.setClusterStatus({
  229. clusterName: this.get('content.cluster.name'),
  230. clusterState: this.get('clusterDeployState'),
  231. wizardControllerName: this.get('content.controllerName'),
  232. localdb: App.db.data
  233. });
  234. }
  235. for (var site in configs) {
  236. if (!configs.hasOwnProperty(site)) continue;
  237. App.ajax.send({
  238. name: 'reassign.save_configs',
  239. sender: this,
  240. data: {
  241. siteName: site,
  242. properties: configs[site]
  243. },
  244. success: 'onSaveConfigs',
  245. error: 'onTaskError'
  246. });
  247. }
  248. },
  249. onSaveConfigs: function () {
  250. this.set('configsSitesCount', this.get('configsSitesCount') + 1);
  251. if (this.get('configsSitesCount') === this.get('configsSitesNumber')) {
  252. this.onTaskCompleted();
  253. }
  254. },
  255. startServices: function () {
  256. App.ajax.send({
  257. name: 'reassign.start_services',
  258. sender: this,
  259. success: 'startPolling',
  260. error: 'onTaskError'
  261. });
  262. },
  263. deleteHostComponents: function () {
  264. this.set('multiTaskCounter', 0);
  265. var hostComponents = this.get('hostComponents');
  266. var hostName = this.get('content.reassignHosts.source');
  267. for (var i = 0; i < hostComponents.length; i++) {
  268. App.ajax.send({
  269. name: 'reassign.remove_component',
  270. sender: this,
  271. data: {
  272. hostName: hostName,
  273. componentName: hostComponents[i]
  274. },
  275. success: 'onComponentsTasksSuccess',
  276. error: 'onTaskError'
  277. });
  278. }
  279. },
  280. done: function () {
  281. if (!this.get('isSubmitDisabled')) {
  282. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  283. if (this.get('content.hasManualSteps')) {
  284. App.router.send('next');
  285. } else {
  286. App.router.send('complete');
  287. }
  288. }
  289. }
  290. })