rollback_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. require('controllers/main/admin/highAvailability/progress_controller');
  20. App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageController.extend({
  21. name: "highAvailabilityRollbackController",
  22. failedTask: null,
  23. configsSaved: false,
  24. deletedHdfsClients: 0,
  25. numOfDelOperations: 0,
  26. isRollback: true,
  27. hostsToPerformDel: [],
  28. content: Em.Object.create({
  29. masterComponentHosts: null
  30. }),
  31. commands: [
  32. 'stopAllServices',
  33. 'restoreHBaseConfigs',
  34. 'stopFailoverControllers',
  35. 'deleteFailoverControllers',
  36. 'stopStandbyNameNode',
  37. 'stopNameNode',
  38. 'restoreHDFSConfigs',
  39. 'enableSecondaryNameNode',
  40. 'stopJournalNodes',
  41. 'deleteJournalNodes',
  42. 'deleteAdditionalNameNode',
  43. 'startAllServices'
  44. ],
  45. loadStep: function () {
  46. this.initData();
  47. this.clearStep();
  48. this.loadTasks();
  49. this.addObserver('tasks.@each.status', this, 'onTaskStatusChange');
  50. this.onTaskStatusChange();
  51. },
  52. initData: function () {
  53. this.loadMasterComponentHosts();
  54. this.loadFailedTask();
  55. this.loadHdfsClientHosts();
  56. },
  57. setCommandsAndTasks: function(tmpTasks) {
  58. var fTask = this.get('failedTask');
  59. var newCommands = [];
  60. var newTasks = [];
  61. var index = [
  62. 'deleteSNameNode',
  63. 'startAllServices',
  64. 'reconfigureHBase',
  65. 'startZKFC',
  66. 'installZKFC',
  67. 'startSecondNameNode',
  68. 'startNameNode',
  69. 'startZooKeeperServers',
  70. 'reconfigureHDFS',
  71. 'disableSNameNode',
  72. 'startJournalNodes',
  73. 'installJournalNodes',
  74. 'installNameNode',
  75. 'stopAllServices'
  76. ].indexOf(fTask.command);
  77. if(index > 6){
  78. --index;
  79. }
  80. newCommands = this.get('commands').splice(index);
  81. this.set('commands', newCommands);
  82. newTasks = tmpTasks.splice(index);
  83. for (var i = 0; i < newTasks.length; i++) {
  84. newTasks[i].id = i;
  85. };
  86. this.set('tasks', newTasks);
  87. },
  88. clearStep: function () {
  89. this.set('isSubmitDisabled', true);
  90. this.set('tasks', []);
  91. this.set('logs', []);
  92. this.set('currentRequestIds', []);
  93. var commands = this.get('commands');
  94. var tmpTasks = [];
  95. for (var i = 0; i < commands.length; i++) {
  96. tmpTasks.pushObject(Ember.Object.create({
  97. title: Em.I18n.t('admin.highAvailability.rollback.task' + i + '.title'),
  98. status: 'PENDING',
  99. id: i,
  100. command: commands[i],
  101. showRetry: false,
  102. showRollback: false,
  103. showSkip: false,
  104. name: Em.I18n.t('admin.highAvailability.rollback.task' + i + '.title'),
  105. displayName: Em.I18n.t('admin.highAvailability.rollback.task' + i + '.title'),
  106. progress: 0,
  107. isRunning: false,
  108. hosts: []
  109. }));
  110. }
  111. this.setCommandsAndTasks(tmpTasks);
  112. },
  113. onTaskStatusChange: function () {
  114. if (!this.get('tasks').someProperty('status', 'IN_PROGRESS') && !this.get('tasks').someProperty('status', 'QUEUED') && !this.get('tasks').someProperty('status', 'FAILED')) {
  115. var nextTask = this.get('tasks').findProperty('status', 'PENDING');
  116. if (nextTask) {
  117. this.set('status', 'IN_PROGRESS');
  118. this.runTask(nextTask.get('id'));
  119. this.setTaskStatus(nextTask.get('id'), 'QUEUED');
  120. this.set('currentTaskId', nextTask.get('id'));
  121. } else {
  122. this.set('status', 'COMPLETED');
  123. this.set('isSubmitDisabled', false);
  124. }
  125. } else if (this.get('tasks').someProperty('status', 'FAILED')) {
  126. this.set('status', 'FAILED');
  127. this.get('tasks').findProperty('status', 'FAILED').set('showRetry', true);
  128. this.get('tasks').findProperty('status', 'FAILED').set('showSkip', true);
  129. }
  130. var statuses = this.get('tasks').mapProperty('status');
  131. var logs = this.get('tasks').mapProperty('hosts');
  132. var requestIds = this.get('currentRequestIds');
  133. this.saveTasksStatuses(statuses);
  134. this.saveRequestIds(requestIds);
  135. this.saveLogs(logs);
  136. App.clusterStatus.setClusterStatus({
  137. clusterName: this.get('content.cluster.name'),
  138. clusterState: 'HIGH_AVAILABILITY_ROLLBACK',
  139. wizardControllerName: this.get('content.controllerName'),
  140. localdb: App.db.data
  141. });
  142. },
  143. skipTask: function () {
  144. var task = this.get('tasks').findProperty('status', 'FAILED');
  145. task.set('showRetry', false);
  146. task.set('showSkip', false);
  147. task.set('status', 'COMPLETED');
  148. },
  149. onTaskCompleted: function () {
  150. var curTaskStatus = this.getTaskStatus(this.get('currentTaskId'));
  151. if (curTaskStatus != 'FAILED' && curTaskStatus != 'TIMEDOUT' && curTaskStatus != 'ABORTED') {
  152. this.setTaskStatus(this.get('currentTaskId'), 'COMPLETED');
  153. }
  154. },
  155. getTaskStatus: function (taskId) {
  156. return this.get('tasks').findProperty('id', taskId).get('status');
  157. },
  158. loadFailedTask: function(){
  159. var failedTask = App.db.getHighAvailabilityWizardFailedTask();
  160. this.set('failedTask', failedTask);
  161. },
  162. done: function () {
  163. if (!this.get('isSubmitDisabled')) {
  164. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  165. this.get('popup').hide();
  166. App.router.transitionTo('main.admin.adminHighAvailability');
  167. }
  168. },
  169. stopAllServices: function(){
  170. App.ajax.send({
  171. name: 'admin.high_availability.stop_all_services',
  172. sender: this,
  173. success: 'startPolling',
  174. error: 'onTaskError'
  175. });
  176. },
  177. restoreHBaseConfigs: function(){
  178. this.loadConfigTag("hbaseSiteTag");
  179. var hbaseSiteTag = this.get("content.hbaseSiteTag");
  180. App.ajax.send({
  181. name: 'admin.high_availability.load_hbase_configs',
  182. sender: this,
  183. data: {
  184. hbaseSiteTag: hbaseSiteTag
  185. },
  186. success: 'onLoadHbaseConfigs',
  187. error: 'onTaskError'
  188. });
  189. },
  190. stopFailoverControllers: function(){
  191. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  192. this.stopComponent('ZKFC', hostNames);
  193. },
  194. deleteFailoverControllers: function(){
  195. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  196. this.checkBeforeDelete('ZKFC', hostNames);
  197. },
  198. stopStandbyNameNode: function(){
  199. var hostName = this.get('content.masterComponentHosts').findProperty('isAddNameNode', true).hostName;;
  200. this.stopComponent('NAMENODE', hostName);
  201. },
  202. stopNameNode: function(){
  203. var hostNames = this.get('content.masterComponentHosts').findProperty('isCurNameNode').hostName;
  204. this.stopComponent('NAMENODE', hostNames);
  205. },
  206. restoreHDFSConfigs: function(){
  207. this.unInstallHDFSClients();
  208. },
  209. enableSecondaryNameNode: function(){
  210. var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
  211. this.installComponent('SECONDARY_NAMENODE', hostName, hostName.length);
  212. },
  213. stopJournalNodes: function(){
  214. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  215. this.stopComponent('JOURNALNODE', hostNames);
  216. },
  217. deleteJournalNodes: function(){
  218. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  219. this.unInstallComponent('JOURNALNODE', hostNames);
  220. },
  221. deleteAdditionalNameNode: function(){
  222. var hostNames = this.get('content.masterComponentHosts').filterProperty('isAddNameNode', true).mapProperty('hostName');
  223. this.unInstallComponent('NAMENODE', hostNames);
  224. },
  225. startAllServices: function(){
  226. App.ajax.send({
  227. name: 'admin.high_availability.start_all_services',
  228. sender: this,
  229. success: 'startPolling',
  230. error: 'onTaskError'
  231. });
  232. },
  233. onLoadHbaseConfigs: function (data) {
  234. var hbaseSiteProperties = data.items.findProperty('type', 'hbase-site').properties;
  235. App.ajax.send({
  236. name: 'admin.high_availability.save_configs',
  237. sender: this,
  238. data: {
  239. siteName: 'hbase-site',
  240. properties: hbaseSiteProperties
  241. },
  242. success: 'onTaskCompleted',
  243. error: 'onTaskError'
  244. });
  245. },
  246. stopComponent: function (componentName, hostName) {
  247. if (!(hostName instanceof Array)) {
  248. hostName = [hostName];
  249. }
  250. for (var i = 0; i < hostName.length; i++) {
  251. App.ajax.send({
  252. name: 'admin.high_availability.stop_component',
  253. sender: this,
  254. data: {
  255. hostName: hostName[i],
  256. componentName: componentName,
  257. displayName: App.format.role(componentName),
  258. taskNum: hostName.length
  259. },
  260. success: 'startPolling',
  261. error: 'onTaskError'
  262. });
  263. }
  264. },
  265. onDeletedHDFSClient: function () {
  266. var deletedHdfsClients = this.get('deletedHdfsClients');
  267. var hostName = this.get("content.hdfsClientHostNames");
  268. var notDeletedHdfsClients = hostName.length - deletedHdfsClients;
  269. if (notDeletedHdfsClients > 1 && hostName.length != 1 ) {
  270. this.set('deletedHdfsClients', deletedHdfsClients+1);
  271. return;
  272. }
  273. this.loadConfigTag("hdfsSiteTag");
  274. this.loadConfigTag("coreSiteTag");
  275. var hdfsSiteTag = this.get("content.hdfsSiteTag");
  276. var coreSiteTag = this.get("content.coreSiteTag");
  277. App.ajax.send({
  278. name: 'admin.high_availability.load_configs',
  279. sender: this,
  280. data: {
  281. hdfsSiteTag: hdfsSiteTag,
  282. coreSiteTag: coreSiteTag
  283. },
  284. success: 'onLoadConfigs',
  285. error: 'onTaskError'
  286. });
  287. },
  288. onLoadConfigs: function (data) {
  289. this.set('configsSaved', false);
  290. App.ajax.send({
  291. name: 'admin.high_availability.save_configs',
  292. sender: this,
  293. data: {
  294. siteName: 'hdfs-site',
  295. properties: data.items.findProperty('type', 'hdfs-site').properties
  296. },
  297. success: 'onHdfsConfigsSaved',
  298. error: 'onTaskError'
  299. });
  300. App.ajax.send({
  301. name: 'admin.high_availability.save_configs',
  302. sender: this,
  303. data: {
  304. siteName: 'core-site',
  305. properties: data.items.findProperty('type', 'core-site').properties
  306. },
  307. success: 'onHdfsConfigsSaved',
  308. error: 'onTaskError'
  309. });
  310. },
  311. onHdfsConfigsSaved: function () {
  312. if (!this.get('configsSaved')) {
  313. this.set('configsSaved', true);
  314. return;
  315. }
  316. this.onTaskCompleted();
  317. },
  318. unInstallHDFSClients: function () {
  319. var hostName = this.get("content.hdfsClientHostNames");
  320. for (var i = 0; i < hostName.length; i++) {
  321. App.ajax.send({
  322. name: 'admin.high_availability.delete_component',
  323. sender: this,
  324. data: {
  325. componentName: 'HDFS_CLIENT',
  326. hostName: hostName[i]
  327. },
  328. success: 'onDeletedHDFSClient',
  329. error: 'onTaskError'
  330. });
  331. }
  332. },
  333. unInstallComponent: function (componentName, hostName) {
  334. if (!(hostName instanceof Array)) {
  335. hostName = [hostName];
  336. }
  337. for (var i = 0; i < hostName.length; i++) {
  338. App.ajax.send({
  339. name: 'admin.high_availability.maintenance_mode',
  340. sender: this,
  341. data: {
  342. hostName: hostName[i],
  343. componentName: componentName,
  344. taskNum: hostName.length,
  345. callback: 'checkBeforeDelete'
  346. },
  347. success: 'checkResult',
  348. error: 'checkResult'
  349. });
  350. }
  351. },
  352. checkBeforeDelete: function (componentName, hostName){
  353. this.set('hostsToPerformDel', []);
  354. if (!(hostName instanceof Array)) {
  355. hostName = [hostName];
  356. }
  357. for (var i = 0; i < hostName.length; i++) {
  358. App.ajax.send({
  359. name: 'admin.high_availability.getHostComponent',
  360. sender: this,
  361. data: {
  362. componentName: componentName,
  363. hostName: hostName[i],
  364. taskNum: hostName.length,
  365. callback: 'deleteComponent'
  366. },
  367. success: 'checkResult',
  368. error: 'checkResult'
  369. });
  370. }
  371. },
  372. checkResult: function () {
  373. var callback = arguments[2].callback;
  374. var hostName = arguments[2].hostName;
  375. var componentName = arguments[2].componentName;
  376. var taskNum = arguments[2].taskNum;
  377. var hostsToPerformDel = this.get('hostsToPerformDel');
  378. if(arguments[1] != 'error'){
  379. hostsToPerformDel.push({
  380. hostName: hostName,
  381. isOnHost: true
  382. });
  383. }else{
  384. hostsToPerformDel.push({
  385. hostName: 'error',
  386. isOnHost: false
  387. });
  388. }
  389. if(hostsToPerformDel.length == taskNum){
  390. var hostsForDel = hostsToPerformDel.filterProperty('isOnHost', true).mapProperty('hostName');
  391. this.set('hostsToPerformDel', []);
  392. if(hostsForDel.length == 0){
  393. this.onTaskCompleted();
  394. return;
  395. }
  396. this[callback](componentName, hostsForDel);
  397. }
  398. },
  399. deleteComponent: function (componentName, hostName) {
  400. if (!(hostName instanceof Array)) {
  401. hostName = [hostName];
  402. }
  403. this.set('numOfDelOperations', hostName.length);
  404. for (var i = 0; i < hostName.length; i++) {
  405. App.ajax.send({
  406. name: 'admin.high_availability.delete_component',
  407. sender: this,
  408. data: {
  409. componentName: componentName,
  410. hostName: hostName[i]
  411. },
  412. success: 'onDeleteComplete',
  413. error: 'onTaskError'
  414. });
  415. }
  416. },
  417. onDeleteComplete: function () {
  418. var leftOp = this.get('numOfDelOperations');
  419. if(leftOp > 1){
  420. this.set('numOfDelOperations', leftOp-1);
  421. return;
  422. }
  423. this.onTaskCompleted();
  424. }
  425. });