step2_controller.js 9.4 KB

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