wizard_controller.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.HighAvailabilityWizardController = App.WizardController.extend({
  20. name: 'highAvailabilityWizardController',
  21. totalSteps: 9,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. content: Em.Object.create({
  27. controllerName: 'highAvailabilityWizardController',
  28. cluster: null,
  29. hosts: null,
  30. services: null,
  31. slaveComponentHosts: null,
  32. masterComponentHosts: null,
  33. serviceName: 'MISC',
  34. hdfsUser:"hdfs"
  35. }),
  36. /**
  37. * return new object extended from clusterStatusTemplate
  38. * @return Object
  39. */
  40. getCluster: function(){
  41. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  42. },
  43. /**
  44. * Load services data from server.
  45. */
  46. loadServicesFromServer: function() {
  47. var displayOrderConfig = require('data/services');
  48. var apiUrl = App.get('stack2VersionURL');
  49. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  50. //
  51. apiService.forEach(function(item, index){
  52. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  53. apiService[index].isDisabled = apiService[index].isSelected;
  54. apiService[index].isInstalled = apiService[index].isSelected;
  55. });
  56. this.set('content.services', apiService);
  57. App.db.setService(apiService);
  58. },
  59. /**
  60. * Load confirmed hosts.
  61. * Will be used at <code>Assign Masters(step5)</code> step
  62. */
  63. loadConfirmedHosts: function(){
  64. var hosts = App.db.getHosts();
  65. if(!hosts || !hosts.length){
  66. var hosts = {};
  67. App.Host.find().forEach(function(item){
  68. hosts[item.get('id')] = {
  69. name: item.get('id'),
  70. cpu: item.get('cpu'),
  71. memory: item.get('memory'),
  72. disk_info: item.get('diskInfo'),
  73. bootStatus: "REGISTERED",
  74. isInstalled: true
  75. };
  76. });
  77. App.db.setHosts(hosts);
  78. }
  79. this.set('content.hosts', hosts);
  80. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  81. },
  82. /**
  83. * Load master component hosts data for using in required step controllers
  84. */
  85. loadMasterComponentHosts: function () {
  86. var masterComponentHosts = App.db.getMasterComponentHosts();
  87. if(!masterComponentHosts){
  88. masterComponentHosts = [];
  89. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  90. masterComponentHosts.push({
  91. component: item.get('componentName'),
  92. hostName: item.get('host.hostName'),
  93. isInstalled: true
  94. })
  95. });
  96. }
  97. this.set("content.masterComponentHosts", masterComponentHosts);
  98. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  99. },
  100. /**
  101. * save status of the cluster.
  102. * @param clusterStatus object with status,requestId fields.
  103. */
  104. saveClusterStatus: function (clusterStatus) {
  105. var oldStatus = this.toObject(this.get('content.cluster'));
  106. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  107. if (clusterStatus.requestId) {
  108. clusterStatus.requestId.forEach(function (requestId) {
  109. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  110. clusterStatus.oldRequestsId.push(requestId)
  111. }
  112. }, this);
  113. }
  114. this.set('content.cluster', clusterStatus);
  115. this.save('cluster');
  116. },
  117. /**
  118. * Save Master Component Hosts data to Main Controller
  119. * @param stepController App.WizardStep5Controller
  120. */
  121. saveMasterComponentHosts: function (stepController) {
  122. var obj = stepController.get('selectedServicesMasters');
  123. var masterComponentHosts = [];
  124. obj.forEach(function (_component) {
  125. masterComponentHosts.push({
  126. display_name: _component.get('display_name'),
  127. component: _component.get('component_name'),
  128. hostName: _component.get('selectedHost'),
  129. serviceId: _component.get('serviceId'),
  130. isCurNameNode: _component.get('isCurNameNode'),
  131. isAddNameNode: _component.get('isAddNameNode'),
  132. isInstalled: true
  133. });
  134. });
  135. App.db.setMasterComponentHosts(masterComponentHosts);
  136. this.set('content.masterComponentHosts', masterComponentHosts);
  137. },
  138. loadComponentToReassign: function () {
  139. var masterComponent = App.db.getMasterToReassign();
  140. if (masterComponent) {
  141. this.set('content.reassign', masterComponent);
  142. }
  143. },
  144. /**
  145. * Load data for all steps until <code>current step</code>
  146. */
  147. loadAllPriorSteps: function () {
  148. var step = this.get('currentStep');
  149. switch (step) {
  150. case '9':
  151. case '8':
  152. case '7':
  153. case '6':
  154. case '5':
  155. case '4':
  156. case '3':
  157. case '2':
  158. this.loadServicesFromServer();
  159. this.loadMasterComponentHosts();
  160. this.loadConfirmedHosts();
  161. case '1':
  162. this.load('cluster');
  163. }
  164. },
  165. /**
  166. * Remove all loaded data.
  167. * Created as copy for App.router.clearAllSteps
  168. */
  169. clearAllSteps: function () {
  170. this.clearInstallOptions();
  171. // clear temporary information stored during the install
  172. this.set('content.cluster', this.getCluster());
  173. },
  174. /**
  175. * Clear all temporary data
  176. */
  177. finish: function () {
  178. this.setCurrentStep('1');
  179. this.clearAllSteps();
  180. this.clearStorageData();
  181. App.router.get('updateController').updateAll();
  182. }
  183. });