rollback_controller.js 16 KB

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