wizard_controller.js 7.7 KB

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