rollback_controller.js 13 KB

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