reassign_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 ('global' in configs) {
  94. this.getServiceConfigsFromServer(configs['global'].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: "global",
  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. * return new object extended from clusterStatusTemplate
  120. * @return Object
  121. */
  122. getCluster: function () {
  123. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  124. },
  125. /**
  126. * Load services data from server.
  127. */
  128. loadServicesFromServer: function () {
  129. var apiService = this.loadServiceComponents();
  130. apiService.forEach(function (item, index) {
  131. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  132. apiService[index].isDisabled = apiService[index].isSelected;
  133. apiService[index].isInstalled = apiService[index].isSelected;
  134. });
  135. this.set('content.services', apiService);
  136. App.db.setService(apiService);
  137. },
  138. /**
  139. * Load confirmed hosts.
  140. * Will be used at <code>Assign Masters(step5)</code> step
  141. */
  142. loadConfirmedHosts: function () {
  143. var hosts = App.db.getHosts();
  144. if (hosts) {
  145. this.set('content.hosts', hosts);
  146. }
  147. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  148. },
  149. /**
  150. * Load tasks statuses for step5 of Reassign Master Wizard to restore installation
  151. */
  152. loadTasksStatuses: function () {
  153. var statuses = App.db.getReassignTasksStatuses();
  154. this.set('content.tasksStatuses', statuses);
  155. console.log('ReassignMasterController.loadTasksStatuses: loaded statuses', statuses);
  156. },
  157. /**
  158. * save status of the cluster.
  159. * @param clusterStatus object with status,requestId fields.
  160. */
  161. saveClusterStatus: function (clusterStatus) {
  162. var oldStatus = this.toObject(this.get('content.cluster'));
  163. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  164. if (clusterStatus.requestId) {
  165. clusterStatus.requestId.forEach(function (requestId) {
  166. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  167. clusterStatus.oldRequestsId.push(requestId)
  168. }
  169. }, this);
  170. }
  171. this.set('content.cluster', clusterStatus);
  172. this.save('cluster');
  173. },
  174. /**
  175. * Save Master Component Hosts data to Main Controller
  176. * @param stepController App.WizardStep5Controller
  177. */
  178. saveMasterComponentHosts: function (stepController) {
  179. var obj = stepController.get('selectedServicesMasters');
  180. var masterComponentHosts = [];
  181. obj.forEach(function (_component) {
  182. masterComponentHosts.push({
  183. display_name: _component.get('display_name'),
  184. component: _component.get('component_name'),
  185. hostName: _component.get('selectedHost'),
  186. serviceId: _component.get('serviceId'),
  187. isInstalled: true
  188. });
  189. });
  190. App.db.setMasterComponentHosts(masterComponentHosts);
  191. this.set('content.masterComponentHosts', masterComponentHosts);
  192. },
  193. loadComponentToReassign: function () {
  194. var masterComponent = App.db.getMasterToReassign();
  195. if (masterComponent) {
  196. this.set('content.reassign', masterComponent);
  197. }
  198. },
  199. saveComponentToReassign: function (masterComponent) {
  200. var component = {
  201. component_name: masterComponent.get('componentName'),
  202. display_name: masterComponent.get('displayName'),
  203. service_id: masterComponent.get('service.serviceName'),
  204. host_id: masterComponent.get('hostName')
  205. };
  206. App.db.setMasterToReassign(component);
  207. },
  208. saveTasksStatuses: function (statuses) {
  209. App.db.setReassignTasksStatuses(statuses);
  210. this.set('content.tasksStatuses', statuses);
  211. console.log('ReassignMasterController.saveTasksStatuses: saved statuses', statuses);
  212. },
  213. loadTasksRequestIds: function () {
  214. var requestIds = App.db.getReassignTasksRequestIds();
  215. this.set('content.tasksRequestIds', requestIds);
  216. },
  217. saveTasksRequestIds: function (requestIds) {
  218. App.db.setReassignTasksRequestIds(requestIds);
  219. this.set('content.tasksRequestIds', requestIds);
  220. },
  221. loadRequestIds: function () {
  222. var requestIds = App.db.getReassignMasterWizardRequestIds();
  223. this.set('content.requestIds', requestIds);
  224. },
  225. saveRequestIds: function (requestIds) {
  226. App.db.setReassignMasterWizardRequestIds(requestIds);
  227. this.set('content.requestIds', requestIds);
  228. },
  229. saveComponentDir: function (componentDir) {
  230. App.db.setReassignMasterWizardComponentDir(componentDir);
  231. this.set('content.componentDir', componentDir);
  232. },
  233. loadComponentDir: function () {
  234. var componentDir = App.db.getReassignMasterWizardComponentDir();
  235. this.set('content.componentDir', componentDir);
  236. },
  237. saveReassignHosts: function (reassignHosts) {
  238. App.db.setReassignMasterWizardReassignHosts(reassignHosts);
  239. this.set('content.reassignHosts', reassignHosts);
  240. },
  241. loadReassignHosts: function () {
  242. var reassignHosts = App.db.getReassignMasterWizardReassignHosts();
  243. this.set('content.reassignHosts', reassignHosts);
  244. },
  245. saveSecurityEnabled: function (securityEnabled) {
  246. this.setDBProperty('securityEnabled', securityEnabled);
  247. this.set('content.securityEnabled', securityEnabled);
  248. },
  249. loadSecurityEnabled: function () {
  250. var securityEnabled = this.getDBProperty('securityEnabled');
  251. this.set('content.securityEnabled', securityEnabled);
  252. },
  253. saveSecureConfigs: function (secureConfigs) {
  254. this.setDBProperty('secureConfigs', secureConfigs);
  255. this.set('content.secureConfigs', secureConfigs);
  256. },
  257. loadSecureConfigs: function () {
  258. var secureConfigs = this.getDBProperty('secureConfigs');
  259. this.set('content.secureConfigs', secureConfigs);
  260. },
  261. /**
  262. * Load data for all steps until <code>current step</code>
  263. */
  264. loadAllPriorSteps: function () {
  265. var step = this.get('currentStep');
  266. switch (step) {
  267. case '6':
  268. case '5':
  269. this.loadSecureConfigs();
  270. this.loadComponentDir();
  271. case '4':
  272. this.loadTasksStatuses();
  273. this.loadTasksRequestIds();
  274. this.loadRequestIds();
  275. case '3':
  276. this.loadReassignHosts();
  277. case '2':
  278. this.loadServicesFromServer();
  279. this.loadMasterComponentHosts();
  280. this.loadConfirmedHosts();
  281. case '1':
  282. this.loadComponentToReassign();
  283. this.load('cluster');
  284. }
  285. },
  286. /**
  287. * Remove all loaded data.
  288. * Created as copy for App.router.clearAllSteps
  289. */
  290. clearAllSteps: function () {
  291. this.clearInstallOptions();
  292. // clear temporary information stored during the install
  293. this.set('content.cluster', this.getCluster());
  294. },
  295. /**
  296. * Clear all temporary data
  297. */
  298. finish: function () {
  299. this.setCurrentStep('1');
  300. this.clearAllSteps();
  301. this.clearStorageData();
  302. App.router.get('updateController').updateAll();
  303. }
  304. });