step2_controller.js 10 KB

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