reassign_controller.js 9.0 KB

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