step2_controller.js 10 KB

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