wizard_controller.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. saveConfigTag: function(tag){
  145. App.db.setHighAvailabilityWizardConfigTag(tag);
  146. this.set('content.'+[tag.name], tag.value);
  147. },
  148. saveHdfsClientHosts: function(hostNames){
  149. App.db.setHighAvailabilityWizardHdfsClientHosts(hostNames);
  150. this.set('content.hdfsClientHostNames', hostNames);
  151. },
  152. loadHdfsClientHosts: function(){
  153. var hostNames = App.db.getHighAvailabilityWizardHdfsClientHosts();
  154. if (!(hostNames instanceof Array)) {
  155. hostNames = [hostNames];
  156. }
  157. this.set('content.hdfsClientHostNames', hostNames);
  158. },
  159. loadConfigTag: function(tag){
  160. var tagVal = App.db.getHighAvailabilityWizardConfigTag(tag);
  161. this.set('content.'+tag, tagVal);
  162. },
  163. loadTasksStatuses: function(){
  164. var statuses = App.db.getHighAvailabilityWizardTasksStatuses();
  165. this.set('content.tasksStatuses', statuses);
  166. },
  167. saveRequestIds: function(requestIds){
  168. App.db.setHighAvailabilityWizardRequestIds(requestIds);
  169. this.set('content.requestIds', requestIds);
  170. },
  171. saveLogs: function(logs){
  172. App.db.setHighAvailabilityWizardLogs(logs);
  173. this.set('content.logs', logs);
  174. },
  175. loadRequestIds: function(){
  176. var requestIds = App.db.getHighAvailabilityWizardRequestIds();
  177. this.set('content.requestIds', requestIds);
  178. },
  179. loadLogs: function(){
  180. var logs = App.db.getHighAvailabilityWizardLogs();
  181. this.set('content.logs', logs);
  182. },
  183. saveNameServiceId: function(nameServiceId){
  184. App.db.setHighAvailabilityWizardNameServiceId(nameServiceId);
  185. this.set('content.nameServiceId', nameServiceId);
  186. },
  187. loadNameServiceId: function(){
  188. var nameServiceId = App.db.getHighAvailabilityWizardNameServiceId();
  189. this.set('content.nameServiceId', nameServiceId);
  190. },
  191. /**
  192. * Load data for all steps until <code>current step</code>
  193. */
  194. loadAllPriorSteps: function () {
  195. var step = this.get('currentStep');
  196. switch (step) {
  197. case '9':
  198. case '8':
  199. case '7':
  200. case '6':
  201. case '5':
  202. this.loadNameServiceId();
  203. this.loadTasksStatuses();
  204. this.loadRequestIds();
  205. this.loadLogs();
  206. case '4':
  207. case '3':
  208. case '2':
  209. this.loadServicesFromServer();
  210. this.loadMasterComponentHosts();
  211. this.loadConfirmedHosts();
  212. case '1':
  213. this.load('cluster');
  214. }
  215. },
  216. /**
  217. * Remove all loaded data.
  218. * Created as copy for App.router.clearAllSteps
  219. */
  220. clearAllSteps: function () {
  221. this.clearInstallOptions();
  222. // clear temporary information stored during the install
  223. this.set('content.cluster', this.getCluster());
  224. },
  225. clearTasksData: function () {
  226. this.saveTasksStatuses(undefined);
  227. this.saveRequestIds(undefined);
  228. this.saveLogs(undefined);
  229. },
  230. /**
  231. * Clear all temporary data
  232. */
  233. finish: function () {
  234. this.setCurrentStep('1');
  235. this.clearAllSteps();
  236. App.router.get('updateController').updateAll();
  237. }
  238. });