reassign_controller.js 11 KB

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