wizard_controller.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.HighAvailabilityWizardController = App.WizardController.extend({
  20. name: 'highAvailabilityWizardController',
  21. totalSteps: 9,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. content: Em.Object.create({
  27. controllerName: 'highAvailabilityWizardController',
  28. cluster: null,
  29. hosts: null,
  30. services: null,
  31. slaveComponentHosts: null,
  32. masterComponentHosts: null,
  33. serviceConfigProperties: [],
  34. serviceName: 'MISC',
  35. hdfsUser:"hdfs",
  36. nameServiceId: '',
  37. failedTask : null
  38. }),
  39. setCurrentStep: function (currentStep, completed) {
  40. this._super(currentStep, completed);
  41. App.clusterStatus.setClusterStatus({
  42. clusterName: this.get('content.cluster.name'),
  43. clusterState: 'HIGH_AVAILABILITY_DEPLOY',
  44. wizardControllerName: 'highAvailabilityWizardController',
  45. localdb: App.db.data
  46. });
  47. },
  48. /**
  49. * return new object extended from clusterStatusTemplate
  50. * @return Object
  51. */
  52. getCluster: function(){
  53. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  54. },
  55. /**
  56. * Load services data from server.
  57. */
  58. loadServicesFromServer: function() {
  59. var displayOrderConfig = require('data/services');
  60. var apiUrl = App.get('stack2VersionURL');
  61. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  62. //
  63. apiService.forEach(function(item, index){
  64. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  65. apiService[index].isDisabled = apiService[index].isSelected;
  66. apiService[index].isInstalled = apiService[index].isSelected;
  67. });
  68. this.set('content.services', apiService);
  69. App.db.setService(apiService);
  70. },
  71. /**
  72. * Load confirmed hosts.
  73. * Will be used at <code>Assign Masters(step5)</code> step
  74. */
  75. loadConfirmedHosts: function(){
  76. var hosts = App.db.getHosts();
  77. if(!hosts || !hosts.length){
  78. var hosts = {};
  79. App.Host.find().forEach(function(item){
  80. hosts[item.get('id')] = {
  81. name: item.get('id'),
  82. cpu: item.get('cpu'),
  83. memory: item.get('memory'),
  84. disk_info: item.get('diskInfo'),
  85. bootStatus: "REGISTERED",
  86. isInstalled: true
  87. };
  88. });
  89. App.db.setHosts(hosts);
  90. }
  91. this.set('content.hosts', hosts);
  92. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  93. },
  94. /**
  95. * Load master component hosts data for using in required step controllers
  96. */
  97. loadMasterComponentHosts: function () {
  98. var masterComponentHosts = App.db.getMasterComponentHosts();
  99. if(!masterComponentHosts){
  100. masterComponentHosts = [];
  101. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  102. masterComponentHosts.push({
  103. component: item.get('componentName'),
  104. hostName: item.get('host.hostName'),
  105. isInstalled: true
  106. })
  107. });
  108. }
  109. this.set("content.masterComponentHosts", masterComponentHosts);
  110. console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  111. },
  112. /**
  113. * save status of the cluster.
  114. * @param clusterStatus object with status,requestId fields.
  115. */
  116. saveClusterStatus: function (clusterStatus) {
  117. var oldStatus = this.toObject(this.get('content.cluster'));
  118. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  119. if (clusterStatus.requestId) {
  120. clusterStatus.requestId.forEach(function (requestId) {
  121. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  122. clusterStatus.oldRequestsId.push(requestId)
  123. }
  124. }, this);
  125. }
  126. this.set('content.cluster', clusterStatus);
  127. this.save('cluster');
  128. },
  129. /**
  130. * Save Master Component Hosts data to Main Controller
  131. * @param stepController App.WizardStep5Controller
  132. */
  133. saveMasterComponentHosts: function (stepController) {
  134. var obj = stepController.get('selectedServicesMasters');
  135. var masterComponentHosts = [];
  136. obj.forEach(function (_component) {
  137. masterComponentHosts.push({
  138. display_name: _component.get('display_name'),
  139. component: _component.get('component_name'),
  140. hostName: _component.get('selectedHost'),
  141. serviceId: _component.get('serviceId'),
  142. isCurNameNode: _component.get('isCurNameNode'),
  143. isAddNameNode: _component.get('isAddNameNode'),
  144. isInstalled: true
  145. });
  146. });
  147. App.db.setMasterComponentHosts(masterComponentHosts);
  148. this.set('content.masterComponentHosts', masterComponentHosts);
  149. },
  150. saveHdfsUser: function () {
  151. App.db.setHighAvailabilityWizardHdfsUser(this.get('content.hdfsUser'));
  152. },
  153. saveTasksStatuses: function(statuses){
  154. App.db.setHighAvailabilityWizardTasksStatuses(statuses);
  155. this.set('content.tasksStatuses', statuses);
  156. },
  157. saveConfigTag: function(tag){
  158. App.db.setHighAvailabilityWizardConfigTag(tag);
  159. this.set('content.'+[tag.name], tag.value);
  160. },
  161. saveHdfsClientHosts: function(hostNames){
  162. App.db.setHighAvailabilityWizardHdfsClientHosts(hostNames);
  163. this.set('content.hdfsClientHostNames', hostNames);
  164. },
  165. /**
  166. * Save config properties
  167. * @param stepController HighAvailabilityWizardStep3Controller
  168. */
  169. saveServiceConfigProperties: function(stepController) {
  170. var serviceConfigProperties = [];
  171. var data = stepController.get('serverConfigData');
  172. var _content = stepController.get('stepConfigs')[0];
  173. _content.get('configs').forEach(function (_configProperties) {
  174. var siteObj = data.items.findProperty('type', _configProperties.get('filename'));
  175. if (siteObj) {
  176. siteObj.properties[_configProperties.get('name')] = _configProperties.get('value');
  177. }
  178. }, this);
  179. this.setDBProperty('serviceConfigProperties', data);
  180. this.set('content.serviceConfigProperties', data);
  181. },
  182. loadHdfsClientHosts: function(){
  183. var hostNames = App.db.getHighAvailabilityWizardHdfsClientHosts();
  184. if (!(hostNames instanceof Array)) {
  185. hostNames = [hostNames];
  186. }
  187. this.set('content.hdfsClientHostNames', hostNames);
  188. },
  189. loadConfigTag: function(tag){
  190. var tagVal = App.db.getHighAvailabilityWizardConfigTag(tag);
  191. this.set('content.'+tag, tagVal);
  192. },
  193. loadHdfsUser: function(){
  194. var hdfsUser = App.db.getHighAvailabilityWizardHdfsUser();
  195. this.set('content.hdfsUser', hdfsUser);
  196. },
  197. loadTasksStatuses: function(){
  198. var statuses = App.db.getHighAvailabilityWizardTasksStatuses();
  199. this.set('content.tasksStatuses', statuses);
  200. },
  201. /**
  202. * Load serviceConfigProperties to model
  203. */
  204. loadServiceConfigProperties: function () {
  205. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  206. this.set('content.serviceConfigProperties', serviceConfigProperties);
  207. },
  208. saveRequestIds: function(requestIds){
  209. App.db.setHighAvailabilityWizardRequestIds(requestIds);
  210. this.set('content.requestIds', requestIds);
  211. },
  212. saveLogs: function(logs){
  213. App.db.setHighAvailabilityWizardLogs(logs);
  214. this.set('content.logs', logs);
  215. },
  216. loadRequestIds: function(){
  217. var requestIds = App.db.getHighAvailabilityWizardRequestIds();
  218. this.set('content.requestIds', requestIds);
  219. },
  220. loadLogs: function(){
  221. var logs = App.db.getHighAvailabilityWizardLogs();
  222. this.set('content.logs', logs);
  223. },
  224. saveNameServiceId: function(nameServiceId){
  225. App.db.setHighAvailabilityWizardNameServiceId(nameServiceId);
  226. this.set('content.nameServiceId', nameServiceId);
  227. },
  228. loadNameServiceId: function(){
  229. var nameServiceId = App.db.getHighAvailabilityWizardNameServiceId();
  230. this.set('content.nameServiceId', nameServiceId);
  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 '9':
  239. case '8':
  240. case '7':
  241. case '6':
  242. case '5':
  243. this.loadTasksStatuses();
  244. this.loadRequestIds();
  245. this.loadLogs();
  246. case '4':
  247. case '3':
  248. this.loadNameServiceId();
  249. this.loadServiceConfigProperties();
  250. case '2':
  251. this.loadServicesFromServer();
  252. this.loadMasterComponentHosts();
  253. this.loadConfirmedHosts();
  254. this.loadHdfsUser();
  255. case '1':
  256. this.load('cluster');
  257. }
  258. },
  259. /**
  260. * Remove all loaded data.
  261. * Created as copy for App.router.clearAllSteps
  262. */
  263. clearAllSteps: function () {
  264. this.clearInstallOptions();
  265. // clear temporary information stored during the install
  266. this.set('content.cluster', this.getCluster());
  267. },
  268. clearTasksData: function () {
  269. this.saveTasksStatuses(undefined);
  270. this.saveRequestIds(undefined);
  271. this.saveLogs(undefined);
  272. },
  273. /**
  274. * Clear all temporary data
  275. */
  276. finish: function () {
  277. App.db.data.HighAvailabilityWizard = {};
  278. App.db.data.Installer = {};
  279. App.router.get('updateController').updateAll();
  280. }
  281. });