step4_controller.js 15 KB

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