rollback_controller.js 13 KB

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