فهرست منبع

AMBARI-18809. Filter Kerberos related properties in CreateConfigRequest (magyari_sandor)

Sandor Magyari 9 سال پیش
والد
کامیت
3b530582ba

+ 31 - 10
ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java

@@ -159,6 +159,20 @@ public class ClusterConfigurationRequest {
     setConfigurationsOnCluster(clusterTopology, TopologyManager.TOPOLOGY_RESOLVED_TAG, updatedConfigTypes);
   }
 
+  /**
+   * A config type is orphaned if there are services related to except cluster-env and global.
+   */
+  private boolean isOrphanedConfigType(String configType, Blueprint blueprint) {
+    boolean isOrphanedConfigType = false;
+    if (!"cluster-env".equals(configType) && !"global".equals(configType)) {
+      String service = blueprint.getStack().getServiceForConfigType(configType);
+      if (!blueprint.getServices().contains(service)) {
+        isOrphanedConfigType = true;
+      }
+    }
+    return isOrphanedConfigType;
+  }
+
   private Set<String> configureKerberos(Configuration clusterConfiguration, Map<String, Map<String, String>> existingConfigurations) throws AmbariException {
     Set<String> updatedConfigTypes = new HashSet<>();
 
@@ -198,16 +212,23 @@ public class ClusterConfigurationRequest {
       // ******************************************************************************************
 
       for (String configType : updatedConfigs.keySet()) {
-        Map<String, String> propertyMap = updatedConfigs.get(configType);
-        Map<String, String> clusterConfigProperties = existingConfigurations.get(configType);
-        Map<String, String> stackDefaultConfigProperties = stackDefaultProps.get(configType);
-        for (String property : propertyMap.keySet()) {
-          // update value only if property value configured in Blueprint /ClusterTemplate is not a custom one
-          if (!propertyHasCustomValue(clusterConfigProperties, stackDefaultConfigProperties, property)) {
-            LOG.debug("Update Kerberos related config property: {} {} {}", configType, property, propertyMap.get
-              (property));
-            clusterConfiguration.setProperty(configType, property, propertyMap.get(property));
-            updatedConfigTypes.add(configType);
+        // apply only if config type has related services in Blueprint
+        if (!isOrphanedConfigType(configType, blueprint)) {
+          Map<String, String> propertyMap = updatedConfigs.get(configType);
+          Map<String, String> clusterConfigProperties = existingConfigurations.get(configType);
+          Map<String, String> stackDefaultConfigProperties = stackDefaultProps.get(configType);
+          for (String property : propertyMap.keySet()) {
+            // update value only if property value configured in Blueprint / ClusterTemplate is not a custom one
+            String currentValue = clusterConfiguration.getPropertyValue(configType, property);
+            String newValue = propertyMap.get(property);
+            if (!propertyHasCustomValue(clusterConfigProperties, stackDefaultConfigProperties, property) &&
+              (currentValue == null || !currentValue.equals(newValue))) {
+
+              LOG.debug("Update Kerberos related config property: {} {} {}", configType, property, propertyMap.get
+                (property));
+              clusterConfiguration.setProperty(configType, property, newValue);
+              updatedConfigTypes.add(configType);
+            }
           }
         }
       }

+ 48 - 11
ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java

@@ -30,6 +30,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -110,7 +111,7 @@ public class ClusterConfigurationRequestTest {
   @Test
   public void testProcessWithKerberos_UpdateKererosConfigProperty_WithNoCustomValue() throws Exception {
 
-    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue");
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", null);
 
     Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
     assertEquals(2, updatedConfigTypes.size());
@@ -125,7 +126,8 @@ public class ClusterConfigurationRequestTest {
   public void testProcessWithKerberos_UpdateKererosConfigProperty_WithCustomValueEqualToStackDefault() throws
     Exception {
 
-    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("defaultTestValue", "defaultTestValue");
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("defaultTestValue",
+      "defaultTestValue", null);
 
     Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
     assertEquals(2, updatedConfigTypes.size());
@@ -141,7 +143,8 @@ public class ClusterConfigurationRequestTest {
   public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueDifferentThanStackDefault() throws
     Exception {
 
-    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", "defaultTestValue");
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue",
+      "defaultTestValue", null);
 
     Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
     assertEquals(1, updatedConfigTypes.size());
@@ -156,14 +159,43 @@ public class ClusterConfigurationRequestTest {
   @Test
   public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueNoStackDefault() throws Exception {
 
-    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", null);
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", null, null);
+
+    Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
+    assertEquals(1, updatedConfigTypes.size());
+  }
+
+  @Test
+  public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithKerberosConfigSameAsDefault() throws
+    Exception {
+    Map<String, Map<String, String>> kerberosConfig = new HashMap<>();
+    Map<String, String> properties = new HashMap<>();
+    properties.put("testProperty", "defaultTestValue");
+    kerberosConfig.put("testConfigType", properties);
+
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", kerberosConfig);
+
+    Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
+    assertEquals(1, updatedConfigTypes.size());
+  }
+
+  @Test
+  public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithOrphanedKerberosConfigType() throws
+    Exception {
+    Map<String, Map<String, String>> kerberosConfig = new HashMap<>();
+    Map<String, String> properties = new HashMap<>();
+    properties.put("testProperty", "KERBEROStestValue");
+    kerberosConfig.put("orphanedTestConfigType", properties);
+
+    Capture<? extends Set<String>> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", kerberosConfig);
 
     Set<String> updatedConfigTypes = captureUpdatedConfigTypes.getValue();
     assertEquals(1, updatedConfigTypes.size());
   }
 
   private Capture<? extends Set<String>> testProcessWithKerberos(String blueprintPropertyValue, String
-    stackPropertyValue) throws AmbariException, KerberosInvalidConfigurationException, ConfigurationTopologyException {
+    stackPropertyValue,  Map<String, Map<String, String>> kerberosConfig) throws AmbariException, KerberosInvalidConfigurationException,
+    ConfigurationTopologyException {
 
 
     Map<String, Map<String, String>> existingConfig = new HashMap<String, Map<String, String>>();
@@ -189,7 +221,7 @@ public class ClusterConfigurationRequestTest {
     expect(clusters.getCluster("testCluster")).andReturn(cluster).anyTimes();
 
     expect(blueprint.getStack()).andReturn(stack).anyTimes();
-    expect(stack.getServiceForConfigType(anyString())).andReturn("KERBEROS").anyTimes();
+    expect(stack.getServiceForConfigType("testConfigType")).andReturn("KERBEROS").anyTimes();
     expect(stack.getAllConfigurationTypes(anyString())).andReturn(Collections.<String>singletonList("testConfigType")
     ).anyTimes();
     expect(stack.getExcludedConfigurationTypes(anyString())).andReturn(Collections.<String>emptySet()).anyTimes();
@@ -219,14 +251,19 @@ public class ClusterConfigurationRequestTest {
     expect(topology.getConfiguration()).andReturn(blueprintConfig).anyTimes();
     expect(topology.getHostGroupInfo()).andReturn(Collections.<String, HostGroupInfo>emptyMap()).anyTimes();
     expect(topology.getClusterId()).andReturn(Long.valueOf(1)).anyTimes();
-    expect(ambariContext.getClusterName(Long.valueOf(1))).andReturn("testCluster").anyTimes();
+    expect(topology.getHostGroupsForComponent(anyString())).andReturn(Collections.<String>emptyList())
+      .anyTimes();
+
+      expect(ambariContext.getClusterName(Long.valueOf(1))).andReturn("testCluster").anyTimes();
     expect(ambariContext.createConfigurationRequests(anyObject(Map.class))).andReturn(Collections
       .<ConfigurationRequest>emptyList()).anyTimes();
 
-    Map<String, Map<String, String>> kerberosConfig = new HashMap<String, Map<String, String>>();
-    Map<String, String> properties = new HashMap<>();
-    properties.put("testProperty", "KERBEROStestValue");
-    kerberosConfig.put("testConfigType", properties);
+    if (kerberosConfig == null) {
+      kerberosConfig = new HashMap<>();
+      Map<String, String> properties = new HashMap<>();
+      properties.put("testProperty", "KERBEROStestValue");
+      kerberosConfig.put("testConfigType", properties);
+     }
     expect(kerberosHelper.ensureHeadlessIdentities(anyObject(Cluster.class), anyObject(Map.class), anyObject
       (Set.class))).andReturn(true).once();
     expect(kerberosHelper.getServiceConfigurationUpdates(anyObject(Cluster.class), anyObject(Map.class), anyObject