reassign_controller.js 11 KB

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