AMBARI-18809. Filter Kerberos related properties in CreateConfigRequest (magyari_sandor)
(cherry picked from commit e4c9890b78c5c9412849b4cd71d31965f30deb55) Change-Id: I957fb8760f7f10815b1d4ec62af04b3f1af465fb Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/00ad53c4 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/00ad53c4 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/00ad53c4 Branch: refs/heads/AMBARI-2.4.2.16 Commit: 00ad53c43d32b22c23c1c4209dc5a60ed606291a Parents: 7d6b947 Author: Sandor Magyari <[email protected]> Authored: Mon Nov 7 12:14:24 2016 +0100 Committer: Sandor Magyari <[email protected]> Committed: Mon Nov 14 15:40:14 2016 +0000 ---------------------------------------------------------------------- .../topology/ClusterConfigurationRequest.java | 41 ++++++++++---- .../ClusterConfigurationRequestTest.java | 59 ++++++++++++++++---- 2 files changed, 79 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/00ad53c4/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java index 6ae08d1..6077907 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java +++ b/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); + } } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/00ad53c4/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java index 3176e42..a97378f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java +++ b/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
