reassign_controller.js 7.7 KB

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