wizard_controller.js 9.9 KB

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