reassign_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. group: "hadoop",
  50. reassign: null,
  51. componentsWithManualCommands: ['NAMENODE', 'SECONDARY_NAMENODE'],
  52. hasManualSteps: false,
  53. securityEnabled: false
  54. }),
  55. addManualSteps: function () {
  56. if (this.get('content.componentsWithManualCommands')) { // While logging off this function is called with content.componentsWithManualCommands undefined
  57. this.set('content.hasManualSteps', this.get('content.componentsWithManualCommands').contains(this.get('content.reassign.component_name')) || this.get('content.securityEnabled'));
  58. }
  59. }.observes('content.reassign.component_name', 'content.securityEnabled'),
  60. getSecurityStatus: function () {
  61. if (App.testMode) {
  62. this.set('securityEnabled', !App.testEnableSecurity);
  63. } else {
  64. //get Security Status From Server
  65. App.ajax.send({
  66. name: 'config.tags.sync',
  67. sender: this,
  68. success: 'getSecurityStatusSuccessCallback',
  69. error: 'errorCallback'
  70. });
  71. }
  72. },
  73. errorCallback: function () {
  74. console.error('Cannot get security status from server');
  75. },
  76. getSecurityStatusSuccessCallback: function (data) {
  77. var configs = data.Clusters.desired_configs;
  78. if ('global' in configs) {
  79. this.getServiceConfigsFromServer(configs['global'].tag);
  80. }
  81. else {
  82. console.error('Cannot get security status from server');
  83. }
  84. },
  85. getServiceConfigsFromServer: function (tag) {
  86. var tags = [
  87. {
  88. siteName: "global",
  89. tagName: tag
  90. }
  91. ];
  92. var data = App.router.get('configurationController').getConfigsByTags(tags);
  93. var configs = data.findProperty('tag', tag).properties;
  94. var result = configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true);
  95. this.saveSecurityEnabled(result);
  96. App.clusterStatus.setClusterStatus({
  97. clusterName: this.get('content.cluster.name'),
  98. wizardControllerName: 'reassignMasterController',
  99. localdb: App.db.data
  100. });
  101. },
  102. /**
  103. * return new object extended from clusterStatusTemplate
  104. * @return Object
  105. */
  106. getCluster: function () {
  107. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  108. },
  109. /**
  110. * Load services data from server.
  111. */
  112. loadServicesFromServer: function () {
  113. var displayOrderConfig = require('data/services');
  114. var apiUrl = App.get('stack2VersionURL');
  115. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  116. //
  117. apiService.forEach(function (item, index) {
  118. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  119. apiService[index].isDisabled = apiService[index].isSelected;
  120. apiService[index].isInstalled = apiService[index].isSelected;
  121. });
  122. this.set('content.services', apiService);
  123. App.db.setService(apiService);
  124. },
  125. /**
  126. * Load confirmed hosts.
  127. * Will be used at <code>Assign Masters(step5)</code> step
  128. */
  129. loadConfirmedHosts: function () {
  130. var hosts = App.db.getHosts();
  131. if (!hosts || !hosts.length) {
  132. var hosts = {};
  133. App.Host.find().forEach(function (item) {
  134. hosts[item.get('id')] = {
  135. name: item.get('id'),
  136. cpu: item.get('cpu'),
  137. memory: item.get('memory'),
  138. disk_info: item.get('diskInfo'),
  139. bootStatus: "REGISTERED",
  140. isInstalled: true
  141. };
  142. });
  143. App.db.setHosts(hosts);
  144. }
  145. this.set('content.hosts', hosts);
  146. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  147. },
  148. /**
  149. * Load master component hosts data for using in required step controllers
  150. */
  151. loadMasterComponentHosts: function () {
  152. var masterComponentHosts = App.db.getMasterComponentHosts();
  153. if (!masterComponentHosts) {
  154. masterComponentHosts = [];
  155. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  156. masterComponentHosts.push({
  157. component: item.get('componentName'),
  158. hostName: item.get('host.hostName'),
  159. isInstalled: true
  160. })
  161. });
  162. }
  163. this.set("content.masterComponentHosts", masterComponentHosts);
  164. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  165. },
  166. /**
  167. * Load tasks statuses for step5 of Reassign Master Wizard to restore installation
  168. */
  169. loadTasksStatuses: function () {
  170. var statuses = App.db.getReassignTasksStatuses();
  171. this.set('content.tasksStatuses', statuses);
  172. console.log('ReassignMasterController.loadTasksStatuses: loaded statuses', statuses);
  173. },
  174. /**
  175. * save status of the cluster.
  176. * @param clusterStatus object with status,requestId fields.
  177. */
  178. saveClusterStatus: function (clusterStatus) {
  179. var oldStatus = this.toObject(this.get('content.cluster'));
  180. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  181. if (clusterStatus.requestId) {
  182. clusterStatus.requestId.forEach(function (requestId) {
  183. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  184. clusterStatus.oldRequestsId.push(requestId)
  185. }
  186. }, this);
  187. }
  188. this.set('content.cluster', clusterStatus);
  189. this.save('cluster');
  190. },
  191. /**
  192. * Save Master Component Hosts data to Main Controller
  193. * @param stepController App.WizardStep5Controller
  194. */
  195. saveMasterComponentHosts: function (stepController) {
  196. var obj = stepController.get('selectedServicesMasters');
  197. var masterComponentHosts = [];
  198. obj.forEach(function (_component) {
  199. masterComponentHosts.push({
  200. display_name: _component.get('display_name'),
  201. component: _component.get('component_name'),
  202. hostName: _component.get('selectedHost'),
  203. serviceId: _component.get('serviceId'),
  204. isInstalled: true
  205. });
  206. });
  207. App.db.setMasterComponentHosts(masterComponentHosts);
  208. this.set('content.masterComponentHosts', masterComponentHosts);
  209. },
  210. loadComponentToReassign: function () {
  211. var masterComponent = App.db.getMasterToReassign();
  212. if (masterComponent) {
  213. this.set('content.reassign', masterComponent);
  214. }
  215. },
  216. saveComponentToReassign: function (masterComponent) {
  217. var component = {
  218. component_name: masterComponent.get('componentName'),
  219. display_name: masterComponent.get('displayName'),
  220. service_id: masterComponent.get('service.serviceName'),
  221. host_id: masterComponent.get('host.hostName')
  222. };
  223. App.db.setMasterToReassign(component);
  224. },
  225. saveTasksStatuses: function (statuses) {
  226. App.db.setReassignTasksStatuses(statuses);
  227. this.set('content.tasksStatuses', statuses);
  228. console.log('ReassignMasterController.saveTasksStatuses: saved statuses', statuses);
  229. },
  230. loadRequestIds: function () {
  231. var requestIds = App.db.getReassignMasterWizardRequestIds();
  232. this.set('content.requestIds', requestIds);
  233. },
  234. saveRequestIds: function (requestIds) {
  235. App.db.setReassignMasterWizardRequestIds(requestIds);
  236. this.set('content.requestIds', requestIds);
  237. },
  238. saveLogs: function (logs) {
  239. App.db.setReassignMasterWizardLogs(logs);
  240. this.set('content.logs', logs);
  241. },
  242. loadLogs: function () {
  243. var logs = App.db.getReassignMasterWizardLogs();
  244. this.set('content.logs', logs);
  245. },
  246. saveComponentDir: function (componentDir) {
  247. App.db.setReassignMasterWizardComponentDir(componentDir);
  248. this.set('content.componentDir', componentDir);
  249. },
  250. loadComponentDir: function () {
  251. var componentDir = App.db.getReassignMasterWizardComponentDir();
  252. this.set('content.componentDir', componentDir);
  253. },
  254. saveReassignHosts: function (reassignHosts) {
  255. App.db.setReassignMasterWizardReassignHosts(reassignHosts);
  256. this.set('content.reassignHosts', reassignHosts);
  257. },
  258. loadReassignHosts: function () {
  259. var reassignHosts = App.db.getReassignMasterWizardReassignHosts();
  260. this.set('content.reassignHosts', reassignHosts);
  261. },
  262. saveSecurityEnabled: function (securityEnabled) {
  263. this.setDBProperty('securityEnabled', securityEnabled);
  264. this.set('content.securityEnabled', securityEnabled);
  265. },
  266. loadSecurityEnabled: function () {
  267. var securityEnabled = this.getDBProperty('securityEnabled');
  268. this.set('content.securityEnabled', securityEnabled);
  269. },
  270. saveSecureConfigs: function (secureConfigs) {
  271. this.setDBProperty('secureConfigs', secureConfigs);
  272. this.set('content.secureConfigs', secureConfigs);
  273. },
  274. loadSecureConfigs: function () {
  275. var secureConfigs = this.getDBProperty('secureConfigs');
  276. this.set('content.secureConfigs', secureConfigs);
  277. },
  278. /**
  279. * Load data for all steps until <code>current step</code>
  280. */
  281. loadAllPriorSteps: function () {
  282. var step = this.get('currentStep');
  283. switch (step) {
  284. case '6':
  285. case '5':
  286. this.loadSecureConfigs();
  287. this.loadComponentDir();
  288. case '4':
  289. this.loadTasksStatuses();
  290. this.loadRequestIds();
  291. this.loadLogs();
  292. case '3':
  293. this.loadReassignHosts();
  294. case '2':
  295. this.loadServicesFromServer();
  296. this.loadMasterComponentHosts();
  297. this.loadConfirmedHosts();
  298. case '1':
  299. this.loadComponentToReassign();
  300. this.load('cluster');
  301. }
  302. },
  303. /**
  304. * Remove all loaded data.
  305. * Created as copy for App.router.clearAllSteps
  306. */
  307. clearAllSteps: function () {
  308. this.clearInstallOptions();
  309. // clear temporary information stored during the install
  310. this.set('content.cluster', this.getCluster());
  311. },
  312. /**
  313. * Clear all temporary data
  314. */
  315. finish: function () {
  316. this.setCurrentStep('1');
  317. this.clearAllSteps();
  318. this.clearStorageData();
  319. App.router.get('updateController').updateAll();
  320. }
  321. });