step4_controller.js 13 KB

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