step2_controller.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 this.get('content.hosts');
  50. }.property('content.hosts'),
  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. var 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(configs, advancedConfigs);
  78. this.showAdConfigs(configs);
  79. this.applyServicesConfigs(configs, storedConfigs);
  80. },
  81. /**
  82. * Make Active Directory specific configs visible if user has selected AD option
  83. * @param configs
  84. */
  85. showAdConfigs: function (configs) {
  86. var kdcType = this.get('content.kerberosOption');
  87. var configNames = ['ldap_url', 'container_dn'];
  88. configNames.forEach(function (_configName) {
  89. var config = configs.findProperty('name', _configName);
  90. config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.ad');
  91. }, this);
  92. },
  93. submit: function () {
  94. this.set('isSubmitDisabled', true);
  95. var self = this;
  96. this.deleteKerberosService().always(function (data) {
  97. self.createKerberosResources();
  98. });
  99. },
  100. createKerberosResources: function () {
  101. var self = this;
  102. this.createKerberosService().done(function () {
  103. self.createKerberosComponent().done(function () {
  104. self.createKerberosHostComponents().done(function () {
  105. self.createConfigurations().done(function () {
  106. self.createKerberosAdminSession().done(function () {
  107. App.router.send('next');
  108. });
  109. });
  110. });
  111. });
  112. });
  113. },
  114. /**
  115. * Delete Kerberos service if it exists
  116. */
  117. deleteKerberosService: function () {
  118. var serviceName = this.selectedServiceNames[0];
  119. return App.ajax.send({
  120. name: 'common.delete.service',
  121. sender: this,
  122. data: {
  123. serviceName: serviceName
  124. }
  125. });
  126. },
  127. createKerberosService: function () {
  128. return App.ajax.send({
  129. name: 'wizard.step8.create_selected_services',
  130. sender: this,
  131. data: {
  132. data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
  133. cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
  134. }
  135. });
  136. },
  137. createKerberosComponent: function () {
  138. return App.ajax.send({
  139. name: 'common.create_component',
  140. sender: this,
  141. data: {
  142. serviceName: this.selectedServiceNames[0],
  143. componentName: this.componentName
  144. }
  145. });
  146. },
  147. createKerberosHostComponents: function () {
  148. var hostNames = this.get('content.hosts');
  149. var queryStr = '';
  150. hostNames.forEach(function (hostName) {
  151. queryStr += 'Hosts/host_name=' + hostName + '|';
  152. });
  153. //slice off last symbol '|'
  154. queryStr = queryStr.slice(0, -1);
  155. var data = {
  156. "RequestInfo": {
  157. "query": queryStr
  158. },
  159. "Body": {
  160. "host_components": [
  161. {
  162. "HostRoles": {
  163. "component_name": this.componentName
  164. }
  165. }
  166. ]
  167. }
  168. };
  169. return App.ajax.send({
  170. name: 'wizard.step8.register_host_to_component',
  171. sender: this,
  172. data: {
  173. cluster: App.router.getClusterName(),
  174. data: JSON.stringify(data)
  175. }
  176. });
  177. },
  178. createConfigurations: function () {
  179. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  180. var serviceConfigTags = [];
  181. var tag = 'version' + (new Date).getTime();
  182. Object.keys(service.get('configTypes')).forEach(function (type) {
  183. if (!serviceConfigTags.someProperty('type', type)) {
  184. var obj = this.createKerberosSiteObj(type, tag);
  185. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  186. serviceConfigTags.pushObject(obj);
  187. }
  188. }, this);
  189. var allConfigData = [];
  190. var serviceConfigData = [];
  191. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  192. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  193. if (serviceConfigTag) {
  194. serviceConfigData.pushObject(serviceConfigTag);
  195. }
  196. }, this);
  197. if (serviceConfigData.length) {
  198. allConfigData.pushObject(JSON.stringify({
  199. Clusters: {
  200. desired_config: serviceConfigData
  201. }
  202. }));
  203. }
  204. return App.ajax.send({
  205. name: 'common.across.services.configurations',
  206. sender: this,
  207. data: {
  208. data: '[' + allConfigData.toString() + ']'
  209. }
  210. });
  211. },
  212. createKerberosSiteObj: function (site, tag) {
  213. var properties = {};
  214. var content = this.get('stepConfigs')[0].get('configs');
  215. var configs = content.filterProperty('filename', site + '.xml');
  216. configs.forEach(function (_configProperty) {
  217. // do not pass any globals whose name ends with _host or _hosts
  218. if (_configProperty.isRequiredByAgent !== false) {
  219. properties[_configProperty.name] = _configProperty.value;
  220. }
  221. }, this);
  222. this.tweakKdcTypeValue(properties);
  223. return {"type": site, "tag": tag, "properties": properties};
  224. },
  225. tweakKdcTypeValue: function (properties) {
  226. if (properties['kdc_type'] === Em.I18n.t('admin.kerberos.wizard.step1.option.kdc')) {
  227. properties['kdc_type'] = "mit-kdc";
  228. } else if (properties['kdc_type'] === Em.I18n.t('admin.kerberos.wizard.step1.option.ad')) {
  229. properties['kdc_type'] = "active-directory";
  230. }
  231. },
  232. /**
  233. * puts kerberos admin credentials in the live cluster session
  234. * @returns {*} jqXHr
  235. */
  236. createKerberosAdminSession: function (configs) {
  237. configs = configs || this.get('stepConfigs')[0].get('configs');
  238. var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
  239. var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
  240. return App.ajax.send({
  241. name: 'common.cluster.update',
  242. sender: this,
  243. data: {
  244. clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
  245. data: [{
  246. session_attributes: {
  247. kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
  248. }
  249. }]
  250. }
  251. });
  252. },
  253. /**
  254. * shows popup with to warn user
  255. * @param primary
  256. */
  257. showConnectionInProgressPopup: function(primary) {
  258. var primaryText = Em.I18n.t('common.exitAnyway');
  259. var msg = Em.I18n.t('services.service.config.connection.exitPopup.msg');
  260. App.showConfirmationPopup(primary, msg, null, null, primaryText)
  261. }
  262. });