You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/11/10 16:59:14 UTC
[46/50] [abbrv] ambari git commit: AMBARI-18809. Filter Kerberos
related properties in CreateConfigRequest (magyari_sandor)
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-feature-AMBARI-18456
Commit: e55f8a8500de714b8cd6dd8bffac3685c1d49541
Parents: 8335312
Author: Sandor Magyari <sm...@hortonworks.com>
Authored: Mon Nov 7 12:14:24 2016 +0100
Committer: Sandor Magyari <sm...@hortonworks.com>
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<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/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<? 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