step2_controller.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. require('controllers/wizard/step7_controller');
  20. App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend({
  21. name: "kerberosWizardStep2Controller",
  22. isKerberosWizard: true,
  23. selectedServiceNames: ['KERBEROS'],
  24. allSelectedServiceNames: ['KERBEROS'],
  25. componentName: 'KERBEROS_CLIENT',
  26. installedServiceNames: [],
  27. servicesInstalled: false,
  28. addMiscTabToPage: false,
  29. /**
  30. * @type {boolean} true if test connection to hosts is in progress
  31. */
  32. testConnectionInProgress: false,
  33. /**
  34. * Should Back-button be disabled
  35. * @type {boolean}
  36. */
  37. isBackBtnDisabled: function() {
  38. return this.get('testConnectionInProgress');
  39. }.property('testConnectionInProgress'),
  40. /**
  41. * Should Next-button be disabled
  42. * @type {boolean}
  43. */
  44. isSubmitDisabled: function () {
  45. if (!this.get('stepConfigs.length') || this.get('testConnectionInProgress') || this.get('submitButtonClicked')) return true;
  46. return (!this.get('stepConfigs').filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  47. }.property('stepConfigs.@each.errorCount', 'miscModalVisible', 'submitButtonClicked', 'testConnectionInProgress'),
  48. hostNames: function () {
  49. return App.get('allHostNames');
  50. }.property('App.allHostNames'),
  51. serviceConfigTags: [],
  52. clearStep: function () {
  53. this._super();
  54. this.set('configs', []);
  55. this.get('serviceConfigTags').clear();
  56. this.set('servicesInstalled', false);
  57. },
  58. isConfigsLoaded: function () {
  59. return this.get('wizardController.stackConfigsLoaded');
  60. }.property('wizardController.stackConfigsLoaded'),
  61. /**
  62. * On load function
  63. * @method loadStep
  64. */
  65. loadStep: function () {
  66. console.log("TRACE: Loading step2: Configure Kerberos");
  67. if (!App.StackService.find().someProperty('serviceName', 'KERBEROS') || !this.get('isConfigsLoaded')) {
  68. return;
  69. }
  70. this.clearStep();
  71. //STEP 2: Load on-site configs by service from local DB
  72. var storedConfigs = this.get('content.serviceConfigProperties');
  73. //STEP 3: Merge pre-defined configs with loaded on-site configs
  74. this.set('configs', App.config.mergePreDefinedWithStack(this.get('selectedServiceNames')));
  75. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  76. this.filterConfigs(this.get('configs'));
  77. this.applyServicesConfigs(this.get('configs'), storedConfigs);
  78. },
  79. /**
  80. * Make Active Directory specific configs visible if user has selected AD option
  81. * @param configs
  82. */
  83. filterConfigs: function (configs) {
  84. var kdcType = this.get('content.kerberosOption');
  85. var configNames = ['ldap_url', 'container_dn', 'create_attributes_template'];
  86. var kerberosWizardController = this.controllers.get('kerberosWizardController');
  87. var manageIdentitiesConfig = configs.findProperty('name', 'manage_identities');
  88. if (kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.manual')) {
  89. if (kerberosWizardController.get('skipClientInstall')) {
  90. kerberosWizardController.overrideVisibility(configs, false, kerberosWizardController.get('exceptionsOnSkipClient'));
  91. }
  92. return;
  93. } else if (manageIdentitiesConfig) {
  94. manageIdentitiesConfig.isVisible = false;
  95. manageIdentitiesConfig.value = 'true';
  96. }
  97. configNames.forEach(function (_configName) {
  98. var config = configs.findProperty('name', _configName);
  99. if (config) {
  100. config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.ad');
  101. }
  102. }, this);
  103. },
  104. submit: function () {
  105. if (this.get('isSubmitDisabled')) return false;
  106. this.set('isSubmitDisabled', true);
  107. var self = this;
  108. this.deleteKerberosService().always(function (data) {
  109. self.configureKerberos();
  110. });
  111. },
  112. configureKerberos: function () {
  113. var self = this;
  114. var wizardController = App.router.get(this.get('content.controllerName'));
  115. var callback = function () {
  116. self.createConfigurations().done(function () {
  117. self.createKerberosAdminSession().done(function () {
  118. App.router.send('next');
  119. });
  120. });
  121. };
  122. if (wizardController.get('skipClientInstall')) {
  123. callback();
  124. } else {
  125. wizardController.createKerberosResources(callback);
  126. }
  127. },
  128. /**
  129. * Delete Kerberos service if it exists
  130. */
  131. deleteKerberosService: function () {
  132. var serviceName = this.selectedServiceNames[0];
  133. return App.ajax.send({
  134. name: 'common.delete.service',
  135. sender: this,
  136. data: {
  137. serviceName: serviceName
  138. }
  139. });
  140. },
  141. createConfigurations: function () {
  142. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  143. var serviceConfigTags = [];
  144. var tag = 'version' + (new Date).getTime();
  145. Object.keys(service.get('configTypes')).forEach(function (type) {
  146. if (!serviceConfigTags.someProperty('type', type)) {
  147. var obj = this.createKerberosSiteObj(type, tag);
  148. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  149. serviceConfigTags.pushObject(obj);
  150. }
  151. }, this);
  152. var allConfigData = [];
  153. var serviceConfigData = [];
  154. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  155. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  156. if (serviceConfigTag) {
  157. serviceConfigData.pushObject(serviceConfigTag);
  158. }
  159. }, this);
  160. if (serviceConfigData.length) {
  161. allConfigData.pushObject(JSON.stringify({
  162. Clusters: {
  163. desired_config: serviceConfigData
  164. }
  165. }));
  166. }
  167. return App.ajax.send({
  168. name: 'common.across.services.configurations',
  169. sender: this,
  170. data: {
  171. data: '[' + allConfigData.toString() + ']'
  172. }
  173. });
  174. },
  175. createKerberosSiteObj: function (site, tag) {
  176. var properties = {};
  177. var content = this.get('stepConfigs')[0].get('configs');
  178. var configs = content.filterProperty('filename', site + '.xml');
  179. configs.forEach(function (_configProperty) {
  180. // do not pass any globals whose name ends with _host or _hosts
  181. if (_configProperty.isRequiredByAgent !== false) {
  182. properties[_configProperty.name] = _configProperty.value;
  183. }
  184. }, this);
  185. this.tweakKdcTypeValue(properties);
  186. this.tweakManualKdcProperties(properties);
  187. return {"type": site, "tag": tag, "properties": properties};
  188. },
  189. tweakKdcTypeValue: function (properties) {
  190. for (var prop in App.router.get('mainAdminKerberosController.kdcTypesValues')) {
  191. if (App.router.get('mainAdminKerberosController.kdcTypesValues').hasOwnProperty(prop)) {
  192. if (App.router.get('mainAdminKerberosController.kdcTypesValues')[prop] === properties['kdc_type']) {
  193. properties['kdc_type'] = prop;
  194. }
  195. }
  196. }
  197. },
  198. tweakManualKdcProperties: function (properties) {
  199. var kerberosWizardController = this.controllers.get('kerberosWizardController');
  200. if (properties['kdc_type'] === 'none' || kerberosWizardController.get('skipClientInstall')) {
  201. if (properties.hasOwnProperty('manage_identities')) {
  202. properties['manage_identities'] = 'false';
  203. }
  204. if (properties.hasOwnProperty('install_packages')) {
  205. properties['install_packages'] = 'false';
  206. }
  207. if (properties.hasOwnProperty('manage_krb5_conf')) {
  208. properties['manage_krb5_conf'] = 'false';
  209. }
  210. }
  211. },
  212. /**
  213. * puts kerberos admin credentials in the live cluster session
  214. * @returns {*} jqXHr
  215. */
  216. createKerberosAdminSession: function (configs) {
  217. configs = configs || this.get('stepConfigs')[0].get('configs');
  218. var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
  219. var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
  220. return App.ajax.send({
  221. name: 'common.cluster.update',
  222. sender: this,
  223. data: {
  224. clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
  225. data: [{
  226. session_attributes: {
  227. kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
  228. }
  229. }]
  230. }
  231. });
  232. },
  233. /**
  234. * shows popup with to warn user
  235. * @param primary
  236. */
  237. showConnectionInProgressPopup: function(primary) {
  238. var primaryText = Em.I18n.t('common.exitAnyway');
  239. var msg = Em.I18n.t('services.service.config.connection.exitPopup.msg');
  240. App.showConfirmationPopup(primary, msg, null, null, primaryText)
  241. }
  242. });