reassign_controller.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. hasManualSteps: false
  49. }),
  50. componentsWithManualSteps: ['NAMENODE', 'SECONDARY_NAMENODE'],
  51. addManualSteps: function () {
  52. this.set('content.hasManualSteps', this.get('componentsWithManualSteps').contains(this.get('content.reassign.component_name')));
  53. }.observes('content.reassign.component_name'),
  54. skipStep3: function () {
  55. return this.get('content.reassign.service_id') == 'GANGLIA';
  56. }.property('content.reassign.service_id'),
  57. /**
  58. * return new object extended from clusterStatusTemplate
  59. * @return Object
  60. */
  61. getCluster: function(){
  62. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  63. },
  64. /**
  65. * Load services data from server.
  66. */
  67. loadServicesFromServer: function() {
  68. var displayOrderConfig = require('data/services');
  69. var apiUrl = App.get('stack2VersionURL');
  70. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  71. //
  72. apiService.forEach(function(item, index){
  73. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  74. apiService[index].isDisabled = apiService[index].isSelected;
  75. apiService[index].isInstalled = apiService[index].isSelected;
  76. });
  77. this.set('content.services', apiService);
  78. App.db.setService(apiService);
  79. },
  80. /**
  81. * Load confirmed hosts.
  82. * Will be used at <code>Assign Masters(step5)</code> step
  83. */
  84. loadConfirmedHosts: function(){
  85. var hosts = App.db.getHosts();
  86. if(!hosts || !hosts.length){
  87. var hosts = {};
  88. App.Host.find().forEach(function(item){
  89. hosts[item.get('id')] = {
  90. name: item.get('id'),
  91. cpu: item.get('cpu'),
  92. memory: item.get('memory'),
  93. disk_info: item.get('diskInfo'),
  94. bootStatus: "REGISTERED",
  95. isInstalled: true
  96. };
  97. });
  98. App.db.setHosts(hosts);
  99. }
  100. this.set('content.hosts', hosts);
  101. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  102. },
  103. /**
  104. * Load master component hosts data for using in required step controllers
  105. */
  106. loadMasterComponentHosts: function () {
  107. var masterComponentHosts = App.db.getMasterComponentHosts();
  108. if(!masterComponentHosts){
  109. masterComponentHosts = [];
  110. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  111. masterComponentHosts.push({
  112. component: item.get('componentName'),
  113. hostName: item.get('host.hostName'),
  114. isInstalled: true
  115. })
  116. });
  117. }
  118. this.set("content.masterComponentHosts", masterComponentHosts);
  119. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  120. },
  121. /**
  122. * Load tasks statuses for step5 of Reassign Master Wizard to restore installation
  123. */
  124. loadTasksStatuses: function(){
  125. var statuses = App.db.getReassignTasksStatuses();
  126. this.set('content.tasksStatuses', statuses);
  127. console.log('ReassignMasterController.loadTasksStatuses: loaded statuses', statuses);
  128. },
  129. /**
  130. * save status of the cluster.
  131. * @param clusterStatus object with status,requestId fields.
  132. */
  133. saveClusterStatus: function (clusterStatus) {
  134. var oldStatus = this.toObject(this.get('content.cluster'));
  135. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  136. if (clusterStatus.requestId) {
  137. clusterStatus.requestId.forEach(function (requestId) {
  138. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  139. clusterStatus.oldRequestsId.push(requestId)
  140. }
  141. }, this);
  142. }
  143. this.set('content.cluster', clusterStatus);
  144. this.save('cluster');
  145. },
  146. /**
  147. * Save Master Component Hosts data to Main Controller
  148. * @param stepController App.WizardStep5Controller
  149. */
  150. saveMasterComponentHosts: function (stepController) {
  151. var obj = stepController.get('selectedServicesMasters');
  152. var masterComponentHosts = [];
  153. obj.forEach(function (_component) {
  154. masterComponentHosts.push({
  155. display_name: _component.get('display_name'),
  156. component: _component.get('component_name'),
  157. hostName: _component.get('selectedHost'),
  158. serviceId: _component.get('serviceId'),
  159. isInstalled: true
  160. });
  161. });
  162. App.db.setMasterComponentHosts(masterComponentHosts);
  163. this.set('content.masterComponentHosts', masterComponentHosts);
  164. },
  165. loadComponentToReassign: function () {
  166. var masterComponent = App.db.getMasterToReassign();
  167. if (masterComponent) {
  168. this.set('content.reassign', masterComponent);
  169. }
  170. },
  171. saveComponentToReassign: function (masterComponent) {
  172. var component = {
  173. component_name: masterComponent.get('componentName'),
  174. display_name: masterComponent.get('displayName'),
  175. service_id: masterComponent.get('service.serviceName'),
  176. host_id: masterComponent.get('host.hostName')
  177. };
  178. App.db.setMasterToReassign(component);
  179. },
  180. saveTasksStatuses: function(statuses){
  181. App.db.setReassignTasksStatuses(statuses);
  182. this.set('content.tasksStatuses', statuses);
  183. console.log('ReassignMasterController.saveTasksStatuses: saved statuses', statuses);
  184. },
  185. loadRequestIds: function(){
  186. var requestIds = App.db.getReassignMasterWizardRequestIds();
  187. this.set('content.requestIds', requestIds);
  188. },
  189. saveRequestIds: function(requestIds){
  190. App.db.setReassignMasterWizardRequestIds(requestIds);
  191. this.set('content.requestIds', requestIds);
  192. },
  193. saveLogs: function(logs){
  194. App.db.setReassignMasterWizardLogs(logs);
  195. this.set('content.logs', logs);
  196. },
  197. loadLogs: function(){
  198. var logs = App.db.getReassignMasterWizardLogs();
  199. this.set('content.logs', logs);
  200. },
  201. saveComponentDir: function(componentDir){
  202. App.db.setReassignMasterWizardComponentDir(componentDir);
  203. this.set('content.componentDir', componentDir);
  204. },
  205. loadComponentDir: function(){
  206. var componentDir = App.db.getReassignMasterWizardComponentDir();
  207. this.set('content.componentDir', componentDir);
  208. },
  209. /**
  210. * Load data for all steps until <code>current step</code>
  211. */
  212. loadAllPriorSteps: function () {
  213. var step = this.get('currentStep');
  214. switch (step) {
  215. case '6':
  216. case '5':
  217. this.loadComponentDir();
  218. case '4':
  219. this.loadTasksStatuses();
  220. this.loadRequestIds();
  221. this.loadLogs();
  222. case '3':
  223. case '2':
  224. this.loadServicesFromServer();
  225. this.loadMasterComponentHosts();
  226. this.loadConfirmedHosts();
  227. case '1':
  228. this.loadComponentToReassign();
  229. this.load('cluster');
  230. }
  231. },
  232. /**
  233. * Remove all loaded data.
  234. * Created as copy for App.router.clearAllSteps
  235. */
  236. clearAllSteps: function () {
  237. this.clearInstallOptions();
  238. // clear temporary information stored during the install
  239. this.set('content.cluster', this.getCluster());
  240. },
  241. /**
  242. * Clear all temporary data
  243. */
  244. finish: function () {
  245. this.setCurrentStep('1');
  246. this.clearAllSteps();
  247. this.clearStorageData();
  248. App.router.get('updateController').updateAll();
  249. }
  250. });