Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id EEA29200BCC for ; Mon, 14 Nov 2016 19:27:18 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EB760160B0F; Mon, 14 Nov 2016 18:27:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2B17F160B25 for ; Mon, 14 Nov 2016 19:27:17 +0100 (CET) Received: (qmail 25449 invoked by uid 500); 14 Nov 2016 18:27:15 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 24848 invoked by uid 99); 14 Nov 2016 18:27:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2016 18:27:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3C991DFCCC; Mon, 14 Nov 2016 18:27:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ncole@apache.org To: commits@ambari.apache.org Date: Mon, 14 Nov 2016 18:27:36 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [23/50] [abbrv] ambari git commit: AMBARI-18809. Filter Kerberos related properties in CreateConfigRequest (magyari_sandor) archived-at: Mon, 14 Nov 2016 18:27:19 -0000 AMBARI-18809. Filter Kerberos related properties in CreateConfigRequest (magyari_sandor) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e55f8a85 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e55f8a85 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e55f8a85 Branch: refs/heads/branch-dev-patch-upgrade Commit: e55f8a8500de714b8cd6dd8bffac3685c1d49541 Parents: 8335312 Author: Sandor Magyari Authored: Mon Nov 7 12:14:24 2016 +0100 Committer: Sandor Magyari Committed: Thu Nov 10 15:56:15 2016 +0100 ---------------------------------------------------------------------- .../topology/ClusterConfigurationRequest.java | 41 ++++++++++---- .../ClusterConfigurationRequestTest.java | 59 ++++++++++++++++---- 2 files changed, 79 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e55f8a85/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 configureKerberos(Configuration clusterConfiguration, Map> existingConfigurations) throws AmbariException { Set updatedConfigTypes = new HashSet<>(); @@ -198,16 +212,23 @@ public class ClusterConfigurationRequest { // ****************************************************************************************** for (String configType : updatedConfigs.keySet()) { - Map propertyMap = updatedConfigs.get(configType); - Map clusterConfigProperties = existingConfigurations.get(configType); - Map 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 propertyMap = updatedConfigs.get(configType); + Map clusterConfigProperties = existingConfigurations.get(configType); + Map 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/e55f8a85/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> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue"); + Capture> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", null); Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); assertEquals(2, updatedConfigTypes.size()); @@ -125,7 +126,8 @@ public class ClusterConfigurationRequestTest { public void testProcessWithKerberos_UpdateKererosConfigProperty_WithCustomValueEqualToStackDefault() throws Exception { - Capture> captureUpdatedConfigTypes = testProcessWithKerberos("defaultTestValue", "defaultTestValue"); + Capture> captureUpdatedConfigTypes = testProcessWithKerberos("defaultTestValue", + "defaultTestValue", null); Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); assertEquals(2, updatedConfigTypes.size()); @@ -141,7 +143,8 @@ public class ClusterConfigurationRequestTest { public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueDifferentThanStackDefault() throws Exception { - Capture> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", "defaultTestValue"); + Capture> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", + "defaultTestValue", null); Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); assertEquals(1, updatedConfigTypes.size()); @@ -156,14 +159,43 @@ public class ClusterConfigurationRequestTest { @Test public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueNoStackDefault() throws Exception { - Capture> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", null); + Capture> captureUpdatedConfigTypes = testProcessWithKerberos("testPropertyValue", null, null); + + Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); + assertEquals(1, updatedConfigTypes.size()); + } + + @Test + public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithKerberosConfigSameAsDefault() throws + Exception { + Map> kerberosConfig = new HashMap<>(); + Map properties = new HashMap<>(); + properties.put("testProperty", "defaultTestValue"); + kerberosConfig.put("testConfigType", properties); + + Capture> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", kerberosConfig); + + Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); + assertEquals(1, updatedConfigTypes.size()); + } + + @Test + public void testProcessWithKerberos_DontUpdateKererosConfigProperty_WithOrphanedKerberosConfigType() throws + Exception { + Map> kerberosConfig = new HashMap<>(); + Map properties = new HashMap<>(); + properties.put("testProperty", "KERBEROStestValue"); + kerberosConfig.put("orphanedTestConfigType", properties); + + Capture> captureUpdatedConfigTypes = testProcessWithKerberos(null, "defaultTestValue", kerberosConfig); Set updatedConfigTypes = captureUpdatedConfigTypes.getValue(); assertEquals(1, updatedConfigTypes.size()); } private Capture> testProcessWithKerberos(String blueprintPropertyValue, String - stackPropertyValue) throws AmbariException, KerberosInvalidConfigurationException, ConfigurationTopologyException { + stackPropertyValue, Map> kerberosConfig) throws AmbariException, KerberosInvalidConfigurationException, + ConfigurationTopologyException { Map> existingConfig = new HashMap>(); @@ -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.singletonList("testConfigType") ).anyTimes(); expect(stack.getExcludedConfigurationTypes(anyString())).andReturn(Collections.emptySet()).anyTimes(); @@ -219,14 +251,19 @@ public class ClusterConfigurationRequestTest { expect(topology.getConfiguration()).andReturn(blueprintConfig).anyTimes(); expect(topology.getHostGroupInfo()).andReturn(Collections.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.emptyList()) + .anyTimes(); + + expect(ambariContext.getClusterName(Long.valueOf(1))).andReturn("testCluster").anyTimes(); expect(ambariContext.createConfigurationRequests(anyObject(Map.class))).andReturn(Collections .emptyList()).anyTimes(); - Map> kerberosConfig = new HashMap>(); - Map properties = new HashMap<>(); - properties.put("testProperty", "KERBEROStestValue"); - kerberosConfig.put("testConfigType", properties); + if (kerberosConfig == null) { + kerberosConfig = new HashMap<>(); + Map 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