Ver código fonte

AMBARI-8200 Add Service wizard: Custom properties with empty values should not be be marked erroneous. (Buzhor Denys via ababiichuk)

aBabiichuk 10 anos atrás
pai
commit
b67ddc7c1f

+ 32 - 2
ambari-web/app/controllers/wizard/step7_controller.js

@@ -51,7 +51,13 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, {
   /**
   /**
    * used in services_config.js view to mark a config with security icon
    * used in services_config.js view to mark a config with security icon
    */
    */
-  secureConfigs: require('data/secure_mapping'),
+  secureConfigs: function() {
+    if (App.get('isHadoop2Stack')) {
+      return require('data/HDP2/secure_mapping');
+    } else {
+      return require('data/secure_mapping');
+    }
+  }.property('isHadoop2Stack'),
 
 
   /**
   /**
    * config categories with secure properties
    * config categories with secure properties
@@ -818,7 +824,12 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, {
           this.addSecureConfigs(selectedService, serviceName) ;
           this.addSecureConfigs(selectedService, serviceName) ;
         }
         }
       }, this);
       }, this);
-
+      this.get('installedServiceNames').forEach(function(serviceName) {
+        var serviceConfigObj = serviceConfigs.findProperty('serviceName', serviceName);
+        if (this.get('securityEnabled')) {
+          this.setSecureConfigs(serviceConfigObj, serviceName);
+        }
+      }, this);
       // Remove SNameNode if HA is enabled
       // Remove SNameNode if HA is enabled
       if (App.get('isHaEnabled')) {
       if (App.get('isHaEnabled')) {
         var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
         var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
@@ -833,6 +844,25 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, {
     this.set('stepConfigs', serviceConfigs);
     this.set('stepConfigs', serviceConfigs);
   },
   },
 
 
+  /**
+   * Set secure properties for installed services. Mark secure properties and 
+   * properties with default empty value as non required to pass validation.
+   *
+   * @param {Em.Object} serviceConfigObj
+   * @param {String} serviceName
+   */
+  setSecureConfigs: function(serviceConfigObj, serviceName) {
+    var configProperties = serviceConfigObj.get('configs');
+    if (!configProperties) return;
+    var secureConfigs = this.get('secureConfigs').filterProperty('serviceName', serviceName);
+    secureConfigs.forEach(function(secureConfig) {
+      var property = configProperties.findProperty('name', secureConfig.name);
+      if (property) {
+        property.set('isRequired', secureConfig.value != "");
+        if (!property.get('isRequired')) property.set('errorMessage', '');
+      }
+    });
+  },
   /**
   /**
    *
    *
    * @param selectedService
    * @param selectedService

+ 2 - 1
ambari-web/app/data/HDP2/secure_mapping.js

@@ -16,6 +16,7 @@
  * limitations under the License.
  * limitations under the License.
  */
  */
 
 
+var App = require('app');
 // All of the "name" properties have to coincide with how they will appear in the *-site.xml file
 // All of the "name" properties have to coincide with how they will appear in the *-site.xml file
 // The "template" properties can come from the config properties in site_properties.js or secure_properties.js .
 // The "template" properties can come from the config properties in site_properties.js or secure_properties.js .
 var props = [
 var props = [
@@ -921,7 +922,7 @@ var yarn22Mapping = [
     "value": "",
     "value": "",
     "templateName": [],
     "templateName": [],
     "foreignKey": null,
     "foreignKey": null,
-    "serviceName": "YARN",
+    "serviceName": "HDFS",
     "filename": "core-site.xml"
     "filename": "core-site.xml"
   },
   },
   {
   {

+ 36 - 2
ambari-web/test/controllers/wizard/step7_test.js

@@ -333,7 +333,7 @@ describe('App.InstallerStep7Controller', function () {
     it('should set property to false', function () {
     it('should set property to false', function () {
       var allSelectedServiceNames = ['YARN'],
       var allSelectedServiceNames = ['YARN'],
         configs = [
         configs = [
-          {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true},
+          {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true}
         ],
         ],
         expected = [
         expected = [
           {name: 'hadoop.registry.rm.enabled', value: false, defaultValue: false, forceUpdate: true}
           {name: 'hadoop.registry.rm.enabled', value: false, defaultValue: false, forceUpdate: true}
@@ -346,7 +346,7 @@ describe('App.InstallerStep7Controller', function () {
     it('should skip setting property', function () {
     it('should skip setting property', function () {
       var allSelectedServiceNames = ['YARN', 'SLIDER'],
       var allSelectedServiceNames = ['YARN', 'SLIDER'],
         configs = [
         configs = [
-          {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true},
+          {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true}
         ],
         ],
         expected = [
         expected = [
           {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true}
           {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true}
@@ -1238,4 +1238,38 @@ describe('App.InstallerStep7Controller', function () {
 
 
   });
   });
 
 
+  describe('#setSecureConfigs', function() {
+    var serviceConfigObj = Em.Object.create({
+      serviceName: 'HDFS',
+      configs: [
+        Em.Object.create({ name: 'hadoop.http.authentication.signature.secret.file' }),
+        Em.Object.create({ name: 'hadoop.security.authentication' })
+      ]
+    });
+    var tests = [
+      { name: 'hadoop.http.authentication.signature.secret.file', e: false },
+      { name: 'hadoop.security.authentication', e: true }
+    ];
+
+    sinon.stub(App, 'get', function(key) {
+      if (['isHadoop22Stack', 'isHadoop2Stack'].contains(key)) return true;
+      else App.get(key);
+    });
+    var controller = App.WizardStep7Controller.create({});
+    controller.get('secureConfigs').pushObjects([
+      {
+        name: 'hadoop.http.authentication.signature.secret.file',
+        serviceName: 'HDFS',
+        value: ''
+      }
+    ]);
+    controller.setSecureConfigs(serviceConfigObj, 'HDFS');
+    App.get.restore();
+    tests.forEach(function(test) {
+      it('{0} is {1}required'.format(test.name, !!test.e ? '' : 'non ' ), function() {
+        expect(serviceConfigObj.get('configs').findProperty('name', test.name).get('isRequired')).to.eql(test.e);
+      });
+    });
+  });
+
 });
 });