This is an automated email from the ASF dual-hosted git repository. houyu pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new e68b7d3988 AMBARI-25887: Disable host encode for existing hive database when export blueprint configuration (#3659) e68b7d3988 is described below commit e68b7d39884895aec24198a13557666c815b7107 Author: Zhiguo Wu <wuzhi...@apache.org> AuthorDate: Sat Mar 18 22:37:26 2023 +0800 AMBARI-25887: Disable host encode for existing hive database when export blueprint configuration (#3659) --- .../internal/BlueprintConfigurationProcessor.java | 104 +++++++++++++++------ 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java index b3540dce5d..bd060c8ea9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java @@ -1508,38 +1508,33 @@ public class BlueprintConfigurationProcessor { Map<String, Map<String, String>> properties = configuration.getFullProperties(); for (Map.Entry<String, Map<String, PropertyUpdater>> entry : updaters.entrySet()) { String type = entry.getKey(); - for (String propertyName : entry.getValue().keySet()) { + Map<String, PropertyUpdater> propertyNameUpdaters = entry.getValue(); + for (Map.Entry<String, PropertyUpdater> propertyNameUpdater : propertyNameUpdaters.entrySet()) { + String propertyName = propertyNameUpdater.getKey(); + PropertyUpdater propertyUpdater = propertyNameUpdater.getValue(); boolean matchedHost = false; Map<String, String> typeProperties = properties.get(type); if (typeProperties != null && typeProperties.containsKey(propertyName)) { String propValue = typeProperties.get(propertyName); - for (HostGroupInfo groupInfo : clusterTopology.getHostGroupInfo().values()) { - Collection<String> hosts = groupInfo.getHostNames(); - for (String host : hosts) { - //todo: need to use regular expression to avoid matching a host which is a superset. - if (propValue.contains(host)) { - matchedHost = true; - configuration.setProperty(type, propertyName, - propValue.replace(host, "%HOSTGROUP::" + groupInfo.getHostGroupName() + "%")); - break; - } - } - if (matchedHost) { - break; - } + String replacedValue = propertyUpdater.updateForBlueprintExport(propertyName, propValue, properties, clusterTopology); + if (!replacedValue.equals(propValue)) { + matchedHost = true; + configuration.setProperty(type, propertyName, replacedValue); } + // remove properties that do not contain hostnames, // except in the case of HA-related properties, that // can contain nameservice references instead of hostnames (Fix for Bug AMBARI-7458). // also will not remove properties that reference the special 0.0.0.0 network // address or properties with undefined hosts - if (! matchedHost && - ! isNameServiceProperty(propertyName) && - ! isSpecialNetworkAddress(propValue) && - ! isUndefinedAddress(propValue) && - ! isPlaceholder(propValue)) { + if (!matchedHost && + !isNameServiceProperty(propertyName) && + !isDatabaseConnectionURL(propertyName) && + !isSpecialNetworkAddress(propValue) && + !isUndefinedAddress(propValue) && + !isPlaceholder(propValue)) { configuration.removeProperty(type, propertyName); } @@ -1572,6 +1567,17 @@ public class BlueprintConfigurationProcessor { return configPropertiesWithHASupport.contains(propertyName); } + /** + * Determine if a property is a database connection url. + * + * @param propertyName property name + * + * @return true if the property value is a database connection url. + */ + private static boolean isDatabaseConnectionURL(String propertyName) { + return propertyName.equals("javax.jdo.option.ConnectionURL"); + } + /** * Queries a property value to determine if the value contains * a host address with all zeros (0.0.0.0). This is a special @@ -1608,17 +1614,14 @@ public class BlueprintConfigurationProcessor { Map<String, Map<String, String>> properties = configuration.getFullProperties(); for (Map.Entry<String, Map<String, PropertyUpdater>> entry : updaters.entrySet()) { String type = entry.getKey(); - for (String propertyName : entry.getValue().keySet()) { + Map<String, PropertyUpdater> propertyNameUpdaters = entry.getValue(); + for (Map.Entry<String, PropertyUpdater> propertyNameUpdater : propertyNameUpdaters.entrySet()) { + String propertyName = propertyNameUpdater.getKey(); + PropertyUpdater propertyUpdater = propertyNameUpdater.getValue(); Map<String, String> typeProperties = properties.get(type); if (typeProperties != null && typeProperties.containsKey(propertyName)) { String propValue = typeProperties.get(propertyName); - for (HostGroupInfo groupInfo : clusterTopology.getHostGroupInfo().values()) { - Collection<String> hosts = groupInfo.getHostNames(); - for (String host : hosts) { - propValue = propValue.replaceAll(host + "\\b", "%HOSTGROUP::" + - groupInfo.getHostGroupName() + "%"); - } - } + propValue = propertyUpdater.updateForBlueprintExport(propertyName, propValue, properties, clusterTopology); Collection<String> addedGroups = new HashSet<>(); String[] toks = propValue.split(","); boolean inBrackets = propValue.startsWith("["); @@ -1967,6 +1970,24 @@ public class BlueprintConfigurationProcessor { } } + @Override + public String updateForBlueprintExport(String propertyName, + String value, + Map<String, Map<String, String>> properties, + ClusterTopology topology) { + for (HostGroupInfo groupInfo : topology.getHostGroupInfo().values()) { + Collection<String> hosts = groupInfo.getHostNames(); + for (String host : hosts) { + //todo: need to use regular expression to avoid matching a host which is a superset. + if (value.contains(host)) { + return value.replace(host, "%HOSTGROUP::" + groupInfo.getHostGroupName() + "%"); + } + } + } + + return value; + } + @Override public Collection<String> getRequiredHostGroups(String propertyName, String origValue, @@ -2216,6 +2237,18 @@ public class BlueprintConfigurationProcessor { } } + @Override + public String updateForBlueprintExport(String propertyName, + String value, + Map<String, Map<String, String>> properties, + ClusterTopology topology) { + if (isDatabaseManaged(properties)) { + return super.updateForBlueprintExport(propertyName, value, properties, topology); + } else { + return value; + } + } + @Override public Collection<String> getRequiredHostGroups(String propertyName, String origValue, @@ -2321,6 +2354,21 @@ public class BlueprintConfigurationProcessor { return resolveHostGroupPlaceholder(origValue, hostStrings); } + @Override + public String updateForBlueprintExport(String propertyName, + String value, + Map<String, Map<String, String>> properties, + ClusterTopology topology) { + for (HostGroupInfo groupInfo : topology.getHostGroupInfo().values()) { + Collection<String> hosts = groupInfo.getHostNames(); + for (String host : hosts) { + value = value.replaceAll(host + "\\b", "%HOSTGROUP::" + groupInfo.getHostGroupName() + "%"); + } + } + + return value; + } + /** * Gets the prefix for hosts * @param value property value --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@ambari.apache.org For additional commands, e-mail: commits-h...@ambari.apache.org