wizard_controller.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 apiService = this.loadServiceComponents();
  60. apiService.forEach(function(item, index){
  61. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  62. apiService[index].isDisabled = apiService[index].isSelected;
  63. apiService[index].isInstalled = apiService[index].isSelected;
  64. });
  65. this.set('content.services', apiService);
  66. App.db.setService(apiService);
  67. },
  68. /**
  69. * Load confirmed hosts.
  70. * Will be used at <code>Assign Masters(step5)</code> step
  71. */
  72. loadConfirmedHosts: function(){
  73. var hosts = App.db.getHosts();
  74. if(!hosts || !hosts.length){
  75. var hosts = {};
  76. App.Host.find().forEach(function(item){
  77. hosts[item.get('id')] = {
  78. name: item.get('id'),
  79. cpu: item.get('cpu'),
  80. memory: item.get('memory'),
  81. disk_info: item.get('diskInfo'),
  82. bootStatus: "REGISTERED",
  83. isInstalled: true
  84. };
  85. });
  86. App.db.setHosts(hosts);
  87. }
  88. this.set('content.hosts', hosts);
  89. console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
  90. },
  91. /**
  92. * save status of the cluster.
  93. * @param clusterStatus object with status,requestId fields.
  94. */
  95. saveClusterStatus: function (clusterStatus) {
  96. var oldStatus = this.toObject(this.get('content.cluster'));
  97. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  98. if (clusterStatus.requestId) {
  99. clusterStatus.requestId.forEach(function (requestId) {
  100. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  101. clusterStatus.oldRequestsId.push(requestId)
  102. }
  103. }, this);
  104. }
  105. this.set('content.cluster', clusterStatus);
  106. this.save('cluster');
  107. },
  108. /**
  109. * Save Master Component Hosts data to Main Controller
  110. * @param stepController App.WizardStep5Controller
  111. */
  112. saveMasterComponentHosts: function (stepController) {
  113. var obj = stepController.get('selectedServicesMasters');
  114. var masterComponentHosts = [];
  115. obj.forEach(function (_component) {
  116. masterComponentHosts.push({
  117. display_name: _component.get('display_name'),
  118. component: _component.get('component_name'),
  119. hostName: _component.get('selectedHost'),
  120. serviceId: _component.get('serviceId'),
  121. isCurNameNode: _component.get('isCurNameNode'),
  122. isAddNameNode: _component.get('isAddNameNode'),
  123. isInstalled: true
  124. });
  125. });
  126. App.db.setMasterComponentHosts(masterComponentHosts);
  127. this.set('content.masterComponentHosts', masterComponentHosts);
  128. },
  129. saveHdfsUser: function () {
  130. App.db.setHighAvailabilityWizardHdfsUser(this.get('content.hdfsUser'));
  131. },
  132. saveTasksStatuses: function(statuses){
  133. App.db.setHighAvailabilityWizardTasksStatuses(statuses);
  134. this.set('content.tasksStatuses', statuses);
  135. },
  136. saveConfigTag: function(tag){
  137. App.db.setHighAvailabilityWizardConfigTag(tag);
  138. this.set('content.'+[tag.name], tag.value);
  139. },
  140. saveHdfsClientHosts: function(hostNames){
  141. App.db.setHighAvailabilityWizardHdfsClientHosts(hostNames);
  142. this.set('content.hdfsClientHostNames', hostNames);
  143. },
  144. /**
  145. * Save config properties
  146. * @param stepController HighAvailabilityWizardStep3Controller
  147. */
  148. saveServiceConfigProperties: function(stepController) {
  149. var serviceConfigProperties = [];
  150. var data = stepController.get('serverConfigData');
  151. var _content = stepController.get('stepConfigs')[0];
  152. _content.get('configs').forEach(function (_configProperties) {
  153. var siteObj = data.items.findProperty('type', _configProperties.get('filename'));
  154. if (siteObj) {
  155. siteObj.properties[_configProperties.get('name')] = _configProperties.get('value');
  156. }
  157. }, this);
  158. this.setDBProperty('serviceConfigProperties', data);
  159. this.set('content.serviceConfigProperties', data);
  160. },
  161. loadHdfsClientHosts: function(){
  162. var hostNames = App.db.getHighAvailabilityWizardHdfsClientHosts();
  163. if (!(hostNames instanceof Array)) {
  164. hostNames = [hostNames];
  165. }
  166. this.set('content.hdfsClientHostNames', hostNames);
  167. },
  168. loadConfigTag: function(tag){
  169. var tagVal = App.db.getHighAvailabilityWizardConfigTag(tag);
  170. this.set('content.'+tag, tagVal);
  171. },
  172. loadHdfsUser: function(){
  173. var hdfsUser = App.db.getHighAvailabilityWizardHdfsUser();
  174. this.set('content.hdfsUser', hdfsUser);
  175. },
  176. loadTasksStatuses: function(){
  177. var statuses = App.db.getHighAvailabilityWizardTasksStatuses();
  178. this.set('content.tasksStatuses', statuses);
  179. },
  180. /**
  181. * Load serviceConfigProperties to model
  182. */
  183. loadServiceConfigProperties: function () {
  184. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  185. this.set('content.serviceConfigProperties', serviceConfigProperties);
  186. },
  187. saveRequestIds: function(requestIds){
  188. App.db.setHighAvailabilityWizardRequestIds(requestIds);
  189. this.set('content.requestIds', requestIds);
  190. },
  191. saveLogs: function(logs){
  192. App.db.setHighAvailabilityWizardLogs(logs);
  193. this.set('content.logs', logs);
  194. },
  195. loadRequestIds: function(){
  196. var requestIds = App.db.getHighAvailabilityWizardRequestIds();
  197. this.set('content.requestIds', requestIds);
  198. },
  199. loadLogs: function(){
  200. var logs = App.db.getHighAvailabilityWizardLogs();
  201. this.set('content.logs', logs);
  202. },
  203. saveNameServiceId: function(nameServiceId){
  204. App.db.setHighAvailabilityWizardNameServiceId(nameServiceId);
  205. this.set('content.nameServiceId', nameServiceId);
  206. },
  207. loadNameServiceId: function(){
  208. var nameServiceId = App.db.getHighAvailabilityWizardNameServiceId();
  209. this.set('content.nameServiceId', nameServiceId);
  210. },
  211. /**
  212. * Load data for all steps until <code>current step</code>
  213. */
  214. loadAllPriorSteps: function () {
  215. var step = this.get('currentStep');
  216. switch (step) {
  217. case '9':
  218. case '8':
  219. case '7':
  220. case '6':
  221. case '5':
  222. this.loadTasksStatuses();
  223. this.loadRequestIds();
  224. this.loadLogs();
  225. case '4':
  226. case '3':
  227. this.loadNameServiceId();
  228. this.loadServiceConfigProperties();
  229. case '2':
  230. this.loadServicesFromServer();
  231. this.loadMasterComponentHosts();
  232. this.loadConfirmedHosts();
  233. this.loadHdfsUser();
  234. case '1':
  235. this.load('cluster');
  236. }
  237. },
  238. /**
  239. * Remove all loaded data.
  240. * Created as copy for App.router.clearAllSteps
  241. */
  242. clearAllSteps: function () {
  243. this.clearInstallOptions();
  244. // clear temporary information stored during the install
  245. this.set('content.cluster', this.getCluster());
  246. },
  247. clearTasksData: function () {
  248. this.saveTasksStatuses(undefined);
  249. this.saveRequestIds(undefined);
  250. this.saveLogs(undefined);
  251. },
  252. /**
  253. * Clear all temporary data
  254. */
  255. finish: function () {
  256. App.db.data.HighAvailabilityWizard = {};
  257. App.db.data.Installer = {};
  258. App.router.get('updateController').updateAll();
  259. }
  260. });