step2_controller.js 11 KB

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