reassign_controller.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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: 6,
  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. /**
  50. * return new object extended from clusterStatusTemplate
  51. * @return Object
  52. */
  53. getCluster: function(){
  54. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  55. },
  56. /**
  57. * Load services data from server.
  58. */
  59. loadServicesFromServer: function() {
  60. var displayOrderConfig = require('data/services');
  61. var apiUrl = App.get('stackVersionURL');
  62. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  63. //
  64. apiService.forEach(function(item, index){
  65. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  66. apiService[index].isDisabled = apiService[index].isSelected;
  67. apiService[index].isInstalled = apiService[index].isSelected;
  68. });
  69. this.set('content.services', apiService);
  70. App.db.setService(apiService);
  71. },
  72. /**
  73. * Load confirmed hosts.
  74. * Will be used at <code>Assign Masters(step5)</code> step
  75. */
  76. loadConfirmedHosts: function(){
  77. var hosts = App.db.getHosts();
  78. if(!hosts || !hosts.length){
  79. var hosts = {};
  80. App.Host.find().forEach(function(item){
  81. hosts[item.get('id')] = {
  82. name: item.get('id'),
  83. cpu: item.get('cpu'),
  84. memory: item.get('memory'),
  85. disk_info: item.get('diskInfo'),
  86. bootStatus: "REGISTERED",
  87. isInstalled: true
  88. };
  89. });
  90. App.db.setHosts(hosts);
  91. }
  92. this.set('content.hosts', hosts);
  93. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  94. },
  95. /**
  96. * Load master component hosts data for using in required step controllers
  97. */
  98. loadMasterComponentHosts: function () {
  99. var masterComponentHosts = App.db.getMasterComponentHosts();
  100. if(!masterComponentHosts){
  101. masterComponentHosts = [];
  102. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  103. masterComponentHosts.push({
  104. component: item.get('componentName'),
  105. hostName: item.get('host.hostName'),
  106. isInstalled: true
  107. })
  108. });
  109. }
  110. this.set("content.masterComponentHosts", masterComponentHosts);
  111. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  112. },
  113. /**
  114. * Save Master Component Hosts data to Main Controller
  115. * @param stepController App.WizardStep5Controller
  116. */
  117. saveMasterComponentHosts: function (stepController) {
  118. var obj = stepController.get('selectedServicesMasters');
  119. var masterComponentHosts = [];
  120. obj.forEach(function (_component) {
  121. masterComponentHosts.push({
  122. display_name: _component.get('display_name'),
  123. component: _component.get('component_name'),
  124. hostName: _component.get('selectedHost'),
  125. serviceId: _component.get('serviceId'),
  126. isInstalled: true
  127. });
  128. });
  129. App.db.setMasterComponentHosts(masterComponentHosts);
  130. this.set('content.masterComponentHosts', masterComponentHosts);
  131. },
  132. loadComponentToReassign: function () {
  133. var masterComponent = App.db.getMasterToReassign();
  134. if (masterComponent) {
  135. this.set('content.reassign', masterComponent);
  136. }
  137. },
  138. saveComponentToReassign: function (masterComponent) {
  139. var component = {
  140. component_name: masterComponent.get('componentName'),
  141. display_name: masterComponent.get('displayName'),
  142. service_id: masterComponent.get('service.serviceName'),
  143. host_id: masterComponent.get('host.hostName')
  144. };
  145. App.db.setMasterToReassign(component);
  146. },
  147. /**
  148. * Save config properties
  149. * @param stepController Step7WizardController
  150. */
  151. saveServiceConfigProperties: function (stepController) {
  152. var serviceConfigProperties = [];
  153. stepController.get('stepConfigs').forEach(function (_content) {
  154. _content.get('configs').forEach(function (_configProperties) {
  155. var displayType = _configProperties.get('displayType');
  156. if (displayType === 'directories' || displayType === 'directory') {
  157. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  158. _configProperties.set('value', value);
  159. }
  160. var configProperty = {
  161. id: _configProperties.get('id'),
  162. name: _configProperties.get('name'),
  163. value: _configProperties.get('value'),
  164. defaultValue: _configProperties.get('defaultValue'),
  165. service: _configProperties.get('serviceName'),
  166. domain: _configProperties.get('domain'),
  167. filename: _configProperties.get('filename')
  168. };
  169. serviceConfigProperties.push(configProperty);
  170. }, this);
  171. }, this);
  172. App.db.setServiceConfigProperties(serviceConfigProperties);
  173. this.set('content.serviceConfigProperties', serviceConfigProperties);
  174. },
  175. /**
  176. * Load data for all steps until <code>current step</code>
  177. */
  178. loadAllPriorSteps: function () {
  179. var step = this.get('currentStep');
  180. switch (step) {
  181. case '6':
  182. case '5':
  183. case '4':
  184. case '3':
  185. case '2':
  186. this.loadServicesFromServer();
  187. this.loadMasterComponentHosts();
  188. this.loadConfirmedHosts();
  189. case '1':
  190. this.loadComponentToReassign();
  191. this.load('cluster');
  192. }
  193. },
  194. /**
  195. * Remove all loaded data.
  196. * Created as copy for App.router.clearAllSteps
  197. */
  198. clearAllSteps: function () {
  199. this.clearInstallOptions();
  200. // clear temporary information stored during the install
  201. this.set('content.cluster', this.getCluster());
  202. },
  203. /**
  204. * Clear all temporary data
  205. */
  206. finish: function () {
  207. this.setCurrentStep('1');
  208. this.clearAllSteps();
  209. this.clearStorageData();
  210. App.router.get('updateController').updateAll();
  211. }
  212. });