step4_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecurityConfigs, {
  21. name: 'kerberosWizardStep4Controller',
  22. adminPropertyNames: [{name: 'admin_principal', displayName: 'Admin principal'}, {name: 'admin_password', displayName: 'Admin password'}],
  23. clearStep: function() {
  24. this.set('isRecommendedLoaded', false);
  25. this.set('selectedService', null);
  26. this.set('stepConfigs', []);
  27. },
  28. loadStep: function() {
  29. if (this.get('wizardController.skipConfigureIdentitiesStep')) {
  30. App.router.send('next');
  31. return;
  32. }
  33. var self = this;
  34. this.clearStep();
  35. this.getDescriptorConfigs().then(function(properties) {
  36. self.setStepConfigs(properties);
  37. self.set('isRecommendedLoaded', true);
  38. });
  39. },
  40. /**
  41. * Create service config object for Kerberos service.
  42. *
  43. * @param {App.ServiceConfigProperty[]} configs
  44. * @returns {Em.Object}
  45. */
  46. createServiceConfig: function(configs) {
  47. // Identity configs related to user principal
  48. var clusterConfigs = configs.filterProperty('serviceName','Cluster');
  49. // storm user principal is not required for ambari operation
  50. var userConfigs = configs.filterProperty('identityType','user').rejectProperty('serviceName','STORM');
  51. var generalConfigs = clusterConfigs.concat(userConfigs).uniq('name');
  52. var advancedConfigs = configs.filter(function(element){
  53. return !generalConfigs.findProperty('name', element.get('name'));
  54. });
  55. var categoryForGeneralConfigs = [
  56. App.ServiceConfigCategory.create({ name: 'Global', displayName: 'Global'}),
  57. App.ServiceConfigCategory.create({ name: 'Ambari Principals', displayName: 'Ambari Principals'})
  58. ];
  59. var categoryForAdvancedConfigs = this.createCategoryForServices();
  60. return [
  61. App.ServiceConfig.create({
  62. displayName: 'General',
  63. name: 'GENERAL',
  64. serviceName: 'KERBEROS_GENERAL',
  65. configCategories: categoryForGeneralConfigs,
  66. configs: generalConfigs,
  67. showConfig: true
  68. }),
  69. App.ServiceConfig.create({
  70. displayName: 'Advanced',
  71. name: 'ADVANCED',
  72. serviceName: 'KERBEROS_ADVANCED',
  73. configCategories: categoryForAdvancedConfigs,
  74. configs: advancedConfigs,
  75. showConfig: true
  76. })
  77. ];
  78. },
  79. /**
  80. * creates categories for advanced secure configs
  81. * @returns {[App.ServiceConfigCategory]}
  82. */
  83. createCategoryForServices: function() {
  84. var services = [];
  85. if (this.get('wizardController.name') == 'addServiceController') {
  86. services = App.StackService.find().filter(function(item) {
  87. return item.get('isInstalled') || item.get('isSelected');
  88. });
  89. } else {
  90. services = App.Service.find();
  91. }
  92. return services.map(function(item) {
  93. return App.ServiceConfigCategory.create({ name: item.get('serviceName'), displayName: item.get('displayName'), collapsedByDefault: true});
  94. });
  95. },
  96. /**
  97. * Prepare step configs using stack descriptor properties.
  98. *
  99. * @param {App.ServiceConfigProperty[]} configs
  100. */
  101. setStepConfigs: function(configs) {
  102. var configProperties = this.prepareConfigProperties(configs);
  103. if (this.get('wizardController.name') == 'addServiceController') {
  104. // config properties for installed services should be disabled on Add Service Wizard
  105. configProperties.forEach(function(item) {
  106. if (this.get('adminPropertyNames').mapProperty('name').contains(item.get('name'))) return;
  107. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  108. item.set('isEditable', false);
  109. }
  110. }, this);
  111. }
  112. this.get('stepConfigs').pushObjects(this.createServiceConfig(configProperties));
  113. this.set('selectedService', this.get('stepConfigs')[0]);
  114. },
  115. /**
  116. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  117. * for Add Service Wizard.
  118. * Set property value observer.
  119. * Set realm property with value from previous configuration step.
  120. * Set appropriate category for all configs.
  121. * Hide KDC related credentials properties if kerberos was manually enabled.
  122. *
  123. * @param {App.ServiceConfigProperty[]} configs
  124. * @returns {App.ServiceConfigProperty[]}
  125. */
  126. prepareConfigProperties: function(configs) {
  127. var self = this;
  128. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  129. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  130. var adminProps = [];
  131. var configProperties = configs.slice(0);
  132. var siteProperties = App.config.get('preDefinedSiteProperties');
  133. if (this.get('wizardController.name') == 'addServiceController') {
  134. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  135. this.get('adminPropertyNames').forEach(function(item) {
  136. var property = storedServiceConfigs.filterProperty('filename', 'krb5-conf.xml').findProperty('name', item.name);
  137. if (!!property) {
  138. var _prop = App.ServiceConfigProperty.create($.extend({}, property, { name: item.name, value: '', recommendedValue: '', serviceName: 'Cluster', displayName: item.displayName}));
  139. if (App.router.get('mainAdminKerberosController.isManualKerberos')) {
  140. _prop.setProperties({
  141. isRequired: false,
  142. isVisible: false
  143. });
  144. }
  145. _prop.validate();
  146. adminProps.push(_prop);
  147. }
  148. });
  149. configProperties = adminProps.concat(configProperties);
  150. }
  151. configProperties = configProperties.filter(function(item) {
  152. return installedServiceNames.contains(item.get('serviceName'));
  153. });
  154. if (this.get('wizardController.name') != 'addServiceController') {
  155. var realmValue = storedServiceConfigs.findProperty('name', 'realm').value;
  156. configProperties.findProperty('name', 'realm').set('value', realmValue);
  157. configProperties.findProperty('name', 'realm').set('recommendedValue', realmValue);
  158. }
  159. configProperties.setEach('isSecureConfig', false);
  160. configProperties.forEach(function(property, item, allConfigs) {
  161. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  162. property.addObserver('value', self, 'spnegoPropertiesObserver');
  163. }
  164. if (property.get('observesValueFrom')) {
  165. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  166. property.set('value', observedValue);
  167. property.set('recommendedValue', observedValue);
  168. }
  169. if (property.get('serviceName') == 'Cluster') {
  170. property.set('category', 'Global');
  171. }
  172. else {
  173. property.set('category', property.get('serviceName'));
  174. }
  175. // All user identity except storm should be grouped under "Ambari Principals" category
  176. if (property.get('identityType') == 'user' && property.get('serviceName') !== 'STORM') property.set('category', 'Ambari Principals');
  177. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  178. if (siteProperty) {
  179. if (siteProperty.category === property.get('category')) {
  180. property.set('displayName',siteProperty.displayName);
  181. if (siteProperty.index) {
  182. property.set('index', siteProperty.index);
  183. }
  184. }
  185. if (siteProperty.displayType) {
  186. property.set('displayType', siteProperty.displayType);
  187. }
  188. }
  189. this.tweakConfigProperty(property);
  190. },this);
  191. return configProperties;
  192. },
  193. /**
  194. * Function to override kerberos descriptor's property values
  195. */
  196. tweakConfigProperty: function(config) {
  197. if (config.name === 'templeton.hive.properties') {
  198. var defaultHiveMsPort = "9083";
  199. var hiveMSHosts = App.HostComponent.find().filterProperty('componentName', 'HIVE_METASTORE');
  200. if (hiveMSHosts.length > 1) {
  201. var hiveMSHostNames = hiveMSHosts.mapProperty('hostName');
  202. var port = config.value.match(/:[0-9]{2,4}/);
  203. port = port ? port[0].slice(1) : defaultHiveMsPort;
  204. for (var i = 0; i < hiveMSHostNames.length; i++) {
  205. hiveMSHostNames[i] = "thrift://" + hiveMSHostNames[i] + ":" + port;
  206. }
  207. var configValue = config.value.replace(/thrift.+[0-9]{2,},/i, hiveMSHostNames.join('\\,') + ",");
  208. config.set('value', configValue);
  209. config.set('recommendedValue', configValue);
  210. }
  211. }
  212. },
  213. /**
  214. * Sync up values between inherited property and its reference.
  215. *
  216. * @param {App.ServiceConfigProperty} configProperty
  217. */
  218. spnegoPropertiesObserver: function(configProperty) {
  219. var self = this;
  220. var stepConfig = this.get('stepConfigs').findProperty('name', 'ADVANCED');
  221. stepConfig.get('configs').forEach(function(config) {
  222. if (config.get('observesValueFrom') == configProperty.get('name')) {
  223. Em.run.once(self, function() {
  224. config.set('value', configProperty.get('value'));
  225. config.set('recommendedValue', configProperty.get('value'));
  226. });
  227. }
  228. });
  229. },
  230. submit: function() {
  231. this.saveConfigurations();
  232. App.router.send('next');
  233. },
  234. saveConfigurations: function() {
  235. var kerberosDescriptor = this.get('kerberosDescriptor');
  236. var configs = [];
  237. this.get('stepConfigs').forEach(function(_stepConfig){
  238. configs = configs.concat(_stepConfig.get('configs'));
  239. });
  240. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  241. App.get('router.kerberosWizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
  242. }
  243. });