rollback_controller.js 16 KB

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