step4_controller.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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: 'common.services.update',
  89. sender: this,
  90. data: {
  91. "context": "Stop without HDFS",
  92. "ServiceInfo": {
  93. "state": "INSTALLED"
  94. },
  95. urlParams: "ServiceInfo/service_name.in("+list+")"},
  96. success: 'startPolling',
  97. error: 'onTaskError'
  98. };
  99. App.ajax.send(conf);
  100. } else {
  101. App.ajax.send({
  102. name: 'common.services.update',
  103. sender: this,
  104. data: {
  105. "context": "Stop all services",
  106. "ServiceInfo": {
  107. "state": "INSTALLED"
  108. }
  109. },
  110. success: 'startPolling',
  111. error: 'onTaskError'
  112. });
  113. }
  114. },
  115. createHostComponents: function () {
  116. this.set('multiTaskCounter', 0);
  117. var hostComponents = this.get('hostComponents');
  118. var hostName = this.get('content.reassignHosts.target');
  119. for (var i = 0; i < hostComponents.length; i++) {
  120. this.createComponent(hostComponents[i], hostName, this.get('content.reassign.service_id'));
  121. }
  122. },
  123. onCreateComponent: function () {
  124. this.onComponentsTasksSuccess();
  125. },
  126. putHostComponentsInMaintenanceMode: function () {
  127. this.set('multiTaskCounter', 0);
  128. var hostComponents = this.get('hostComponents');
  129. var hostName = this.get('content.reassignHosts.source');
  130. for (var i = 0; i < hostComponents.length; i++) {
  131. App.ajax.send({
  132. name: 'reassign.maintenance_mode',
  133. sender: this,
  134. data: {
  135. hostName: hostName,
  136. componentName: hostComponents[i]
  137. },
  138. success: 'onComponentsTasksSuccess',
  139. error: 'onTaskError'
  140. });
  141. }
  142. },
  143. installHostComponents: function () {
  144. this.set('multiTaskCounter', 0);
  145. var hostComponents = this.get('hostComponents');
  146. var hostName = this.get('content.reassignHosts.target');
  147. for (var i = 0; i < hostComponents.length; i++) {
  148. this.updateComponent(hostComponents[i], hostName, this.get('content.reassign.service_id'), "Install", hostComponents.length);
  149. }
  150. },
  151. reconfigure: function () {
  152. this.loadConfigsTags();
  153. },
  154. loadConfigsTags: function () {
  155. App.ajax.send({
  156. name: 'config.tags',
  157. sender: this,
  158. success: 'onLoadConfigsTags',
  159. error: 'onTaskError'
  160. });
  161. },
  162. onLoadConfigsTags: function (data) {
  163. var componentName = this.get('content.reassign.component_name');
  164. var urlParams = [];
  165. switch (componentName) {
  166. case 'NAMENODE':
  167. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  168. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  169. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  170. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  171. }
  172. break;
  173. case 'SECONDARY_NAMENODE':
  174. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  175. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  176. break;
  177. case 'JOBTRACKER':
  178. urlParams.push('(type=mapred-site&tag=' + data.Clusters.desired_configs['mapred-site'].tag + ')');
  179. break;
  180. case 'RESOURCEMANAGER':
  181. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  182. break;
  183. }
  184. App.ajax.send({
  185. name: 'reassign.load_configs',
  186. sender: this,
  187. data: {
  188. urlParams: urlParams.join('|')
  189. },
  190. success: 'onLoadConfigs',
  191. error: 'onTaskError'
  192. });
  193. },
  194. configsSitesCount: null,
  195. configsSitesNumber: null,
  196. onLoadConfigs: function (data) {
  197. var isHadoop2Stack = App.get('isHadoop2Stack');
  198. var securityEnabled = this.get('content.securityEnabled');
  199. var componentName = this.get('content.reassign.component_name');
  200. var targetHostName = this.get('content.reassignHosts.target');
  201. var sourceHostName = this.get('content.reassignHosts.source');
  202. var configs = {};
  203. var componentDir = '';
  204. var secureConfigs = [];
  205. this.set('configsSitesNumber', data.items.length);
  206. this.set('configsSitesCount', 0);
  207. data.items.forEach(function (item) {
  208. configs[item.type] = item.properties;
  209. }, this);
  210. switch (componentName) {
  211. case 'NAMENODE':
  212. if (isHadoop2Stack) {
  213. if (App.get('isHaEnabled')) {
  214. var nameServices = configs['hdfs-site']['dfs.nameservices'];
  215. if (configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] === sourceHostName + ':50070') {
  216. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] = targetHostName + ':50070';
  217. configs['hdfs-site']['dfs.namenode.https-address.' + nameServices + '.nn1'] = targetHostName + ':50470';
  218. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn1'] = targetHostName + ':8020';
  219. } else {
  220. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn2'] = targetHostName + ':50070';
  221. configs['hdfs-site']['dfs.namenode.https-address.' + nameServices + '.nn2'] = targetHostName + ':50470';
  222. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + '.nn2'] = targetHostName + ':8020';
  223. }
  224. } else {
  225. configs['hdfs-site']['dfs.namenode.http-address'] = targetHostName + ':50070';
  226. configs['hdfs-site']['dfs.namenode.https-address'] = targetHostName + ':50470';
  227. configs['core-site']['fs.defaultFS'] = 'hdfs://' + targetHostName + ':8020';
  228. }
  229. componentDir = configs['hdfs-site']['dfs.namenode.name.dir'];
  230. } else {
  231. componentDir = configs['hdfs-site']['dfs.name.dir'];
  232. configs['hdfs-site']['dfs.http.address'] = targetHostName + ':50070';
  233. configs['hdfs-site']['dfs.https.address'] = targetHostName + ':50470';
  234. configs['core-site']['fs.default.name'] = 'hdfs://' + targetHostName + ':8020';
  235. }
  236. if (!App.get('isHaEnabled')) {
  237. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  238. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName + ':8020');
  239. }
  240. }
  241. if (securityEnabled) {
  242. secureConfigs.push({keytab: configs['hdfs-site']['dfs.namenode.keytab.file'], principal: configs['hdfs-site']['dfs.namenode.kerberos.principal']});
  243. secureConfigs.push({keytab: configs['hdfs-site']['dfs.web.authentication.kerberos.keytab'], principal: configs['hdfs-site']['dfs.web.authentication.kerberos.principal']});
  244. }
  245. break;
  246. case 'SECONDARY_NAMENODE':
  247. if (isHadoop2Stack) {
  248. componentDir = configs['hdfs-site']['dfs.namenode.checkpoint.dir'];
  249. configs['hdfs-site']['dfs.namenode.secondary.http-address'] = targetHostName + ':50090';
  250. } else {
  251. componentDir = configs['core-site']['fs.checkpoint.dir'];
  252. configs['hdfs-site']['dfs.secondary.http.address'] = targetHostName + ':50090';
  253. }
  254. if (securityEnabled) {
  255. secureConfigs.push({keytab: configs['hdfs-site']['dfs.secondary.namenode.keytab.file'], principal: configs['hdfs-site']['dfs.secondary.namenode.kerberos.principal']});
  256. secureConfigs.push({keytab: configs['hdfs-site']['dfs.web.authentication.kerberos.keytab'], principal: configs['hdfs-site']['dfs.web.authentication.kerberos.principal']});
  257. }
  258. break;
  259. case 'JOBTRACKER':
  260. configs['mapred-site']['mapred.job.tracker.http.address'] = targetHostName + ':50030';
  261. configs['mapred-site']['mapred.job.tracker'] = targetHostName + ':50300';
  262. if (securityEnabled) {
  263. secureConfigs.push({keytab: configs['mapred-site']['mapreduce.jobtracker.keytab.file'], principal: configs['mapred-site']['mapreduce.jobtracker.kerberos.principal']});
  264. }
  265. break;
  266. case 'RESOURCEMANAGER':
  267. configs['yarn-site']['yarn.resourcemanager.address'] = targetHostName + ':8050';
  268. configs['yarn-site']['yarn.resourcemanager.admin.address'] = targetHostName + ':8141';
  269. configs['yarn-site']['yarn.resourcemanager.resource-tracker.address'] = targetHostName + ':8025';
  270. configs['yarn-site']['yarn.resourcemanager.scheduler.address'] = targetHostName + ':8030';
  271. configs['yarn-site']['yarn.resourcemanager.webapp.address'] = targetHostName + ':8088';
  272. configs['yarn-site']['yarn.resourcemanager.hostname'] = targetHostName;
  273. if (securityEnabled) {
  274. secureConfigs.push({keytab: configs['yarn-site']['yarn.resourcemanager.keytab'], principal: configs['yarn-site']['yarn.resourcemanager.principal']});
  275. secureConfigs.push({keytab: configs['yarn-site']['yarn.resourcemanager.webapp.spnego-keytab-file'], principal: configs['yarn-site']['yarn.resourcemanager.webapp.spnego-principal']});
  276. }
  277. break;
  278. }
  279. if (componentDir || secureConfigs.length) {
  280. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  281. App.router.get(this.get('content.controllerName')).saveSecureConfigs(secureConfigs);
  282. App.clusterStatus.setClusterStatus({
  283. clusterName: this.get('content.cluster.name'),
  284. clusterState: this.get('clusterDeployState'),
  285. wizardControllerName: this.get('content.controllerName'),
  286. localdb: App.db.data
  287. });
  288. }
  289. for (var site in configs) {
  290. if (!configs.hasOwnProperty(site)) continue;
  291. App.ajax.send({
  292. name: 'reassign.save_configs',
  293. sender: this,
  294. data: {
  295. siteName: site,
  296. properties: configs[site]
  297. },
  298. success: 'onSaveConfigs',
  299. error: 'onTaskError'
  300. });
  301. }
  302. },
  303. onSaveConfigs: function () {
  304. this.set('configsSitesCount', this.get('configsSitesCount') + 1);
  305. if (this.get('configsSitesCount') === this.get('configsSitesNumber')) {
  306. this.onTaskCompleted();
  307. }
  308. },
  309. startZooKeeperServers: function () {
  310. var components = this.get('content.masterComponentHosts').filterProperty('component', 'ZOOKEEPER_SERVER');
  311. this.updateComponent('ZOOKEEPER_SERVER', components.mapProperty('hostName'), "ZOOKEEPER", "Start");
  312. },
  313. startNameNode: function () {
  314. var components = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE');
  315. this.updateComponent('NAMENODE', components.mapProperty('hostName').without(this.get('content.reassignHosts.target')), "HDFS", "Start");
  316. },
  317. startServices: function () {
  318. if(this.get('restartYarnMRComponents')) {
  319. var list = App.Service.find().mapProperty("serviceName").without("HDFS").join(',');
  320. var conf = {
  321. name: 'common.services.update',
  322. sender: this,
  323. data: {
  324. "context": "Start without HDFS",
  325. "ServiceInfo": {
  326. "state": "STARTED"
  327. },
  328. urlParams: "ServiceInfo/service_name.in("+list+")"},
  329. success: 'startPolling',
  330. error: 'onTaskError'
  331. };
  332. App.ajax.send(conf);
  333. } else {
  334. App.ajax.send({
  335. name: 'common.services.update',
  336. sender: this,
  337. data: {
  338. "context": "Start all services",
  339. "ServiceInfo": {
  340. "state": "STARTED"
  341. },
  342. urlParams: "params/run_smoke_test=true"
  343. },
  344. success: 'startPolling',
  345. error: 'onTaskError'
  346. });
  347. }
  348. },
  349. deleteHostComponents: function () {
  350. this.set('multiTaskCounter', 0);
  351. var hostComponents = this.get('hostComponents');
  352. var hostName = this.get('content.reassignHosts.source');
  353. for (var i = 0; i < hostComponents.length; i++) {
  354. App.ajax.send({
  355. name: 'common.delete.host_component',
  356. sender: this,
  357. data: {
  358. hostName: hostName,
  359. componentName: hostComponents[i]
  360. },
  361. success: 'onComponentsTasksSuccess',
  362. error: 'onDeleteHostComponentsError'
  363. });
  364. }
  365. },
  366. onDeleteHostComponentsError: function (error) {
  367. if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
  368. this.onComponentsTasksSuccess();
  369. } else {
  370. this.onTaskError();
  371. }
  372. },
  373. done: function () {
  374. if (!this.get('isSubmitDisabled')) {
  375. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  376. if (this.get('content.hasManualSteps')) {
  377. App.router.send('next');
  378. } else {
  379. App.router.send('complete');
  380. }
  381. }
  382. }
  383. });