rollback_controller.js 15 KB

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