step4_controller.js 16 KB

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