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