reassign_controller.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.ReassignMasterController = App.WizardController.extend({
  20. name: 'reassignMasterController',
  21. totalSteps: 4,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. /**
  27. * All wizards data will be stored in this variable
  28. *
  29. * cluster - cluster name
  30. * installOptions - ssh key, repo info, etc.
  31. * services - services list
  32. * hosts - list of selected hosts
  33. * slaveComponentHosts, - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * config??? - to be described later
  36. */
  37. content: Em.Object.create({
  38. cluster: null,
  39. hosts: null,
  40. installOptions: null,
  41. services: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'reassignMasterController',
  47. reassign: null
  48. }),
  49. skipStep3: function () {
  50. return this.get('content.reassign.service_id') == 'GANGLIA';
  51. }.property('content.reassign.service_id'),
  52. /**
  53. * return new object extended from clusterStatusTemplate
  54. * @return Object
  55. */
  56. getCluster: function(){
  57. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  58. },
  59. /**
  60. * Load services data from server.
  61. */
  62. loadServicesFromServer: function() {
  63. var displayOrderConfig = require('data/services');
  64. var apiUrl = App.get('stack2VersionURL');
  65. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  66. //
  67. apiService.forEach(function(item, index){
  68. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  69. apiService[index].isDisabled = apiService[index].isSelected;
  70. apiService[index].isInstalled = apiService[index].isSelected;
  71. });
  72. this.set('content.services', apiService);
  73. App.db.setService(apiService);
  74. },
  75. /**
  76. * Load confirmed hosts.
  77. * Will be used at <code>Assign Masters(step5)</code> step
  78. */
  79. loadConfirmedHosts: function(){
  80. var hosts = App.db.getHosts();
  81. if(!hosts || !hosts.length){
  82. var hosts = {};
  83. App.Host.find().forEach(function(item){
  84. hosts[item.get('id')] = {
  85. name: item.get('id'),
  86. cpu: item.get('cpu'),
  87. memory: item.get('memory'),
  88. disk_info: item.get('diskInfo'),
  89. bootStatus: "REGISTERED",
  90. isInstalled: true
  91. };
  92. });
  93. App.db.setHosts(hosts);
  94. }
  95. this.set('content.hosts', hosts);
  96. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  97. },
  98. /**
  99. * Load master component hosts data for using in required step controllers
  100. */
  101. loadMasterComponentHosts: function () {
  102. var masterComponentHosts = App.db.getMasterComponentHosts();
  103. if(!masterComponentHosts){
  104. masterComponentHosts = [];
  105. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  106. masterComponentHosts.push({
  107. component: item.get('componentName'),
  108. hostName: item.get('host.hostName'),
  109. isInstalled: true
  110. })
  111. });
  112. }
  113. this.set("content.masterComponentHosts", masterComponentHosts);
  114. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  115. },
  116. /**
  117. * Load tasks statuses for step5 of Reassign Master Wizard to restore installation
  118. */
  119. loadTasksStatuses: function(){
  120. var statuses = App.db.getReassignTasksStatuses();
  121. this.set('content.tasksStatuses', statuses);
  122. console.log('ReassignMasterController.loadTasksStatuses: loaded statuses', statuses);
  123. },
  124. /**
  125. * save status of the cluster.
  126. * @param clusterStatus object with status,requestId fields.
  127. */
  128. saveClusterStatus: function (clusterStatus) {
  129. var oldStatus = this.toObject(this.get('content.cluster'));
  130. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  131. if (clusterStatus.requestId) {
  132. clusterStatus.requestId.forEach(function (requestId) {
  133. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  134. clusterStatus.oldRequestsId.push(requestId)
  135. }
  136. }, this);
  137. }
  138. this.set('content.cluster', clusterStatus);
  139. this.save('cluster');
  140. },
  141. /**
  142. * Save Master Component Hosts data to Main Controller
  143. * @param stepController App.WizardStep5Controller
  144. */
  145. saveMasterComponentHosts: function (stepController) {
  146. var obj = stepController.get('selectedServicesMasters');
  147. var masterComponentHosts = [];
  148. obj.forEach(function (_component) {
  149. masterComponentHosts.push({
  150. display_name: _component.get('display_name'),
  151. component: _component.get('component_name'),
  152. hostName: _component.get('selectedHost'),
  153. serviceId: _component.get('serviceId'),
  154. isInstalled: true
  155. });
  156. });
  157. App.db.setMasterComponentHosts(masterComponentHosts);
  158. this.set('content.masterComponentHosts', masterComponentHosts);
  159. },
  160. loadComponentToReassign: function () {
  161. var masterComponent = App.db.getMasterToReassign();
  162. if (masterComponent) {
  163. this.set('content.reassign', masterComponent);
  164. }
  165. },
  166. saveComponentToReassign: function (masterComponent) {
  167. var component = {
  168. component_name: masterComponent.get('componentName'),
  169. display_name: masterComponent.get('displayName'),
  170. service_id: masterComponent.get('service.serviceName'),
  171. host_id: masterComponent.get('host.hostName')
  172. };
  173. App.db.setMasterToReassign(component);
  174. },
  175. saveTasksStatuses: function(statuses){
  176. App.db.setReassignTasksStatuses(statuses);
  177. this.set('content.tasksStatuses', statuses);
  178. console.log('ReassignMasterController.saveTasksStatuses: saved statuses', statuses);
  179. },
  180. /**
  181. * Load data for all steps until <code>current step</code>
  182. */
  183. loadAllPriorSteps: function () {
  184. var step = this.get('currentStep');
  185. switch (step) {
  186. case '4':
  187. this.loadTasksStatuses();
  188. case '3':
  189. case '2':
  190. this.loadServicesFromServer();
  191. this.loadMasterComponentHosts();
  192. this.loadConfirmedHosts();
  193. case '1':
  194. this.loadComponentToReassign();
  195. this.load('cluster');
  196. }
  197. },
  198. /**
  199. * Remove all loaded data.
  200. * Created as copy for App.router.clearAllSteps
  201. */
  202. clearAllSteps: function () {
  203. this.clearInstallOptions();
  204. // clear temporary information stored during the install
  205. this.set('content.cluster', this.getCluster());
  206. },
  207. /**
  208. * Clear all temporary data
  209. */
  210. finish: function () {
  211. this.setCurrentStep('1');
  212. this.clearAllSteps();
  213. this.clearStorageData();
  214. App.router.get('updateController').updateAll();
  215. }
  216. });