step4_controller.js 13 KB

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