rollback_controller.js 16 KB

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