reassign_controller.js 11 KB

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