rollback_wizard_controller.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.RollbackHighAvailabilityWizardController = App.WizardController.extend({
  20. name: 'rollbackHighAvailabilityWizardController',
  21. totalSteps: 3,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. content: Em.Object.create({
  27. controllerName: 'RollbackHighAvailabilityWizardController',
  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.setRollbackHighAvailabilityWizardTasksStatuses(statuses);
  142. this.set('content.tasksStatuses', statuses);
  143. },
  144. loadTasksStatuses: function(){
  145. var statuses = App.db.getRollbackHighAvailabilityWizardTasksStatuses();
  146. this.set('content.tasksStatuses', statuses);
  147. },
  148. saveRequestIds: function(requestIds){
  149. App.db.setRollbackHighAvailabilityWizardRequestIds(requestIds);
  150. this.set('content.requestIds', requestIds);
  151. },
  152. saveLogs: function(logs){
  153. App.db.setRollbackHighAvailabilityWizardLogs(logs);
  154. this.set('content.logs', logs);
  155. },
  156. loadRequestIds: function(){
  157. var requestIds = App.db.getRollbackHighAvailabilityWizardRequestIds();
  158. this.set('content.requestIds', requestIds);
  159. },
  160. loadLogs: function(){
  161. var logs = App.db.getRollbackHighAvailabilityWizardLogs();
  162. this.set('content.logs', logs);
  163. },
  164. /**
  165. * Load data for all steps until <code>current step</code>
  166. */
  167. loadAllPriorSteps: function () {
  168. var step = this.get('currentStep');
  169. switch (step) {
  170. case '3':
  171. case '2':
  172. //this.loadServicesFromServer();
  173. //this.loadMasterComponentHosts();
  174. //this.loadConfirmedHosts();
  175. case '1':
  176. this.load('cluster');
  177. }
  178. },
  179. /**
  180. * Remove all loaded data.
  181. * Created as copy for App.router.clearAllSteps
  182. */
  183. clearAllSteps: function () {
  184. this.clearInstallOptions();
  185. // clear temporary information stored during the install
  186. this.set('content.cluster', this.getCluster());
  187. },
  188. clearTasksData: function () {
  189. this.saveTasksStatuses(undefined);
  190. this.saveRequestIds(undefined);
  191. this.saveLogs(undefined);
  192. },
  193. /**
  194. * Clear all temporary data
  195. */
  196. finish: function () {
  197. this.setCurrentStep('1');
  198. this.clearAllSteps();
  199. App.router.get('updateController').updateAll();
  200. }
  201. });