wizard_controller.js 8.5 KB

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