reassign_controller.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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.get('testMode')) {
  77. this.set('securityEnabled', !App.get('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 self = this;
  102. var tags = [
  103. {
  104. siteName: "hadoop-env",
  105. tagName: tag
  106. }
  107. ];
  108. App.router.get('configurationController').getConfigsByTags(tags).done(function (data) {
  109. var configs = data.findProperty('tag', tag).properties;
  110. var result = configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true);
  111. self.saveSecurityEnabled(result);
  112. App.clusterStatus.setClusterStatus({
  113. clusterName: self.get('content.cluster.name'),
  114. clusterState: 'DEFAULT',
  115. wizardControllerName: 'reassignMasterController',
  116. localdb: App.db.data
  117. });
  118. });
  119. },
  120. /**
  121. * Load tasks statuses for step5 of Reassign Master Wizard to restore installation
  122. */
  123. loadTasksStatuses: function () {
  124. var statuses = App.db.getReassignTasksStatuses();
  125. this.set('content.tasksStatuses', statuses);
  126. console.log('ReassignMasterController.loadTasksStatuses: loaded statuses', statuses);
  127. },
  128. /**
  129. * save status of the cluster.
  130. * @param clusterStatus object with status,requestId fields.
  131. */
  132. saveClusterStatus: function (clusterStatus) {
  133. var oldStatus = this.toObject(this.get('content.cluster'));
  134. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  135. if (clusterStatus.requestId) {
  136. clusterStatus.requestId.forEach(function (requestId) {
  137. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  138. clusterStatus.oldRequestsId.push(requestId)
  139. }
  140. }, this);
  141. }
  142. this.set('content.cluster', clusterStatus);
  143. this.save('cluster');
  144. },
  145. /**
  146. * Save Master Component Hosts data to Main Controller
  147. * @param stepController App.WizardStep5Controller
  148. */
  149. saveMasterComponentHosts: function (stepController) {
  150. var obj = stepController.get('selectedServicesMasters');
  151. var masterComponentHosts = [];
  152. obj.forEach(function (_component) {
  153. masterComponentHosts.push({
  154. display_name: _component.get('display_name'),
  155. component: _component.get('component_name'),
  156. hostName: _component.get('selectedHost'),
  157. serviceId: _component.get('serviceId'),
  158. isInstalled: true
  159. });
  160. });
  161. App.db.setMasterComponentHosts(masterComponentHosts);
  162. this.set('content.masterComponentHosts', masterComponentHosts);
  163. },
  164. loadComponentToReassign: function () {
  165. var masterComponent = App.db.getMasterToReassign();
  166. if (masterComponent) {
  167. this.set('content.reassign', masterComponent);
  168. }
  169. },
  170. saveComponentToReassign: function (masterComponent) {
  171. var component = {
  172. component_name: masterComponent.get('componentName'),
  173. display_name: masterComponent.get('displayName'),
  174. service_id: masterComponent.get('service.serviceName'),
  175. host_id: masterComponent.get('hostName')
  176. };
  177. App.db.setMasterToReassign(component);
  178. },
  179. saveTasksStatuses: function (statuses) {
  180. App.db.setReassignTasksStatuses(statuses);
  181. this.set('content.tasksStatuses', statuses);
  182. console.log('ReassignMasterController.saveTasksStatuses: saved statuses', statuses);
  183. },
  184. loadTasksRequestIds: function () {
  185. var requestIds = App.db.getReassignTasksRequestIds();
  186. this.set('content.tasksRequestIds', requestIds);
  187. },
  188. saveTasksRequestIds: function (requestIds) {
  189. App.db.setReassignTasksRequestIds(requestIds);
  190. this.set('content.tasksRequestIds', requestIds);
  191. },
  192. loadRequestIds: function () {
  193. var requestIds = App.db.getReassignMasterWizardRequestIds();
  194. this.set('content.requestIds', requestIds);
  195. },
  196. saveRequestIds: function (requestIds) {
  197. App.db.setReassignMasterWizardRequestIds(requestIds);
  198. this.set('content.requestIds', requestIds);
  199. },
  200. saveComponentDir: function (componentDir) {
  201. App.db.setReassignMasterWizardComponentDir(componentDir);
  202. this.set('content.componentDir', componentDir);
  203. },
  204. loadComponentDir: function () {
  205. var componentDir = App.db.getReassignMasterWizardComponentDir();
  206. this.set('content.componentDir', componentDir);
  207. },
  208. saveReassignHosts: function (reassignHosts) {
  209. App.db.setReassignMasterWizardReassignHosts(reassignHosts);
  210. this.set('content.reassignHosts', reassignHosts);
  211. },
  212. loadReassignHosts: function () {
  213. var reassignHosts = App.db.getReassignMasterWizardReassignHosts();
  214. this.set('content.reassignHosts', reassignHosts);
  215. },
  216. saveSecurityEnabled: function (securityEnabled) {
  217. this.setDBProperty('securityEnabled', securityEnabled);
  218. this.set('content.securityEnabled', securityEnabled);
  219. },
  220. loadSecurityEnabled: function () {
  221. var securityEnabled = this.getDBProperty('securityEnabled');
  222. this.set('content.securityEnabled', securityEnabled);
  223. },
  224. saveSecureConfigs: function (secureConfigs) {
  225. this.setDBProperty('secureConfigs', secureConfigs);
  226. this.set('content.secureConfigs', secureConfigs);
  227. },
  228. loadSecureConfigs: function () {
  229. var secureConfigs = this.getDBProperty('secureConfigs');
  230. this.set('content.secureConfigs', secureConfigs);
  231. },
  232. /**
  233. * Load data for all steps until <code>current step</code>
  234. */
  235. loadAllPriorSteps: function () {
  236. var step = this.get('currentStep');
  237. switch (step) {
  238. case '6':
  239. case '5':
  240. this.loadSecureConfigs();
  241. this.loadComponentDir();
  242. case '4':
  243. this.loadTasksStatuses();
  244. this.loadTasksRequestIds();
  245. this.loadRequestIds();
  246. case '3':
  247. this.loadReassignHosts();
  248. case '2':
  249. this.loadServicesFromServer();
  250. this.loadMasterComponentHosts();
  251. this.loadConfirmedHosts();
  252. case '1':
  253. this.loadComponentToReassign();
  254. this.load('cluster');
  255. }
  256. },
  257. /**
  258. * Remove all loaded data.
  259. * Created as copy for App.router.clearAllSteps
  260. */
  261. clearAllSteps: function () {
  262. this.clearInstallOptions();
  263. // clear temporary information stored during the install
  264. this.set('content.cluster', this.getCluster());
  265. },
  266. /**
  267. * Clear all temporary data
  268. */
  269. finish: function () {
  270. this.setCurrentStep('1');
  271. this.clearAllSteps();
  272. this.clearStorageData();
  273. App.router.get('updateController').updateAll();
  274. }
  275. });