step4_controller.js 12 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, App.KDCCredentialsControllerMixin, {
  21. name: 'kerberosWizardStep4Controller',
  22. isWithinAddService: Em.computed.equal('wizardController.name', 'addServiceController'),
  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.getDescriptor().then(function (properties) {
  36. self.setStepConfigs(self.createServicesStackDescriptorConfigs(properties));
  37. }).always(function() {
  38. self.set('isRecommendedLoaded', true);
  39. });
  40. },
  41. /**
  42. * Get descriptor configs from API endpoint.
  43. * On <b>Enable Kerberos</b> loads descriptor from cluster STACK resource.
  44. * On <b>Add Service Wizard</b> first check for cluster's artifacts descriptor and
  45. * save it presence status, then loads from cluster COMPOSITE resource.
  46. * Check for cluster/artifacts/kerberos_descriptor is necessary to determine updating or creation
  47. * kerberos descriptor.
  48. *
  49. * @returns {$.Deferred}
  50. */
  51. getDescriptor: function() {
  52. var self = this;
  53. var dfd = $.Deferred();
  54. var successCallback = function(data) {
  55. dfd.resolve(data);
  56. };
  57. if (this.get('isWithinAddService')) {
  58. App.ajax.send({
  59. sender: this,
  60. name: 'admin.kerberize.cluster_descriptor_artifact'
  61. }).always(function(data, status) {
  62. self.storeClusterDescriptorStatus(status === 'success');
  63. self.loadClusterDescriptorConfigs().then(successCallback);
  64. });
  65. } else {
  66. this.loadStackDescriptorConfigs().then(successCallback);
  67. }
  68. return dfd.promise();
  69. },
  70. /**
  71. * Create service config object for Kerberos service.
  72. *
  73. * @param {App.ServiceConfigProperty[]} configs
  74. * @returns {Em.Object}
  75. */
  76. createServiceConfig: function(configs) {
  77. // Identity configs related to user principal
  78. var clusterConfigs = configs.filterProperty('serviceName','Cluster');
  79. // storm user principal is not required for ambari operation
  80. var userConfigs = configs.filterProperty('identityType','user');
  81. var generalConfigs = clusterConfigs.concat(userConfigs).uniq('name');
  82. var advancedConfigs = configs.filter(function(element){
  83. return !generalConfigs.findProperty('name', element.get('name'));
  84. });
  85. var categoryForGeneralConfigs = [
  86. App.ServiceConfigCategory.create({ name: 'Global', displayName: 'Global'}),
  87. App.ServiceConfigCategory.create({ name: 'Ambari Principals', displayName: 'Ambari Principals'})
  88. ];
  89. var categoryForAdvancedConfigs = this.createCategoryForServices();
  90. return [
  91. App.ServiceConfig.create({
  92. displayName: 'General',
  93. name: 'GENERAL',
  94. serviceName: 'KERBEROS_GENERAL',
  95. configCategories: categoryForGeneralConfigs,
  96. configs: generalConfigs,
  97. showConfig: true
  98. }),
  99. App.ServiceConfig.create({
  100. displayName: 'Advanced',
  101. name: 'ADVANCED',
  102. serviceName: 'KERBEROS_ADVANCED',
  103. configCategories: categoryForAdvancedConfigs,
  104. configs: advancedConfigs,
  105. showConfig: true
  106. })
  107. ];
  108. },
  109. /**
  110. * creates categories for advanced secure configs
  111. * @returns {[App.ServiceConfigCategory]}
  112. */
  113. createCategoryForServices: function() {
  114. var services = [];
  115. if (this.get('wizardController.name') == 'addServiceController') {
  116. services = App.StackService.find().filter(function(item) {
  117. return item.get('isInstalled') || item.get('isSelected');
  118. });
  119. } else {
  120. services = App.Service.find();
  121. }
  122. return services.map(function(item) {
  123. return App.ServiceConfigCategory.create({ name: item.get('serviceName'), displayName: item.get('displayName'), collapsedByDefault: true});
  124. });
  125. },
  126. /**
  127. * Prepare step configs using stack descriptor properties.
  128. *
  129. * @param {App.ServiceConfigProperty[]} configs
  130. * @param {App.ServiceConfigProperty[]} stackConfigs
  131. */
  132. setStepConfigs: function(configs, stackConfigs) {
  133. var configProperties = this.prepareConfigProperties(configs),
  134. stackConfigProperties = stackConfigs ? this.prepareConfigProperties(stackConfigs) : [],
  135. alterProperties = ['value','initialValue', 'defaultValue'];
  136. if (this.get('wizardController.name') == 'addServiceController') {
  137. // config properties for installed services should be disabled on Add Service Wizard
  138. configProperties.forEach(function(item) {
  139. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  140. item.set('isEditable', false);
  141. } else if (stackConfigs) {
  142. var stackConfigProperty = stackConfigProperties.filterProperty('filename', item.get('filename')).findProperty('name', item.get('name'));
  143. if (stackConfigProperty) {
  144. alterProperties.forEach(function (alterProperty) {
  145. item.set(alterProperty, stackConfigProperty.get(alterProperty));
  146. });
  147. }
  148. }
  149. }, this);
  150. // Concat properties that are present in the stack's kerberos descriptor but not in the cluster kerberos descriptor
  151. stackConfigProperties.forEach(function(_stackConfigProperty){
  152. var isPropertyInClusterDescriptor = configProperties.filterProperty('filename', _stackConfigProperty.get('filename')).someProperty('name', _stackConfigProperty.get('name'));
  153. if (!isPropertyInClusterDescriptor) {
  154. if (this.get('installedServiceNames').contains(_stackConfigProperty.get('serviceName')) || _stackConfigProperty.get('serviceName') == 'Cluster') {
  155. _stackConfigProperty.set('isEditable', false);
  156. }
  157. configProperties.pushObject(_stackConfigProperty);
  158. }
  159. }, this);
  160. }
  161. configProperties = App.config.sortConfigs(configProperties);
  162. this.get('stepConfigs').pushObjects(this.createServiceConfig(configProperties));
  163. this.set('selectedService', this.get('stepConfigs')[0]);
  164. },
  165. /**
  166. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  167. * for Add Service Wizard.
  168. * Set property value observer.
  169. * Set realm property with value from previous configuration step.
  170. * Set appropriate category for all configs.
  171. * Hide KDC related credentials properties if kerberos was manually enabled.
  172. *
  173. * @param {App.ServiceConfigProperty[]} configs
  174. * @returns {App.ServiceConfigProperty[]}
  175. */
  176. prepareConfigProperties: function(configs) {
  177. var self = this;
  178. // stored configs from previous steps (Configure Kerberos or Customize Services for ASW)
  179. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  180. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  181. var configProperties = configs.slice(0);
  182. var siteProperties = App.configsCollection.getAll();
  183. // override stored values
  184. App.config.mergeStoredValue(configProperties, this.get('wizardController').loadCachedStepConfigValues(this));
  185. // show admin properties in add service wizard
  186. if (this.get('isWithinAddService')) {
  187. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  188. }
  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. });