rollback_controller.js 17 KB

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