wizard_controller.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.KerberosWizardController = App.WizardController.extend({
  20. name: 'kerberosWizardController',
  21. totalSteps: 7,
  22. isKerberosWizard: true,
  23. /**
  24. * Used for hiding back button in wizard
  25. */
  26. hideBackButton: true,
  27. content: Em.Object.create({
  28. controllerName: 'kerberosWizardController',
  29. serviceName: 'KERBEROS',
  30. hosts: '',
  31. kerberosOption: null,
  32. cluster: null,
  33. services: [],
  34. advancedServiceConfig: null,
  35. serviceConfigProperties: [],
  36. kerberosDescriptorConfigs: null,
  37. failedTask: null
  38. }),
  39. setCurrentStep: function (currentStep, completed) {
  40. this._super(currentStep, completed);
  41. if (App.testMode) {
  42. return;
  43. }
  44. App.clusterStatus.setClusterStatus({
  45. clusterName: this.get('content.cluster.name'),
  46. clusterState: 'KERBEROS_DEPLOY',
  47. wizardControllerName: 'kerberosWizardController',
  48. localdb: App.db.data
  49. });
  50. },
  51. /**
  52. * return new object extended from clusterStatusTemplate
  53. * @return Object
  54. */
  55. getCluster: function () {
  56. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  57. },
  58. /**
  59. * Gets the
  60. * @returns {*} jquery promise
  61. */
  62. getClusterEnvData: function () {
  63. var dfd = $.Deferred();
  64. var self = this;
  65. var siteName = 'cluster-env';
  66. var tags = [{siteName: siteName}];
  67. App.router.get('configurationController').getConfigsByTags(tags).done(function (data) {
  68. var properties = self.updateClusterEnvData(data[0].properties);
  69. var clusterConfig = {"type": siteName, "tag": 'version' + (new Date).getTime(), "properties": properties};
  70. var clusterConfigData = {
  71. Clusters: {
  72. desired_config: clusterConfig
  73. }
  74. };
  75. dfd.resolve(clusterConfigData);
  76. });
  77. return dfd;
  78. },
  79. updateClusterEnvData: function (configs) {
  80. var kerberosDescriptor = this.get('content.kerberosDescriptorConfigs');
  81. configs['security_enabled'] = true;
  82. configs['kerberos_domain'] = kerberosDescriptor.properties.realm;
  83. return configs;
  84. },
  85. /**
  86. * save status of the cluster.
  87. * @param clusterStatus object with status,requestId fields.
  88. */
  89. saveClusterStatus: function (clusterStatus) {
  90. var oldStatus = this.toObject(this.get('content.cluster'));
  91. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  92. if (clusterStatus.requestId) {
  93. clusterStatus.requestId.forEach(function (requestId) {
  94. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  95. clusterStatus.oldRequestsId.push(requestId)
  96. }
  97. }, this);
  98. }
  99. this.set('content.cluster', clusterStatus);
  100. this.save('cluster');
  101. },
  102. saveTasksStatuses: function (statuses) {
  103. this.setDBProperty('tasksStatuses',statuses);
  104. this.set('content.tasksStatuses', statuses);
  105. },
  106. saveConfigTag: function (tag) {
  107. App.db.setKerberosWizardConfigTag(tag);
  108. this.set('content.' + [tag.name], tag.value);
  109. },
  110. saveKerberosOption: function (stepController) {
  111. this.setDBProperty('kerberosOption', stepController.get('selectedItem'));
  112. this.set('content.kerberosOption', stepController.get('selectedItem'));
  113. },
  114. loadConfigTag: function (tag) {
  115. var tagVal = App.db.getKerberosWizardConfigTag(tag);
  116. this.set('content.' + tag, tagVal);
  117. },
  118. loadTasksStatuses: function () {
  119. var statuses = this.getDBProperty('tasksStatuses');
  120. this.set('content.tasksStatuses', statuses);
  121. },
  122. /**
  123. * Load serviceConfigProperties to model
  124. */
  125. loadServiceConfigProperties: function () {
  126. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  127. this.set('content.serviceConfigProperties', serviceConfigProperties);
  128. },
  129. /**
  130. * load advanced configs from server
  131. */
  132. loadAdvancedConfigs: function (dependentController) {
  133. var self = this;
  134. var loadAdvancedConfigResult = [];
  135. dependentController.set('isAdvancedConfigLoaded', false);
  136. var serviceName = this.get('content.serviceName');
  137. App.config.loadAdvancedConfig(serviceName, function (properties) {
  138. loadAdvancedConfigResult.pushObjects(properties);
  139. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  140. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  141. dependentController.set('isAdvancedConfigLoaded', true);
  142. });
  143. },
  144. loadKerberosDescriptorConfigs: function () {
  145. var kerberosDescriptorConfigs = this.getDBProperty('kerberosDescriptorConfigs');
  146. this.set('content.kerberosDescriptorConfigs', kerberosDescriptorConfigs);
  147. },
  148. saveRequestIds: function (requestIds) {
  149. this.setDBProperty('requestIds',requestIds);
  150. this.set('content.requestIds', requestIds);
  151. },
  152. loadKerberosOption: function () {
  153. this.set('content.kerberosOption', this.getDBProperty('kerberosOption'));
  154. },
  155. loadRequestIds: function () {
  156. var requestIds = this.getDBProperty('requestIds');
  157. this.set('content.requestIds', requestIds);
  158. },
  159. saveTasksRequestIds: function (requestIds) {
  160. this.setDBProperty('tasksRequestIds',requestIds);
  161. this.set('content.tasksRequestIds', requestIds);
  162. },
  163. loadTasksRequestIds: function () {
  164. var requestIds = this.getDBProperty('tasksRequestIds');
  165. this.set('content.tasksRequestIds', requestIds);
  166. },
  167. saveKerberosDescriptorConfigs: function (kerberosDescriptorConfigs) {
  168. this.setDBProperty('kerberosDescriptorConfigs',kerberosDescriptorConfigs);
  169. this.set('content.kerberosDescriptorConfigs', kerberosDescriptorConfigs);
  170. },
  171. loadMap: {
  172. '1': [
  173. {
  174. type: 'sync',
  175. callback: function () {
  176. this.loadKerberosOption();
  177. }
  178. }
  179. ],
  180. '2': [
  181. {
  182. type: 'sync',
  183. callback: function () {
  184. var kerberosStep2controller = App.router.get('kerberosWizardStep2Controller');
  185. this.loadAdvancedConfigs(kerberosStep2controller);
  186. this.loadServiceConfigProperties();
  187. this.load('hosts');
  188. }
  189. }
  190. ],
  191. '3': [
  192. {
  193. type: 'sync',
  194. callback: function () {
  195. this.loadTasksStatuses();
  196. this.loadTasksRequestIds();
  197. this.loadRequestIds();
  198. }
  199. }
  200. ],
  201. '4': [
  202. {
  203. type: 'sync',
  204. callback: function () {
  205. this.loadKerberosDescriptorConfigs();
  206. }
  207. }
  208. ],
  209. '5': [
  210. {
  211. type: 'sync',
  212. callback: function () {
  213. this.loadKerberosDescriptorConfigs();
  214. }
  215. }
  216. ]
  217. },
  218. /**
  219. * Remove all loaded data.
  220. * Created as copy for App.router.clearAllSteps
  221. */
  222. clearAllSteps: function () {
  223. this.clearInstallOptions();
  224. // clear temporary information stored during the install
  225. this.set('content.cluster', this.getCluster());
  226. },
  227. clearTasksData: function () {
  228. this.saveTasksStatuses(undefined);
  229. this.saveRequestIds(undefined);
  230. this.saveTasksRequestIds(undefined);
  231. },
  232. /**
  233. * Clear all temporary data
  234. */
  235. finish: function () {
  236. // The in-memory variable for currentstep should be reset to 1st step.
  237. this.setCurrentStep('1');
  238. // kerberos wizard namespace in the localStorage should be emptied
  239. this.resetDbNamespace();
  240. App.router.get('updateController').updateAll();
  241. }
  242. });