step4_controller.js 14 KB

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