reassign_controller.js 9.9 KB

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