rollback_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. },
  187. stopStandbyNameNode: function(){
  188. },
  189. stopNameNode: function(){
  190. },
  191. restoreHDFSConfigs: function(){
  192. this.unInstallHDFSClients();
  193. },
  194. enableSecondaryNameNode: function(){
  195. var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
  196. this.installComponent('SECONDARY_NAMENODE', hostName, hostName.length);
  197. },
  198. stopJournalNodes: function(){
  199. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  200. this.stopComponent('JOURNALNODE', hostNames);
  201. },
  202. deleteJournalNodes: function(){
  203. var hostNames = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  204. this.unInstallComponent('JOURNALNODE', hostNames);
  205. },
  206. deleteAdditionalNameNode: function(){
  207. var hostNames = this.get('content.masterComponentHosts').filterProperty('isAddNameNode', true).mapProperty('hostName');
  208. this.unInstallComponent('NAMENODE', hostNames);
  209. },
  210. startAllServices: function(){
  211. App.ajax.send({
  212. name: 'admin.high_availability.start_all_services',
  213. sender: this,
  214. success: 'startPolling',
  215. error: 'onTaskError'
  216. });
  217. },
  218. onLoadHbaseConfigs: function (data) {
  219. var hbaseSiteProperties = data.items.findProperty('type', 'hbase-site').properties;
  220. App.ajax.send({
  221. name: 'admin.high_availability.save_configs',
  222. sender: this,
  223. data: {
  224. siteName: 'hbase-site',
  225. properties: hbaseSiteProperties
  226. },
  227. success: 'onTaskCompleted',
  228. error: 'onTaskError'
  229. });
  230. },
  231. stopComponent: function (componentName, hostName) {
  232. if (!(hostName instanceof Array)) {
  233. hostName = [hostName];
  234. }
  235. for (var i = 0; i < hostName.length; i++) {
  236. App.ajax.send({
  237. name: 'admin.high_availability.stop_component',
  238. sender: this,
  239. data: {
  240. hostName: hostName[i],
  241. componentName: componentName,
  242. displayName: App.format.role(componentName),
  243. taskNum: hostName.length
  244. },
  245. success: 'startPolling',
  246. error: 'onTaskError'
  247. });
  248. }
  249. },
  250. onDeletedHDFSClient: function () {
  251. var deletedHdfsClients = this.get('deletedHdfsClients');
  252. var hostName = this.get("content.hdfsClientHostNames");
  253. var notDeletedHdfsClients = hostName.length - deletedHdfsClients;
  254. if (notDeletedHdfsClients > 1 && hostName.length != 1 ) {
  255. this.set('deletedHdfsClients', deletedHdfsClients+1);
  256. return;
  257. }
  258. this.loadConfigTag("hdfsSiteTag");
  259. this.loadConfigTag("coreSiteTag");
  260. var hdfsSiteTag = this.get("content.hdfsSiteTag");
  261. var coreSiteTag = this.get("content.coreSiteTag");
  262. App.ajax.send({
  263. name: 'admin.high_availability.load_configs',
  264. sender: this,
  265. data: {
  266. hdfsSiteTag: hdfsSiteTag,
  267. coreSiteTag: coreSiteTag
  268. },
  269. success: 'onLoadConfigs',
  270. error: 'onTaskError'
  271. });
  272. },
  273. onLoadConfigs: function (data) {
  274. this.set('configsSaved', false);
  275. App.ajax.send({
  276. name: 'admin.high_availability.save_configs',
  277. sender: this,
  278. data: {
  279. siteName: 'hdfs-site',
  280. properties: data.items.findProperty('type', 'hdfs-site').properties
  281. },
  282. success: 'onHdfsConfigsSaved',
  283. error: 'onTaskError'
  284. });
  285. App.ajax.send({
  286. name: 'admin.high_availability.save_configs',
  287. sender: this,
  288. data: {
  289. siteName: 'core-site',
  290. properties: data.items.findProperty('type', 'core-site').properties
  291. },
  292. success: 'onHdfsConfigsSaved',
  293. error: 'onTaskError'
  294. });
  295. },
  296. onHdfsConfigsSaved: function () {
  297. if (!this.get('configsSaved')) {
  298. this.set('configsSaved', true);
  299. return;
  300. }
  301. this.onTaskCompleted();
  302. },
  303. unInstallHDFSClients: function () {
  304. var hostName = this.get("content.hdfsClientHostNames");
  305. for (var i = 0; i < hostName.length; i++) {
  306. App.ajax.send({
  307. name: 'admin.high_availability.delete_component',
  308. sender: this,
  309. data: {
  310. componentName: 'HDFS_CLIENT',
  311. hostName: hostName[i]
  312. },
  313. success: 'onDeletedHDFSClient',
  314. error: 'onTaskError'
  315. });
  316. }
  317. },
  318. unInstallComponent: function (componentName, hostName) {
  319. if (!(hostName instanceof Array)) {
  320. hostName = [hostName];
  321. }
  322. for (var i = 0; i < hostName.length; i++) {
  323. App.ajax.send({
  324. name: 'admin.high_availability.maintenance_mode',
  325. sender: this,
  326. data: {
  327. hostName: hostName[i],
  328. componentName: componentName,
  329. taskNum: hostName.length
  330. },
  331. success: 'onMaintenanceComponent',
  332. error: 'onTaskError'
  333. });
  334. }
  335. },
  336. onMaintenanceComponent: function () {
  337. var hostName = arguments[2].hostName;
  338. var componentName = arguments[2].componentName;
  339. this.deleteComponent(componentName, hostName);
  340. },
  341. deleteComponent: function (componentName, hostName) {
  342. if (!(hostName instanceof Array)) {
  343. hostName = [hostName];
  344. }
  345. this.set('numOfDelOperations', hostName.length);
  346. for (var i = 0; i < hostName.length; i++) {
  347. App.ajax.send({
  348. name: 'admin.high_availability.delete_component',
  349. sender: this,
  350. data: {
  351. componentName: componentName,
  352. hostName: hostName[i]
  353. },
  354. success: 'onDeleteComplete',
  355. error: 'onTaskError'
  356. });
  357. }
  358. },
  359. onDeleteComplete: function () {
  360. var leftOp = this.get('numOfDelOperations');
  361. if(leftOp > 1){
  362. this.set('numOfDelOperations', leftOp-1);
  363. return;
  364. }
  365. this.onTaskCompleted();
  366. }
  367. });