reassign_master_routes.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. module.exports = Em.Route.extend({
  19. route: '/reassign',
  20. enter: function (router) {
  21. console.log('in /service/reassign:enter');
  22. Em.run.next(function () {
  23. var reassignMasterController = router.get('reassignMasterController');
  24. App.router.get('updateController').set('isWorking', false);
  25. var hostsUrl = '/hosts?fields=Hosts/host_name,Hosts/disk_info,host_components';
  26. router.get('clusterController').requestHosts(hostsUrl, function () {
  27. console.log('Request for hosts, with disk_info parameter');
  28. });
  29. var popup = App.ModalPopup.show({
  30. classNames: ['full-width-modal'],
  31. header: Em.I18n.t('services.reassign.header'),
  32. bodyClass: App.ReassignMasterView.extend({
  33. controller: reassignMasterController
  34. }),
  35. primary: Em.I18n.t('form.cancel'),
  36. showFooter: false,
  37. secondary: null,
  38. onPrimary: function () {
  39. this.hide();
  40. App.router.get('updateController').set('isWorking', true);
  41. App.router.transitionTo('main.services.index');
  42. },
  43. onClose: function () {
  44. this.hide();
  45. App.router.get('updateController').set('isWorking', true);
  46. App.router.transitionTo('main.services.index')
  47. },
  48. didInsertElement: function () {
  49. this.fitHeight();
  50. }
  51. });
  52. reassignMasterController.set('popup', popup);
  53. App.clusterStatus.updateFromServer();
  54. var currentClusterStatus = App.clusterStatus.get('value');
  55. if (currentClusterStatus) {
  56. switch (currentClusterStatus.clusterState) {
  57. case 'REASSIGN_MASTER_INSTALLING' :
  58. App.db.data = currentClusterStatus.localdb;
  59. reassignMasterController.setCurrentStep(currentClusterStatus.localdb.ReassignMaster.currentStep);
  60. break;
  61. }
  62. }
  63. router.transitionTo('step' + reassignMasterController.get('currentStep'));
  64. });
  65. },
  66. step1: Em.Route.extend({
  67. route: '/step1',
  68. connectOutlets: function (router) {
  69. console.log('in reassignMaster.step1:connectOutlets');
  70. var controller = router.get('reassignMasterController');
  71. controller.setCurrentStep('1');
  72. controller.dataLoading().done(function () {
  73. controller.loadAllPriorSteps();
  74. controller.connectOutlet('reassignMasterWizardStep1', controller.get('content'));
  75. })
  76. },
  77. next: function (router) {
  78. App.db.setMasterComponentHosts(undefined);
  79. router.transitionTo('step2');
  80. },
  81. unroutePath: function () {
  82. return false;
  83. }
  84. }),
  85. step2: Em.Route.extend({
  86. route: '/step2',
  87. connectOutlets: function (router) {
  88. console.log('in reassignMaster.step2:connectOutlets');
  89. var controller = router.get('reassignMasterController');
  90. controller.setCurrentStep('2');
  91. controller.dataLoading().done(function () {
  92. controller.loadAllPriorSteps();
  93. controller.connectOutlet('reassignMasterWizardStep2', controller.get('content'));
  94. })
  95. },
  96. back: Em.Router.transitionTo('step1'),
  97. next: function (router) {
  98. var controller = router.get('reassignMasterController');
  99. var reassignMasterWizardStep2 = router.get('reassignMasterWizardStep2Controller');
  100. controller.saveMasterComponentHosts(reassignMasterWizardStep2);
  101. var reassignHosts = {};
  102. var componentName = reassignMasterWizardStep2.get('content.reassign.component_name');
  103. var masterAssignmentsHosts = reassignMasterWizardStep2.get('selectedServicesMasters').filterProperty('component_name', componentName).mapProperty('selectedHost');
  104. var currentMasterHosts = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('host.hostName');
  105. masterAssignmentsHosts.forEach(function (host) {
  106. if (!currentMasterHosts.contains(host)) {
  107. reassignHosts.target = host;
  108. }
  109. }, this);
  110. currentMasterHosts.forEach(function (host) {
  111. if (!masterAssignmentsHosts.contains(host)) {
  112. reassignHosts.source = host;
  113. }
  114. }, this);
  115. controller.saveReassignHosts(reassignHosts);
  116. router.transitionTo('step3');
  117. },
  118. unroutePath: function () {
  119. return false;
  120. }
  121. }),
  122. step3: Em.Route.extend({
  123. route: '/step3',
  124. connectOutlets: function (router) {
  125. console.log('in reassignMaster.step3:connectOutlets');
  126. var controller = router.get('reassignMasterController');
  127. controller.setCurrentStep('3');
  128. controller.dataLoading().done(function () {
  129. controller.loadAllPriorSteps();
  130. controller.connectOutlet('reassignMasterWizardStep3', controller.get('content'));
  131. })
  132. },
  133. back: Em.Router.transitionTo('step2'),
  134. next: function (router) {
  135. App.db.setReassignTasksStatuses(undefined);
  136. App.db.setReassignMasterWizardLogs(undefined);
  137. App.clusterStatus.setClusterStatus({
  138. clusterName: router.get('reassignMasterController.content.cluster.name'),
  139. clusterState: 'REASSIGN_MASTER_INSTALLING',
  140. wizardControllerName: 'reassignMasterController',
  141. localdb: App.db.data
  142. });
  143. router.transitionTo('step4');
  144. },
  145. unroutePath: function () {
  146. return false;
  147. }
  148. }),
  149. step4: Em.Route.extend({
  150. route: '/step4',
  151. connectOutlets: function (router) {
  152. console.log('in reassignMaster.step4:connectOutlets');
  153. var controller = router.get('reassignMasterController');
  154. controller.setCurrentStep('4');
  155. controller.dataLoading().done(function () {
  156. controller.loadAllPriorSteps();
  157. controller.setLowerStepsDisable(4);
  158. controller.connectOutlet('reassignMasterWizardStep4', controller.get('content'));
  159. })
  160. },
  161. next: function (router) {
  162. router.get('reassignMasterController').setCurrentStep('5');
  163. App.clusterStatus.setClusterStatus({
  164. clusterName: router.get('reassignMasterController.content.cluster.name'),
  165. clusterState: 'REASSIGN_MASTER_INSTALLING',
  166. wizardControllerName: 'reassignMasterController',
  167. localdb: App.db.data
  168. });
  169. router.transitionTo('step5');
  170. },
  171. complete: function (router) {
  172. var controller = router.get('reassignMasterController');
  173. var reassignMasterWizardStep4 = router.get('reassignMasterWizardStep4Controller');
  174. if (!reassignMasterWizardStep4.get('isSubmitDisabled')) {
  175. controller.finish();
  176. controller.get('popup').hide();
  177. App.clusterStatus.setClusterStatus({
  178. clusterName: router.get('reassignMasterController.content.cluster.name'),
  179. clusterState: 'REASSIGN_MASTER_COMPLETED',
  180. wizardControllerName: 'reassignMasterController',
  181. localdb: App.db.data
  182. });
  183. router.transitionTo('main.index');
  184. location.reload();
  185. }
  186. },
  187. unroutePath: function () {
  188. return false;
  189. }
  190. }),
  191. step5: Em.Route.extend({
  192. route: '/step5',
  193. connectOutlets: function (router) {
  194. console.log('in reassignMaster.step5:connectOutlets');
  195. var controller = router.get('reassignMasterController');
  196. controller.setCurrentStep('5');
  197. controller.dataLoading().done(function () {
  198. controller.loadAllPriorSteps();
  199. controller.setLowerStepsDisable(5);
  200. if ((controller.get('content.reassign.component_name') === 'NAMENODE') && (!App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE'))) {
  201. controller.usersLoading().done(function () {
  202. controller.connectOutlet('reassignMasterWizardStep5', controller.get('content'));
  203. })
  204. } else {
  205. controller.connectOutlet('reassignMasterWizardStep5', controller.get('content'));
  206. }
  207. })
  208. },
  209. next: Em.Router.transitionTo('step6'),
  210. unroutePath: function () {
  211. return false;
  212. }
  213. }),
  214. step6: Em.Route.extend({
  215. route: '/step6',
  216. connectOutlets: function (router) {
  217. console.log('in reassignMaster.step6:connectOutlets');
  218. var controller = router.get('reassignMasterController');
  219. controller.setCurrentStep('6');
  220. controller.dataLoading().done(function () {
  221. controller.loadAllPriorSteps();
  222. controller.setLowerStepsDisable(6);
  223. controller.connectOutlet('reassignMasterWizardStep6', controller.get('content'));
  224. })
  225. },
  226. next: function (router) {
  227. var controller = router.get('reassignMasterController');
  228. var reassignMasterWizardStep6 = router.get('reassignMasterWizardStep6Controller');
  229. if (!reassignMasterWizardStep6.get('isSubmitDisabled')) {
  230. controller.finish();
  231. controller.get('popup').hide();
  232. App.clusterStatus.setClusterStatus({
  233. clusterName: router.get('reassignMasterController.content.cluster.name'),
  234. clusterState: 'REASSIGN_MASTER_COMPLETED',
  235. wizardControllerName: 'reassignMasterController',
  236. localdb: App.db.data
  237. });
  238. router.transitionTo('main.index');
  239. location.reload();
  240. }
  241. },
  242. unroutePath: function () {
  243. return false;
  244. }
  245. }),
  246. gotoStep1: Em.Router.transitionTo('step1'),
  247. gotoStep2: Em.Router.transitionTo('step2'),
  248. gotoStep3: Em.Router.transitionTo('step3'),
  249. gotoStep4: Em.Router.transitionTo('step4'),
  250. gotoStep5: Em.Router.transitionTo('step5'),
  251. gotoStep6: Em.Router.transitionTo('step6'),
  252. backToServices: function (router) {
  253. App.router.get('updateController').set('isWorking', true);
  254. router.transitionTo('services');
  255. }
  256. });