rollback_controller.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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: 'common.services.update',
  193. data: {
  194. context: "Stop all services",
  195. "ServiceInfo": {
  196. "state": "INSTALLED"
  197. }
  198. },
  199. sender: this,
  200. success: 'startPolling',
  201. error: 'onTaskError'
  202. });
  203. },
  204. restoreHBaseConfigs: function(){
  205. console.warn('func: restoreHBaseConfigs');
  206. this.loadConfigTag("hbaseSiteTag");
  207. var hbaseSiteTag = this.get("content.hbaseSiteTag");
  208. App.ajax.send({
  209. name: 'admin.high_availability.load_hbase_configs',
  210. sender: this,
  211. data: {
  212. hbaseSiteTag: hbaseSiteTag
  213. },
  214. success: 'onLoadHbaseConfigs',
  215. error: 'onTaskError'
  216. });
  217. },
  218. stopFailoverControllers: function(){
  219. console.warn('func: stopFailoverControllers');
  220. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  221. this.updateComponent('ZKFC', hostNames, "HDFS", "Stop");
  222. },
  223. deleteFailoverControllers: function(){
  224. console.warn('func: deleteFailoverControllers');
  225. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName');
  226. this.checkBeforeDelete('ZKFC', hostNames);
  227. },
  228. stopStandbyNameNode: function(){
  229. console.warn('func: stopStandbyNameNode');
  230. var hostName = this.get('content.masterComponentHosts').findProperty('isAddNameNode', true).hostName;
  231. this.updateComponent('NAMENODE', hostName, "HDFS", "Stop");
  232. },
  233. stopNameNode: function(){
  234. console.warn('func: stopNameNode');
  235. var hostName = this.get('content.masterComponentHosts').findProperty('isCurNameNode').hostName;
  236. this.updateComponent('NAMENODE', hostName, "HDFS", "Stop");
  237. },
  238. restoreHDFSConfigs: function(){
  239. console.warn('func: restoreHDFSConfigs');
  240. this.unInstallHDFSClients();
  241. },
  242. enableSecondaryNameNode: function(){
  243. console.warn('func: enableSecondaryNameNode');
  244. var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
  245. this.updateComponent('SECONDARY_NAMENODE', hostName, "HDFS", "Install", hostName.length);
  246. },
  247. stopJournalNodes: function(){
  248. console.warn('func: stopJournalNodes');
  249. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  250. this.updateComponent('JOURNALNODE', hostNames, "HDFS", "Stop");
  251. },
  252. deleteJournalNodes: function(){
  253. console.warn('func: deleteJournalNodes');
  254. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  255. this.unInstallComponent('JOURNALNODE', hostNames);
  256. },
  257. deleteAdditionalNameNode: function(){
  258. console.warn('func: deleteAdditionalNameNode');
  259. var hostNames = this.get('content.masterComponentHosts').filterProperty('isAddNameNode', true).mapProperty('hostName');
  260. this.unInstallComponent('NAMENODE', hostNames);
  261. },
  262. startAllServices: function(){
  263. console.warn('func: startAllServices');
  264. App.ajax.send({
  265. name: 'common.services.update',
  266. data: {
  267. context: "Start all services",
  268. "ServiceInfo": {
  269. "state": "STARTED"
  270. }
  271. },
  272. sender: this,
  273. success: 'startPolling',
  274. error: 'onTaskError'
  275. });
  276. },
  277. onLoadHbaseConfigs: function (data) {
  278. console.warn('func: onLoadHbaseConfigs');
  279. var hbaseSiteProperties = data.items.findProperty('type', 'hbase-site').properties;
  280. App.ajax.send({
  281. name: 'admin.high_availability.save_configs',
  282. sender: this,
  283. data: {
  284. siteName: 'hbase-site',
  285. properties: hbaseSiteProperties
  286. },
  287. success: 'onTaskCompleted',
  288. error: 'onTaskError'
  289. });
  290. },
  291. onDeletedHDFSClient: function () {
  292. console.warn('func: onDeletedHDFSClient');
  293. var deletedHdfsClients = this.get('deletedHdfsClients');
  294. var hostName = this.get("content.hdfsClientHostNames");
  295. var notDeletedHdfsClients = hostName.length - deletedHdfsClients;
  296. if (notDeletedHdfsClients > 1 && hostName.length != 1 ) {
  297. this.set('deletedHdfsClients', deletedHdfsClients+1);
  298. return;
  299. }
  300. this.loadConfigTag("hdfsSiteTag");
  301. this.loadConfigTag("coreSiteTag");
  302. var hdfsSiteTag = this.get("content.hdfsSiteTag");
  303. var coreSiteTag = this.get("content.coreSiteTag");
  304. App.ajax.send({
  305. name: 'admin.high_availability.load_configs',
  306. sender: this,
  307. data: {
  308. hdfsSiteTag: hdfsSiteTag,
  309. coreSiteTag: coreSiteTag
  310. },
  311. success: 'onLoadConfigs',
  312. error: 'onTaskError'
  313. });
  314. },
  315. onLoadConfigs: function (data) {
  316. console.warn('func: onLoadConfigs');
  317. this.set('configsSaved', false);
  318. App.ajax.send({
  319. name: 'admin.high_availability.save_configs',
  320. sender: this,
  321. data: {
  322. siteName: 'hdfs-site',
  323. properties: data.items.findProperty('type', 'hdfs-site').properties
  324. },
  325. success: 'onHdfsConfigsSaved',
  326. error: 'onTaskError'
  327. });
  328. App.ajax.send({
  329. name: 'admin.high_availability.save_configs',
  330. sender: this,
  331. data: {
  332. siteName: 'core-site',
  333. properties: data.items.findProperty('type', 'core-site').properties
  334. },
  335. success: 'onHdfsConfigsSaved',
  336. error: 'onTaskError'
  337. });
  338. },
  339. onHdfsConfigsSaved: function () {
  340. console.warn('func: onHdfsConfigsSaved');
  341. if (!this.get('configsSaved')) {
  342. this.set('configsSaved', true);
  343. return;
  344. }
  345. this.onTaskCompleted();
  346. },
  347. unInstallHDFSClients: function () {
  348. console.warn('func: unInstallHDFSClients');
  349. var hostName = this.get("content.hdfsClientHostNames");
  350. for (var i = 0; i < hostName.length; i++) {
  351. App.ajax.send({
  352. name: 'common.delete.host_component',
  353. sender: this,
  354. data: {
  355. componentName: 'HDFS_CLIENT',
  356. hostName: hostName[i]
  357. },
  358. success: 'onDeletedHDFSClient',
  359. error: 'onTaskError'
  360. });
  361. }
  362. },
  363. unInstallComponent: function (componentName, hostName) {
  364. console.warn('func: unInstallComponent');
  365. if (!(hostName instanceof Array)) {
  366. hostName = [hostName];
  367. }
  368. for (var i = 0; i < hostName.length; i++) {
  369. App.ajax.send({
  370. name: 'admin.high_availability.maintenance_mode',
  371. sender: this,
  372. data: {
  373. hostName: hostName[i],
  374. componentName: componentName,
  375. taskNum: hostName.length,
  376. callback: 'checkBeforeDelete'
  377. },
  378. success: 'checkResult',
  379. error: 'checkResult'
  380. });
  381. }
  382. },
  383. checkBeforeDelete: function (componentName, hostName){
  384. console.warn('func: checkBeforeDelete');
  385. this.set('hostsToPerformDel', []);
  386. if (!(hostName instanceof Array)) {
  387. hostName = [hostName];
  388. }
  389. for (var i = 0; i < hostName.length; i++) {
  390. App.ajax.send({
  391. name: 'admin.high_availability.getHostComponent',
  392. sender: this,
  393. data: {
  394. componentName: componentName,
  395. hostName: hostName[i],
  396. taskNum: hostName.length,
  397. callback: 'deleteComponent'
  398. },
  399. success: 'checkResult',
  400. error: 'checkResult'
  401. });
  402. }
  403. },
  404. checkResult: function () {
  405. console.warn('func: checkResult');
  406. var callback = arguments[2].callback;
  407. var hostName = arguments[2].hostName;
  408. var componentName = arguments[2].componentName;
  409. var taskNum = arguments[2].taskNum;
  410. var hostsToPerformDel = this.get('hostsToPerformDel');
  411. if(arguments[1] != 'error'){
  412. hostsToPerformDel.push({
  413. hostName: hostName,
  414. isOnHost: true
  415. });
  416. }else{
  417. hostsToPerformDel.push({
  418. hostName: 'error',
  419. isOnHost: false
  420. });
  421. }
  422. if(hostsToPerformDel.length == taskNum){
  423. var hostsForDel = hostsToPerformDel.filterProperty('isOnHost', true).mapProperty('hostName');
  424. this.set('hostsToPerformDel', []);
  425. if(hostsForDel.length == 0){
  426. this.onTaskCompleted();
  427. return;
  428. }
  429. this[callback](componentName, hostsForDel);
  430. }
  431. },
  432. deleteComponent: function (componentName, hostName) {
  433. console.warn('func: deleteComponent');
  434. if (!(hostName instanceof Array)) {
  435. hostName = [hostName];
  436. }
  437. this.set('numOfDelOperations', hostName.length);
  438. for (var i = 0; i < hostName.length; i++) {
  439. App.ajax.send({
  440. name: 'common.delete.host_component',
  441. sender: this,
  442. data: {
  443. componentName: componentName,
  444. hostName: hostName[i]
  445. },
  446. success: 'onDeleteComplete',
  447. error: 'onTaskError'
  448. });
  449. }
  450. },
  451. onDeleteComplete: function () {
  452. console.warn('func: onDeleteComplete');
  453. var leftOp = this.get('numOfDelOperations');
  454. if(leftOp > 1){
  455. this.set('numOfDelOperations', leftOp-1);
  456. return;
  457. }
  458. this.onTaskCompleted();
  459. }
  460. });