wizard_controller.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. hosts: '',
  32. kerberosOption: null,
  33. cluster: null,
  34. services: [],
  35. advancedServiceConfig: null,
  36. serviceConfigProperties: [],
  37. failedTask: null
  38. }),
  39. setCurrentStep: function (currentStep, completed) {
  40. this._super(currentStep, completed);
  41. if (App.get('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. setStepsEnable: function () {
  52. for (var i = 1; i <= this.get('totalSteps'); i++) {
  53. var step = this.get('isStepDisabled').findProperty('step', i);
  54. if (i <= this.get('currentStep') && App.get('router.clusterController.isLoaded')) {
  55. step.set('value', false);
  56. } else {
  57. step.set('value', i != this.get('currentStep'));
  58. }
  59. }
  60. }.observes('currentStep', 'App.router.clusterController.isLoaded'),
  61. /**
  62. * return new object extended from clusterStatusTemplate
  63. * @return Object
  64. */
  65. getCluster: function () {
  66. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.get('router').getClusterName()});
  67. },
  68. /**
  69. * Gets the
  70. * @returns {*} jquery promise
  71. */
  72. getClusterEnvData: function () {
  73. var dfd = $.Deferred();
  74. var self = this;
  75. var siteName = 'cluster-env';
  76. var tags = [{siteName: siteName}];
  77. App.get('router.configurationController').getConfigsByTags(tags).done(function (data) {
  78. var properties = self.updateClusterEnvData(data[0].properties);
  79. var clusterConfig = {"type": siteName, "tag": 'version' + (new Date).getTime(), "properties": properties};
  80. var clusterConfigData = {
  81. Clusters: {
  82. desired_config: clusterConfig
  83. }
  84. };
  85. dfd.resolve(clusterConfigData);
  86. });
  87. return dfd;
  88. },
  89. updateClusterEnvData: function (configs) {
  90. var kerberosDescriptor = this.kerberosDescriptorConfigs;
  91. configs['security_enabled'] = true;
  92. configs['kerberos_domain'] = kerberosDescriptor.properties.realm;
  93. return configs;
  94. },
  95. /**
  96. * save status of the cluster.
  97. * @param clusterStatus object with status,requestId fields.
  98. */
  99. saveClusterStatus: function (clusterStatus) {
  100. var oldStatus = this.toObject(this.get('content.cluster'));
  101. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  102. if (clusterStatus.requestId) {
  103. clusterStatus.requestId.forEach(function (requestId) {
  104. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  105. clusterStatus.oldRequestsId.push(requestId)
  106. }
  107. }, this);
  108. }
  109. this.set('content.cluster', clusterStatus);
  110. this.save('cluster');
  111. },
  112. saveTasksStatuses: function (statuses) {
  113. this.setDBProperty('tasksStatuses',statuses);
  114. this.set('content.tasksStatuses', statuses);
  115. },
  116. saveConfigTag: function (tag) {
  117. App.db.setKerberosWizardConfigTag(tag);
  118. this.set('content.' + [tag.name], tag.value);
  119. },
  120. saveKerberosOption: function (stepController) {
  121. this.setDBProperty('kerberosOption', stepController.get('selectedItem'));
  122. this.set('content.kerberosOption', stepController.get('selectedItem'));
  123. },
  124. loadConfigTag: function (tag) {
  125. var tagVal = App.db.getKerberosWizardConfigTag(tag);
  126. this.set('content.' + tag, tagVal);
  127. },
  128. loadTasksStatuses: function () {
  129. var statuses = this.getDBProperty('tasksStatuses');
  130. this.set('content.tasksStatuses', statuses);
  131. },
  132. /**
  133. * Load serviceConfigProperties to model
  134. */
  135. loadServiceConfigProperties: function () {
  136. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  137. this.set('content.serviceConfigProperties', serviceConfigProperties);
  138. },
  139. /**
  140. * load advanced configs from server
  141. */
  142. loadAdvancedConfigs: function (dependentController) {
  143. var self = this;
  144. var loadAdvancedConfigResult = [];
  145. dependentController.set('isAdvancedConfigLoaded', false);
  146. var serviceName = this.get('content.serviceName');
  147. App.config.loadAdvancedConfig(serviceName, function (properties) {
  148. loadAdvancedConfigResult.pushObjects(properties);
  149. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  150. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  151. dependentController.set('isAdvancedConfigLoaded', true);
  152. });
  153. },
  154. loadKerberosDescriptorConfigs: function () {
  155. var kerberosDescriptorConfigs = this.getDBProperty('kerberosDescriptorConfigs');
  156. this.kerberosDescriptorConfigs = kerberosDescriptorConfigs;
  157. },
  158. saveRequestIds: function (requestIds) {
  159. this.setDBProperty('requestIds',requestIds);
  160. this.set('content.requestIds', requestIds);
  161. },
  162. loadKerberosOption: function () {
  163. this.set('content.kerberosOption', this.getDBProperty('kerberosOption'));
  164. },
  165. loadRequestIds: function () {
  166. var requestIds = this.getDBProperty('requestIds');
  167. this.set('content.requestIds', requestIds);
  168. },
  169. saveTasksRequestIds: function (requestIds) {
  170. this.setDBProperty('tasksRequestIds',requestIds);
  171. this.set('content.tasksRequestIds', requestIds);
  172. },
  173. loadTasksRequestIds: function () {
  174. var requestIds = this.getDBProperty('tasksRequestIds');
  175. this.set('content.tasksRequestIds', requestIds);
  176. },
  177. saveKerberosDescriptorConfigs: function (kerberosDescriptorConfigs) {
  178. this.setDBProperty('kerberosDescriptorConfigs',kerberosDescriptorConfigs);
  179. this.kerberosDescriptorConfigs = kerberosDescriptorConfigs;
  180. },
  181. loadMap: {
  182. '1': [
  183. {
  184. type: 'sync',
  185. callback: function () {
  186. this.loadKerberosOption();
  187. }
  188. }
  189. ],
  190. '2': [
  191. {
  192. type: 'sync',
  193. callback: function () {
  194. var kerberosStep2controller = App.get('router.kerberosWizardStep2Controller');
  195. this.loadAdvancedConfigs(kerberosStep2controller);
  196. this.loadServiceConfigProperties();
  197. this.load('hosts');
  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 currentstep should be reset to 1st step.
  258. this.setCurrentStep('1');
  259. // kerberos wizard namespace in the localStorage should be emptied
  260. this.resetDbNamespace();
  261. App.get('router.updateController').updateAll();
  262. }
  263. });