wizard_controller.js 7.8 KB

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