wizard_controller.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. var componentsUtils = require('utils/components');
  20. App.KerberosWizardController = App.WizardController.extend({
  21. exceptionsOnSkipClient: [{'KDC': 'realm'}, {'KDC': 'kdc_type'}, {'Advanced kerberos-env': 'executable_search_paths'}],
  22. name: 'kerberosWizardController',
  23. totalSteps: 8,
  24. isKerberosWizard: true,
  25. stackConfigsLoaded: false,
  26. /**
  27. * Used for hiding back button in wizard
  28. */
  29. hideBackButton: true,
  30. skipClientInstall: false,
  31. kerberosDescriptorConfigs: null,
  32. content: Em.Object.create({
  33. controllerName: 'kerberosWizardController',
  34. serviceName: 'KERBEROS',
  35. kerberosOption: null,
  36. cluster: null,
  37. services: [],
  38. advancedServiceConfig: null,
  39. serviceConfigProperties: [],
  40. failedTask: null
  41. }),
  42. /**
  43. * set current step
  44. * @param {string} currentStep
  45. * @param {boolean} completed
  46. * @param {boolean} skipStateSave
  47. */
  48. setCurrentStep: function (currentStep, completed, skipStateSave) {
  49. this._super(currentStep, completed);
  50. if (App.get('testMode') || skipStateSave) {
  51. return;
  52. }
  53. App.clusterStatus.setClusterStatus({
  54. clusterName: this.get('content.cluster.name'),
  55. clusterState: 'KERBEROS_DEPLOY',
  56. wizardControllerName: 'kerberosWizardController',
  57. localdb: App.db.data
  58. });
  59. },
  60. setStepsEnable: function () {
  61. for (var i = 1; i <= this.get('totalSteps'); i++) {
  62. var step = this.get('isStepDisabled').findProperty('step', i);
  63. if (i <= this.get('currentStep') && App.get('router.clusterController.isLoaded')) {
  64. step.set('value', false);
  65. } else {
  66. step.set('value', i != this.get('currentStep'));
  67. }
  68. }
  69. }.observes('currentStep', 'App.router.clusterController.isLoaded'),
  70. /**
  71. * return new object extended from clusterStatusTemplate
  72. * @return Object
  73. */
  74. getCluster: function () {
  75. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.get('router').getClusterName()});
  76. },
  77. /**
  78. * Gets the
  79. * @returns {*} jquery promise
  80. */
  81. getClusterEnvData: function () {
  82. var dfd = $.Deferred();
  83. var self = this;
  84. var siteName = 'cluster-env';
  85. var tags = [{siteName: siteName}];
  86. App.get('router.configurationController').getConfigsByTags(tags).done(function (data) {
  87. var properties = self.updateClusterEnvData(data[0].properties);
  88. var clusterConfig = {"type": siteName, "tag": 'version' + (new Date).getTime(), "properties": properties};
  89. var clusterConfigData = {
  90. Clusters: {
  91. desired_config: clusterConfig
  92. }
  93. };
  94. dfd.resolve(clusterConfigData);
  95. });
  96. return dfd;
  97. },
  98. updateClusterEnvData: function (configs) {
  99. var kerberosDescriptor = this.kerberosDescriptorConfigs;
  100. configs['security_enabled'] = true;
  101. configs['kerberos_domain'] = kerberosDescriptor.properties.realm;
  102. return configs;
  103. },
  104. /**
  105. * save status of the cluster.
  106. * @param clusterStatus object with status,requestId fields.
  107. */
  108. saveClusterStatus: function (clusterStatus) {
  109. var oldStatus = this.toObject(this.get('content.cluster'));
  110. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  111. if (clusterStatus.requestId) {
  112. clusterStatus.requestId.forEach(function (requestId) {
  113. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  114. clusterStatus.oldRequestsId.push(requestId)
  115. }
  116. }, this);
  117. }
  118. this.set('content.cluster', clusterStatus);
  119. this.save('cluster');
  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. /**
  130. * Load serviceConfigProperties to model
  131. */
  132. loadServiceConfigProperties: function () {
  133. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  134. this.set('content.serviceConfigProperties', serviceConfigProperties);
  135. },
  136. loadKerberosDescriptorConfigs: function () {
  137. var kerberosDescriptorConfigs = this.getDBProperty('kerberosDescriptorConfigs');
  138. this.set('kerberosDescriptorConfigs', kerberosDescriptorConfigs);
  139. },
  140. /**
  141. * Override the visibility of a list of form items with a new value
  142. *
  143. * @param {Array} itemsArray
  144. * @param newValue
  145. */
  146. overrideVisibility: function (itemsArray, newValue, exceptions) {
  147. newValue = newValue || false;
  148. for (var i = 0, len = itemsArray.length; i < len; i += 1) {
  149. if (!Ember.$.isEmptyObject(itemsArray[i])) {
  150. var isException = exceptions.filterProperty(itemsArray[i].category, itemsArray[i].name);
  151. if (!isException.length) {
  152. itemsArray[i].isVisible = newValue;
  153. }
  154. }
  155. }
  156. },
  157. loadKerberosOption: function () {
  158. this.set('content.kerberosOption', this.getDBProperty('kerberosOption'));
  159. },
  160. saveKerberosDescriptorConfigs: function (kerberosDescriptorConfigs) {
  161. this.setDBProperty('kerberosDescriptorConfigs',kerberosDescriptorConfigs);
  162. this.set('kerberosDescriptorConfigs', kerberosDescriptorConfigs);
  163. },
  164. createKerberosResources: function (callback) {
  165. var self = this;
  166. this.createKerberosService().done(function () {
  167. componentsUtils.createServiceComponent('KERBEROS_CLIENT').done(function () {
  168. self.createKerberosHostComponents().done(callback);
  169. });
  170. });
  171. },
  172. createKerberosService: function () {
  173. return App.ajax.send({
  174. name: 'wizard.step8.create_selected_services',
  175. sender: this,
  176. data: {
  177. data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
  178. cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
  179. }
  180. });
  181. },
  182. createKerberosHostComponents: function () {
  183. var hostNames = App.get('allHostNames');
  184. var queryStr = '';
  185. hostNames.forEach(function (hostName) {
  186. queryStr += 'Hosts/host_name=' + hostName + '|';
  187. });
  188. //slice off last symbol '|'
  189. queryStr = queryStr.slice(0, -1);
  190. var data = {
  191. "RequestInfo": {
  192. "query": queryStr
  193. },
  194. "Body": {
  195. "host_components": [
  196. {
  197. "HostRoles": {
  198. "component_name": 'KERBEROS_CLIENT'
  199. }
  200. }
  201. ]
  202. }
  203. };
  204. return App.ajax.send({
  205. name: 'wizard.step8.register_host_to_component',
  206. sender: this,
  207. data: {
  208. cluster: App.router.getClusterName(),
  209. data: JSON.stringify(data)
  210. }
  211. });
  212. },
  213. loadMap: {
  214. '1': [
  215. {
  216. type: 'sync',
  217. callback: function () {
  218. this.loadKerberosOption();
  219. }
  220. }
  221. ],
  222. '2': [
  223. {
  224. type: 'sync',
  225. callback: function () {
  226. var self = this;
  227. this.loadServiceConfigProperties();
  228. if (!this.get('stackConfigsLoaded')) {
  229. App.config.loadConfigsFromStack(['KERBEROS']).complete(function() {
  230. self.set('stackConfigsLoaded', true);
  231. }, this);
  232. }
  233. }
  234. }
  235. ],
  236. '3': [
  237. {
  238. type: 'sync',
  239. callback: function () {
  240. this.loadTasksStatuses();
  241. this.loadTasksRequestIds();
  242. this.loadRequestIds();
  243. }
  244. }
  245. ],
  246. '4': [
  247. {
  248. type: 'sync',
  249. callback: function () {
  250. this.loadKerberosDescriptorConfigs();
  251. }
  252. }
  253. ],
  254. '6': [
  255. {
  256. type: 'sync',
  257. callback: function () {
  258. this.loadKerberosDescriptorConfigs();
  259. }
  260. }
  261. ]
  262. },
  263. /**
  264. * Remove all loaded data.
  265. * Created as copy for App.router.clearAllSteps
  266. */
  267. clearAllSteps: function () {
  268. this.clearInstallOptions();
  269. // clear temporary information stored during the install
  270. this.set('content.cluster', this.getCluster());
  271. },
  272. clearTasksData: function () {
  273. this.saveTasksStatuses(undefined);
  274. this.saveRequestIds(undefined);
  275. this.saveTasksRequestIds(undefined);
  276. },
  277. /**
  278. * shows popup with to warn user
  279. * @param primary
  280. * @param isCritical
  281. */
  282. warnBeforeExitPopup: function(primary, isCritical) {
  283. var primaryText = Em.I18n.t('common.exitAnyway');
  284. var msg = isCritical ? Em.I18n.t('admin.kerberos.wizard.exit.critical.msg')
  285. : Em.I18n.t('admin.kerberos.wizard.exit.warning.msg');
  286. return App.showConfirmationPopup(primary, msg, null, null, primaryText, isCritical);
  287. },
  288. /**
  289. * Clear all temporary data
  290. */
  291. finish: function () {
  292. // The in-memory variable for current step should be reset to 1st step.
  293. this.setCurrentStep('1', false, true);
  294. // kerberos wizard namespace in the localStorage should be emptied
  295. this.resetDbNamespace();
  296. App.get('router.updateController').updateAll();
  297. }
  298. });