wizard_controller.js 6.9 KB

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