step2_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.createKerberosResources();
  115. });
  116. },
  117. createKerberosResources: function () {
  118. var self = this;
  119. this.createKerberosService().done(function () {
  120. componentsUtils.createServiceComponent('KERBEROS_CLIENT').done(function () {
  121. self.createKerberosHostComponents().done(function () {
  122. self.createConfigurations().done(function () {
  123. self.createKerberosAdminSession().done(function () {
  124. App.router.send('next');
  125. });
  126. });
  127. });
  128. });
  129. });
  130. },
  131. /**
  132. * Delete Kerberos service if it exists
  133. */
  134. deleteKerberosService: function () {
  135. var serviceName = this.selectedServiceNames[0];
  136. return App.ajax.send({
  137. name: 'common.delete.service',
  138. sender: this,
  139. data: {
  140. serviceName: serviceName
  141. }
  142. });
  143. },
  144. createKerberosService: function () {
  145. return App.ajax.send({
  146. name: 'wizard.step8.create_selected_services',
  147. sender: this,
  148. data: {
  149. data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
  150. cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
  151. }
  152. });
  153. },
  154. createKerberosHostComponents: function () {
  155. var hostNames = this.get('hostNames');
  156. var queryStr = '';
  157. hostNames.forEach(function (hostName) {
  158. queryStr += 'Hosts/host_name=' + hostName + '|';
  159. });
  160. //slice off last symbol '|'
  161. queryStr = queryStr.slice(0, -1);
  162. var data = {
  163. "RequestInfo": {
  164. "query": queryStr
  165. },
  166. "Body": {
  167. "host_components": [
  168. {
  169. "HostRoles": {
  170. "component_name": this.componentName
  171. }
  172. }
  173. ]
  174. }
  175. };
  176. return App.ajax.send({
  177. name: 'wizard.step8.register_host_to_component',
  178. sender: this,
  179. data: {
  180. cluster: App.router.getClusterName(),
  181. data: JSON.stringify(data)
  182. }
  183. });
  184. },
  185. createConfigurations: function () {
  186. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  187. var serviceConfigTags = [];
  188. var tag = 'version' + (new Date).getTime();
  189. Object.keys(service.get('configTypes')).forEach(function (type) {
  190. if (!serviceConfigTags.someProperty('type', type)) {
  191. var obj = this.createKerberosSiteObj(type, tag);
  192. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  193. serviceConfigTags.pushObject(obj);
  194. }
  195. }, this);
  196. var allConfigData = [];
  197. var serviceConfigData = [];
  198. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  199. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  200. if (serviceConfigTag) {
  201. serviceConfigData.pushObject(serviceConfigTag);
  202. }
  203. }, this);
  204. if (serviceConfigData.length) {
  205. allConfigData.pushObject(JSON.stringify({
  206. Clusters: {
  207. desired_config: serviceConfigData
  208. }
  209. }));
  210. }
  211. return App.ajax.send({
  212. name: 'common.across.services.configurations',
  213. sender: this,
  214. data: {
  215. data: '[' + allConfigData.toString() + ']'
  216. }
  217. });
  218. },
  219. createKerberosSiteObj: function (site, tag) {
  220. var properties = {};
  221. var content = this.get('stepConfigs')[0].get('configs');
  222. var configs = content.filterProperty('filename', site + '.xml');
  223. configs.forEach(function (_configProperty) {
  224. // do not pass any globals whose name ends with _host or _hosts
  225. if (_configProperty.isRequiredByAgent !== false) {
  226. properties[_configProperty.name] = _configProperty.value;
  227. }
  228. }, this);
  229. this.tweakKdcTypeValue(properties);
  230. this.tweakManualKdcProperties(properties);
  231. return {"type": site, "tag": tag, "properties": properties};
  232. },
  233. tweakKdcTypeValue: function (properties) {
  234. for (var prop in App.router.get('mainAdminKerberosController.kdcTypesValues')) {
  235. if (App.router.get('mainAdminKerberosController.kdcTypesValues').hasOwnProperty(prop)) {
  236. if (App.router.get('mainAdminKerberosController.kdcTypesValues')[prop] === properties['kdc_type']) {
  237. properties['kdc_type'] = prop;
  238. }
  239. }
  240. }
  241. },
  242. tweakManualKdcProperties: function (properties) {
  243. var kerberosWizardController = this.controllers.get('kerberosWizardController');
  244. if (properties['kdc_type'] === 'none' || kerberosWizardController.get('skipClientInstall')) {
  245. if (properties.hasOwnProperty('manage_identities')) {
  246. properties['manage_identities'] = 'false';
  247. }
  248. if (properties.hasOwnProperty('install_packages')) {
  249. properties['install_packages'] = 'false';
  250. }
  251. if (properties.hasOwnProperty('manage_krb5_conf')) {
  252. properties['manage_krb5_conf'] = 'false';
  253. }
  254. }
  255. },
  256. /**
  257. * puts kerberos admin credentials in the live cluster session
  258. * @returns {*} jqXHr
  259. */
  260. createKerberosAdminSession: function (configs) {
  261. configs = configs || this.get('stepConfigs')[0].get('configs');
  262. var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
  263. var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
  264. return App.ajax.send({
  265. name: 'common.cluster.update',
  266. sender: this,
  267. data: {
  268. clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
  269. data: [{
  270. session_attributes: {
  271. kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
  272. }
  273. }]
  274. }
  275. });
  276. },
  277. /**
  278. * shows popup with to warn user
  279. * @param primary
  280. */
  281. showConnectionInProgressPopup: function(primary) {
  282. var primaryText = Em.I18n.t('common.exitAnyway');
  283. var msg = Em.I18n.t('services.service.config.connection.exitPopup.msg');
  284. App.showConfirmationPopup(primary, msg, null, null, primaryText)
  285. }
  286. });