step4_controller.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecurityConfigs, {
  19. name: 'kerberosWizardStep4Controller',
  20. clearStep: function() {
  21. this.set('isRecommendedLoaded', false);
  22. this.set('selectedService', null);
  23. this.set('stepConfigs', []);
  24. },
  25. loadStep: function() {
  26. var self = this;
  27. this.clearStep();
  28. this.getStackDescriptorConfigs().then(function(properties) {
  29. self.setStepConfigs(properties);
  30. self.set('isRecommendedLoaded', true);
  31. });
  32. },
  33. /**
  34. * Create service config object for Kerberos service.
  35. *
  36. * @param {Em.Object[]} configCategories
  37. * @param {App.ServiceConfigProperty[]} configs
  38. * @returns {Em.Object}
  39. */
  40. createServiceConfig: function(configCategories, configs) {
  41. return App.ServiceConfig.create({
  42. displayName: 'Kerberos Descriptor',
  43. name: 'KERBEROS',
  44. serviceName: 'KERBEROS',
  45. configCategories: configCategories,
  46. configs: configs,
  47. showConfig: true,
  48. selected: true
  49. });
  50. },
  51. /**
  52. * Prepare step configs using stack descriptor properties.
  53. *
  54. * @param {App.ServiceConfigProperty[]} configs
  55. */
  56. setStepConfigs: function(configs) {
  57. var selectedService = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  58. var configCategories = selectedService.get('configCategories');
  59. this.get('stepConfigs').pushObject(this.createServiceConfig(configCategories, this.prepareConfigProperties(configs)));
  60. this.set('selectedService', this.get('stepConfigs')[0]);
  61. },
  62. /**
  63. * Filter configs by installed services. Set property value observer.
  64. * Set realm property with value from previous configuration step.
  65. * Set appropriate category for all configs.
  66. *
  67. * @param {App.ServiceCofigProperty[]} configs
  68. * @returns {App.ServiceConfigProperty[]}
  69. */
  70. prepareConfigProperties: function(configs) {
  71. var self = this;
  72. var realmValue = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'realm').value;
  73. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  74. configs = configs.filter(function(item) {
  75. return installedServiceNames.contains(item.get('serviceName'));
  76. });
  77. configs.findProperty('name', 'realm').set('value', realmValue);
  78. configs.findProperty('name', 'realm').set('defaultValue', realmValue);
  79. configs.setEach('isSecureConfig', false);
  80. configs.forEach(function(property, item, allConfigs) {
  81. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  82. property.addObserver('value', self, 'spnegoPropertiesObserver');
  83. }
  84. if (property.get('observesValueFrom')) {
  85. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  86. property.set('value', observedValue);
  87. property.set('defaultValue', observedValue);
  88. }
  89. if (property.get('serviceName') == 'Cluster') property.set('category', 'General');
  90. else property.set('category', 'Advanced');
  91. });
  92. return configs;
  93. },
  94. /**
  95. * Sync up values between inherited property and its reference.
  96. *
  97. * @param {App.ServiceConfigProperty} configProperty
  98. */
  99. spnegoPropertiesObserver: function(configProperty) {
  100. var self = this;
  101. this.get('stepConfigs')[0].get('configs').forEach(function(config) {
  102. if (config.get('observesValueFrom') == configProperty.get('name')) {
  103. Em.run.once(self, function() {
  104. config.set('value', configProperty.get('value'));
  105. config.set('defaultValue', configProperty.get('value'));
  106. });
  107. }
  108. });
  109. },
  110. submit: function() {
  111. this.saveConfigurations();
  112. App.router.send('next');
  113. },
  114. saveConfigurations: function() {
  115. var kerberosDescriptor = this.get('kerberosDescriptor');
  116. var configs = this.get('stepConfigs')[0].get('configs');
  117. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  118. this.get('wizardController').setDBProperty('kerberosDescriptorConfigs', kerberosDescriptor);
  119. this.set('wizardController.content.kerberosDescriptorConfigs', kerberosDescriptor);
  120. }
  121. });