wizard_controller.js 8.7 KB

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