reassign_controller.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. App.ReassignMasterController = App.WizardController.extend({
  20. name: 'reassignMasterController',
  21. totalSteps: 6,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. /**
  27. * All wizards data will be stored in this variable
  28. *
  29. * cluster - cluster name
  30. * installOptions - ssh key, repo info, etc.
  31. * services - services list
  32. * hosts - list of selected hosts
  33. * slaveComponentHosts, - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * config??? - to be described later
  36. */
  37. content: Em.Object.create({
  38. cluster: null,
  39. hosts: null,
  40. installOptions: null,
  41. services: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'reassignMasterController',
  47. isWizard: true,
  48. reassign: null
  49. }),
  50. /**
  51. * return new object extended from clusterStatusTemplate
  52. * @return Object
  53. */
  54. getCluster: function(){
  55. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  56. },
  57. /**
  58. * return true if cluster data is loaded and false otherwise
  59. */
  60. dataLoading: function(){
  61. var dfd = $.Deferred();
  62. this.connectOutlet('loading');
  63. if (App.router.get('clusterController.isLoaded')){
  64. dfd.resolve();
  65. } else{
  66. var interval = setInterval(function(){
  67. if (App.router.get('clusterController.isLoaded')){
  68. dfd.resolve();
  69. clearInterval(interval);
  70. }
  71. },50);
  72. }
  73. return dfd.promise();
  74. },
  75. /**
  76. * Load services data from server.
  77. */
  78. loadServicesFromServer: function() {
  79. var displayOrderConfig = require('data/services');
  80. var apiUrl = App.get('stackVersionURL');
  81. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  82. //
  83. apiService.forEach(function(item, index){
  84. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  85. apiService[index].isDisabled = apiService[index].isSelected;
  86. apiService[index].isInstalled = apiService[index].isSelected;
  87. });
  88. this.set('content.services', apiService);
  89. App.db.setService(apiService);
  90. },
  91. /**
  92. * Load confirmed hosts.
  93. * Will be used at <code>Assign Masters(step5)</code> step
  94. */
  95. loadConfirmedHosts: function(){
  96. var hosts = App.db.getHosts();
  97. if(!hosts || !hosts.length){
  98. var hosts = {};
  99. App.Host.find().forEach(function(item){
  100. hosts[item.get('id')] = {
  101. name: item.get('id'),
  102. cpu: item.get('cpu'),
  103. memory: item.get('memory'),
  104. disk_info: item.get('diskInfo'),
  105. bootStatus: "REGISTERED",
  106. isInstalled: true
  107. };
  108. });
  109. App.db.setHosts(hosts);
  110. }
  111. this.set('content.hosts', hosts);
  112. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  113. },
  114. /**
  115. * Load master component hosts data for using in required step controllers
  116. */
  117. loadMasterComponentHosts: function () {
  118. var masterComponentHosts = App.db.getMasterComponentHosts();
  119. if(!masterComponentHosts){
  120. masterComponentHosts = [];
  121. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  122. masterComponentHosts.push({
  123. component: item.get('componentName'),
  124. hostName: item.get('host.hostName'),
  125. isInstalled: true
  126. })
  127. });
  128. }
  129. this.set("content.masterComponentHosts", masterComponentHosts);
  130. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  131. this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  132. },
  133. loadComponentToReassign: function () {
  134. var masterComponent = App.db.getMasterToReassign();
  135. if (masterComponent) {
  136. this.set('content.reassign', masterComponent);
  137. }
  138. },
  139. saveComponentToReassign: function (masterComponent) {
  140. App.db.setMasterToReassign(masterComponent);
  141. },
  142. /**
  143. * Load data for all steps until <code>current step</code>
  144. */
  145. loadAllPriorSteps: function () {
  146. var step = this.get('currentStep');
  147. switch (step) {
  148. case '6':
  149. case '5':
  150. case '4':
  151. case '3':
  152. case '2':
  153. this.loadServicesFromServer();
  154. this.loadMasterComponentHosts();
  155. this.loadConfirmedHosts();
  156. case '1':
  157. this.loadComponentToReassign();
  158. }
  159. },
  160. /**
  161. * Remove all loaded data.
  162. * Created as copy for App.router.clearAllSteps
  163. */
  164. clearAllSteps: function () {
  165. this.clearInstallOptions();
  166. // clear temporary information stored during the install
  167. this.set('content.cluster', this.getCluster());
  168. },
  169. /**
  170. * Clear all temporary data
  171. */
  172. finish: function () {
  173. this.setCurrentStep('1');
  174. this.clearAllSteps();
  175. this.clearStorageData();
  176. App.router.get('updateController').updateAll();
  177. }
  178. });