reassign_controller.js 11 KB

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