rollback_controller.js 13 KB

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