rollback_controller.js 13 KB

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