wizard_controller.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. requestIds: null
  39. }),
  40. setCurrentStep: function (currentStep, completed) {
  41. this._super(currentStep, completed);
  42. App.clusterStatus.setClusterStatus({
  43. clusterName: this.get('content.cluster.name'),
  44. clusterState: 'HIGH_AVAILABILITY_DEPLOY',
  45. wizardControllerName: 'highAvailabilityWizardController',
  46. localdb: App.db.data
  47. });
  48. },
  49. /**
  50. * return new object extended from clusterStatusTemplate
  51. * @return Object
  52. */
  53. getCluster: function(){
  54. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  55. },
  56. /**
  57. * save status of the cluster.
  58. * @param clusterStatus object with status,requestId fields.
  59. */
  60. saveClusterStatus: function (clusterStatus) {
  61. var oldStatus = this.toObject(this.get('content.cluster'));
  62. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  63. if (clusterStatus.requestId) {
  64. clusterStatus.requestId.forEach(function (requestId) {
  65. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  66. clusterStatus.oldRequestsId.push(requestId)
  67. }
  68. }, this);
  69. }
  70. this.set('content.cluster', clusterStatus);
  71. this.save('cluster');
  72. },
  73. /**
  74. * Save Master Component Hosts data to Main Controller
  75. * @param stepController App.WizardStep5Controller
  76. */
  77. saveMasterComponentHosts: function (stepController) {
  78. var obj = stepController.get('selectedServicesMasters');
  79. var masterComponentHosts = [];
  80. obj.forEach(function (_component) {
  81. masterComponentHosts.push({
  82. display_name: _component.get('display_name'),
  83. component: _component.get('component_name'),
  84. hostName: _component.get('selectedHost'),
  85. serviceId: _component.get('serviceId'),
  86. isCurNameNode: _component.get('isCurNameNode'),
  87. isAddNameNode: _component.get('isAddNameNode'),
  88. isInstalled: true
  89. });
  90. });
  91. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  92. this.set('content.masterComponentHosts', masterComponentHosts);
  93. },
  94. saveHdfsUser: function () {
  95. App.db.setHighAvailabilityWizardHdfsUser(this.get('content.hdfsUser'));
  96. },
  97. saveTasksStatuses: function(statuses){
  98. App.db.setHighAvailabilityWizardTasksStatuses(statuses);
  99. this.set('content.tasksStatuses', statuses);
  100. },
  101. saveConfigTag: function(tag){
  102. App.db.setHighAvailabilityWizardConfigTag(tag);
  103. this.set('content.'+[tag.name], tag.value);
  104. },
  105. saveHdfsClientHosts: function(hostNames){
  106. App.db.setHighAvailabilityWizardHdfsClientHosts(hostNames);
  107. this.set('content.hdfsClientHostNames', hostNames);
  108. },
  109. /**
  110. * Save config properties
  111. * @param stepController HighAvailabilityWizardStep3Controller
  112. */
  113. saveServiceConfigProperties: function(stepController) {
  114. var serviceConfigProperties = [];
  115. var data = stepController.get('serverConfigData');
  116. var _content = stepController.get('stepConfigs')[0];
  117. _content.get('configs').forEach(function (_configProperties) {
  118. var siteObj = data.items.findProperty('type', _configProperties.get('filename'));
  119. if (siteObj) {
  120. siteObj.properties[_configProperties.get('name')] = _configProperties.get('value');
  121. }
  122. }, this);
  123. this.setDBProperty('serviceConfigProperties', data);
  124. this.set('content.serviceConfigProperties', data);
  125. },
  126. loadHdfsClientHosts: function(){
  127. var hostNames = App.db.getHighAvailabilityWizardHdfsClientHosts();
  128. if (!(hostNames instanceof Array)) {
  129. hostNames = [hostNames];
  130. }
  131. this.set('content.hdfsClientHostNames', hostNames);
  132. },
  133. loadConfigTag: function(tag){
  134. var tagVal = App.db.getHighAvailabilityWizardConfigTag(tag);
  135. this.set('content.'+tag, tagVal);
  136. },
  137. loadHdfsUser: function(){
  138. var hdfsUser = App.db.getHighAvailabilityWizardHdfsUser();
  139. this.set('content.hdfsUser', hdfsUser);
  140. },
  141. loadTasksStatuses: function(){
  142. var statuses = App.db.getHighAvailabilityWizardTasksStatuses();
  143. this.set('content.tasksStatuses', statuses);
  144. },
  145. /**
  146. * Load serviceConfigProperties to model
  147. */
  148. loadServiceConfigProperties: function () {
  149. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  150. this.set('content.serviceConfigProperties', serviceConfigProperties);
  151. },
  152. saveRequestIds: function(requestIds){
  153. App.db.setHighAvailabilityWizardRequestIds(requestIds);
  154. this.set('content.requestIds', requestIds);
  155. },
  156. loadRequestIds: function(){
  157. var requestIds = App.db.getHighAvailabilityWizardRequestIds();
  158. this.set('content.requestIds', requestIds);
  159. },
  160. saveNameServiceId: function(nameServiceId){
  161. App.db.setHighAvailabilityWizardNameServiceId(nameServiceId);
  162. this.set('content.nameServiceId', nameServiceId);
  163. },
  164. loadNameServiceId: function(){
  165. var nameServiceId = App.db.getHighAvailabilityWizardNameServiceId();
  166. this.set('content.nameServiceId', nameServiceId);
  167. },
  168. saveTasksRequestIds: function (requestIds) {
  169. App.db.setHighAvailabilityWizardTasksRequestIds(requestIds);
  170. this.set('content.tasksRequestIds', requestIds);
  171. },
  172. loadTasksRequestIds: function () {
  173. var requestIds = App.db.getHighAvailabilityWizardTasksRequestIds();
  174. this.set('content.tasksRequestIds', requestIds);
  175. },
  176. /**
  177. * Load data for all steps until <code>current step</code>
  178. */
  179. loadAllPriorSteps: function () {
  180. var step = this.get('currentStep');
  181. switch (step) {
  182. case '9':
  183. case '8':
  184. case '7':
  185. case '6':
  186. case '5':
  187. this.loadTasksStatuses();
  188. this.loadTasksRequestIds();
  189. this.loadRequestIds();
  190. case '4':
  191. case '3':
  192. this.loadNameServiceId();
  193. this.loadServiceConfigProperties();
  194. case '2':
  195. this.loadServicesFromServer();
  196. this.loadMasterComponentHosts();
  197. this.loadConfirmedHosts();
  198. this.loadHdfsUser();
  199. case '1':
  200. this.load('cluster');
  201. }
  202. },
  203. /**
  204. * Remove all loaded data.
  205. * Created as copy for App.router.clearAllSteps
  206. */
  207. clearAllSteps: function () {
  208. this.clearInstallOptions();
  209. // clear temporary information stored during the install
  210. this.set('content.cluster', this.getCluster());
  211. },
  212. clearTasksData: function () {
  213. this.saveTasksStatuses(undefined);
  214. this.saveRequestIds(undefined);
  215. this.saveTasksRequestIds(undefined);
  216. },
  217. /**
  218. * Clear all temporary data
  219. */
  220. finish: function () {
  221. App.db.data.Installer = {};
  222. this.resetDbNamespace();
  223. App.router.get('updateController').updateAll();
  224. }
  225. });