wizard_controller.js 5.9 KB

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