rollback_controller.js 14 KB

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