rollback_controller.js 13 KB

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