rollback_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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: 'highAvailabilityRollbackController',
  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.popup.proceedOnClose();
  163. }
  164. },
  165. stopAllServices: function(){
  166. App.ajax.send({
  167. name: 'admin.high_availability.stop_all_services',
  168. sender: this,
  169. success: 'startPolling',
  170. error: 'onTaskError'
  171. });
  172. },
  173. restoreHBaseConfigs: function(){
  174. this.loadConfigTag("hbaseSiteTag");
  175. var hbaseSiteTag = this.get("content.hbaseSiteTag");
  176. App.ajax.send({
  177. name: 'admin.high_availability.load_hbase_configs',
  178. sender: this,
  179. data: {
  180. hbaseSiteTag: hbaseSiteTag
  181. },
  182. success: 'onLoadHbaseConfigs',
  183. error: 'onTaskError'
  184. });
  185. },
  186. stopFailoverControllers: function(){
  187. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  188. this.stopComponent('ZKFC', hostNames);
  189. },
  190. deleteFailoverControllers: function(){
  191. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  192. this.checkBeforeDelete('ZKFC', hostNames);
  193. },
  194. stopStandbyNameNode: function(){
  195. var hostName = this.get('content.masterComponentHosts').findProperty('isAddNameNode', true).hostName;;
  196. this.stopComponent('NAMENODE', hostName);
  197. },
  198. stopNameNode: function(){
  199. var hostNames = this.get('content.masterComponentHosts').findProperty('isCurNameNode').hostName;
  200. this.stopComponent('NAMENODE', hostNames);
  201. },
  202. restoreHDFSConfigs: function(){
  203. this.unInstallHDFSClients();
  204. },
  205. enableSecondaryNameNode: function(){
  206. var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
  207. this.installComponent('SECONDARY_NAMENODE', hostName, hostName.length);
  208. },
  209. stopJournalNodes: function(){
  210. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  211. this.stopComponent('JOURNALNODE', hostNames);
  212. },
  213. deleteJournalNodes: function(){
  214. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  215. this.unInstallComponent('JOURNALNODE', hostNames);
  216. },
  217. deleteAdditionalNameNode: function(){
  218. var hostNames = this.get('content.masterComponentHosts').filterProperty('isAddNameNode', true).mapProperty('hostName');
  219. this.unInstallComponent('NAMENODE', hostNames);
  220. },
  221. startAllServices: function(){
  222. App.ajax.send({
  223. name: 'admin.high_availability.start_all_services',
  224. sender: this,
  225. success: 'startPolling',
  226. error: 'onTaskError'
  227. });
  228. },
  229. onLoadHbaseConfigs: function (data) {
  230. var hbaseSiteProperties = data.items.findProperty('type', 'hbase-site').properties;
  231. App.ajax.send({
  232. name: 'admin.high_availability.save_configs',
  233. sender: this,
  234. data: {
  235. siteName: 'hbase-site',
  236. properties: hbaseSiteProperties
  237. },
  238. success: 'onTaskCompleted',
  239. error: 'onTaskError'
  240. });
  241. },
  242. stopComponent: function (componentName, hostName) {
  243. if (!(hostName instanceof Array)) {
  244. hostName = [hostName];
  245. }
  246. for (var i = 0; i < hostName.length; i++) {
  247. App.ajax.send({
  248. name: 'admin.high_availability.stop_component',
  249. sender: this,
  250. data: {
  251. hostName: hostName[i],
  252. componentName: componentName,
  253. displayName: App.format.role(componentName),
  254. taskNum: hostName.length
  255. },
  256. success: 'startPolling',
  257. error: 'onTaskError'
  258. });
  259. }
  260. },
  261. onDeletedHDFSClient: function () {
  262. var deletedHdfsClients = this.get('deletedHdfsClients');
  263. var hostName = this.get("content.hdfsClientHostNames");
  264. var notDeletedHdfsClients = hostName.length - deletedHdfsClients;
  265. if (notDeletedHdfsClients > 1 && hostName.length != 1 ) {
  266. this.set('deletedHdfsClients', deletedHdfsClients+1);
  267. return;
  268. }
  269. this.loadConfigTag("hdfsSiteTag");
  270. this.loadConfigTag("coreSiteTag");
  271. var hdfsSiteTag = this.get("content.hdfsSiteTag");
  272. var coreSiteTag = this.get("content.coreSiteTag");
  273. App.ajax.send({
  274. name: 'admin.high_availability.load_configs',
  275. sender: this,
  276. data: {
  277. hdfsSiteTag: hdfsSiteTag,
  278. coreSiteTag: coreSiteTag
  279. },
  280. success: 'onLoadConfigs',
  281. error: 'onTaskError'
  282. });
  283. },
  284. onLoadConfigs: function (data) {
  285. this.set('configsSaved', false);
  286. App.ajax.send({
  287. name: 'admin.high_availability.save_configs',
  288. sender: this,
  289. data: {
  290. siteName: 'hdfs-site',
  291. properties: data.items.findProperty('type', 'hdfs-site').properties
  292. },
  293. success: 'onHdfsConfigsSaved',
  294. error: 'onTaskError'
  295. });
  296. App.ajax.send({
  297. name: 'admin.high_availability.save_configs',
  298. sender: this,
  299. data: {
  300. siteName: 'core-site',
  301. properties: data.items.findProperty('type', 'core-site').properties
  302. },
  303. success: 'onHdfsConfigsSaved',
  304. error: 'onTaskError'
  305. });
  306. },
  307. onHdfsConfigsSaved: function () {
  308. if (!this.get('configsSaved')) {
  309. this.set('configsSaved', true);
  310. return;
  311. }
  312. this.onTaskCompleted();
  313. },
  314. unInstallHDFSClients: function () {
  315. var hostName = this.get("content.hdfsClientHostNames");
  316. for (var i = 0; i < hostName.length; i++) {
  317. App.ajax.send({
  318. name: 'admin.high_availability.delete_component',
  319. sender: this,
  320. data: {
  321. componentName: 'HDFS_CLIENT',
  322. hostName: hostName[i]
  323. },
  324. success: 'onDeletedHDFSClient',
  325. error: 'onTaskError'
  326. });
  327. }
  328. },
  329. unInstallComponent: function (componentName, hostName) {
  330. if (!(hostName instanceof Array)) {
  331. hostName = [hostName];
  332. }
  333. for (var i = 0; i < hostName.length; i++) {
  334. App.ajax.send({
  335. name: 'admin.high_availability.maintenance_mode',
  336. sender: this,
  337. data: {
  338. hostName: hostName[i],
  339. componentName: componentName,
  340. taskNum: hostName.length,
  341. callback: 'checkBeforeDelete'
  342. },
  343. success: 'checkResult',
  344. error: 'checkResult'
  345. });
  346. }
  347. },
  348. checkBeforeDelete: function (componentName, hostName){
  349. this.set('hostsToPerformDel', []);
  350. if (!(hostName instanceof Array)) {
  351. hostName = [hostName];
  352. }
  353. for (var i = 0; i < hostName.length; i++) {
  354. App.ajax.send({
  355. name: 'admin.high_availability.getHostComponent',
  356. sender: this,
  357. data: {
  358. componentName: componentName,
  359. hostName: hostName[i],
  360. taskNum: hostName.length,
  361. callback: 'deleteComponent'
  362. },
  363. success: 'checkResult',
  364. error: 'checkResult'
  365. });
  366. }
  367. },
  368. checkResult: function () {
  369. var callback = arguments[2].callback;
  370. var hostName = arguments[2].hostName;
  371. var componentName = arguments[2].componentName;
  372. var taskNum = arguments[2].taskNum;
  373. var hostsToPerformDel = this.get('hostsToPerformDel');
  374. if(arguments[1] != 'error'){
  375. hostsToPerformDel.push({
  376. hostName: hostName,
  377. isOnHost: true
  378. });
  379. }else{
  380. hostsToPerformDel.push({
  381. hostName: 'error',
  382. isOnHost: false
  383. });
  384. }
  385. if(hostsToPerformDel.length == taskNum){
  386. var hostsForDel = hostsToPerformDel.filterProperty('isOnHost', true).mapProperty('hostName');
  387. this.set('hostsToPerformDel', []);
  388. if(hostsForDel.length == 0){
  389. this.onTaskCompleted();
  390. return;
  391. }
  392. this[callback](componentName, hostsForDel);
  393. }
  394. },
  395. deleteComponent: function (componentName, hostName) {
  396. if (!(hostName instanceof Array)) {
  397. hostName = [hostName];
  398. }
  399. this.set('numOfDelOperations', hostName.length);
  400. for (var i = 0; i < hostName.length; i++) {
  401. App.ajax.send({
  402. name: 'admin.high_availability.delete_component',
  403. sender: this,
  404. data: {
  405. componentName: componentName,
  406. hostName: hostName[i]
  407. },
  408. success: 'onDeleteComplete',
  409. error: 'onTaskError'
  410. });
  411. }
  412. },
  413. onDeleteComplete: function () {
  414. var leftOp = this.get('numOfDelOperations');
  415. if(leftOp > 1){
  416. this.set('numOfDelOperations', leftOp-1);
  417. return;
  418. }
  419. this.onTaskCompleted();
  420. }
  421. });