This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b3b86d52f42 KAFKA-17717 Remove ConfigUtils#translateDeprecatedConfigs 
and tests (#17458)
b3b86d52f42 is described below

commit b3b86d52f4255ef7f6efad83209e3abbc19421e7
Author: mingdaoy <[email protected]>
AuthorDate: Fri Oct 11 21:57:22 2024 +0800

    KAFKA-17717 Remove ConfigUtils#translateDeprecatedConfigs and tests (#17458)
    
    Reviewers: Chia-Ping Tsai <[email protected]>
---
 .../org/apache/kafka/common/utils/ConfigUtils.java |  87 ----------------
 .../apache/kafka/common/utils/ConfigUtilsTest.java | 115 ---------------------
 2 files changed, 202 deletions(-)

diff --git 
a/clients/src/main/java/org/apache/kafka/common/utils/ConfigUtils.java 
b/clients/src/main/java/org/apache/kafka/common/utils/ConfigUtils.java
index ad150afee63..397ab623b52 100644
--- a/clients/src/main/java/org/apache/kafka/common/utils/ConfigUtils.java
+++ b/clients/src/main/java/org/apache/kafka/common/utils/ConfigUtils.java
@@ -25,101 +25,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 public class ConfigUtils {
 
     private static final Logger log = 
LoggerFactory.getLogger(ConfigUtils.class);
 
-    /**
-     * Translates deprecated configurations into their non-deprecated 
equivalents
-     *
-     * This is a convenience method for {@link 
ConfigUtils#translateDeprecatedConfigs(Map, Map)}
-     * until we can use Java 9+ {@code Map.of(..)} and {@code Set.of(...)}
-     *
-     * @param configs the input configuration
-     * @param aliasGroups An array of arrays of synonyms.  Each synonym array 
begins with the non-deprecated synonym
-     *                    For example, new String[][] { { a, b }, { c, d, e} }
-     *                    would declare b as a deprecated synonym for a,
-     *                    and d and e as deprecated synonyms for c.
-     *                    The ordering of synonyms determines the order of 
precedence
-     *                    (e.g. the first synonym takes precedence over the 
second one)
-     * @return a new configuration map with deprecated  keys translated to 
their non-deprecated equivalents
-     */
-    public static <T> Map<String, T> translateDeprecatedConfigs(Map<String, T> 
configs, String[][] aliasGroups) {
-        return translateDeprecatedConfigs(configs, Stream.of(aliasGroups)
-            .collect(Collectors.toMap(x -> x[0], x -> 
Stream.of(x).skip(1).collect(Collectors.toList()))));
-    }
-
-    /**
-     * Translates deprecated configurations into their non-deprecated 
equivalents
-     *
-     * @param configs the input configuration
-     * @param aliasGroups A map of config to synonyms.  Each key is the 
non-deprecated synonym
-     *                    For example, Map.of(a , Set.of(b), c, Set.of(d, e))
-     *                    would declare b as a deprecated synonym for a,
-     *                    and d and e as deprecated synonyms for c.
-     *                    The ordering of synonyms determines the order of 
precedence
-     *                    (e.g. the first synonym takes precedence over the 
second one)
-     * @return a new configuration map with deprecated  keys translated to 
their non-deprecated equivalents
-     */
-    public static <T> Map<String, T> translateDeprecatedConfigs(Map<String, T> 
configs,
-                                                                Map<String, 
List<String>> aliasGroups) {
-        Set<String> aliasSet = Stream.concat(
-            aliasGroups.keySet().stream(),
-            aliasGroups.values().stream().flatMap(Collection::stream))
-            .collect(Collectors.toSet());
-
-        // pass through all configurations without aliases
-        Map<String, T> newConfigs = configs.entrySet().stream()
-            .filter(e -> !aliasSet.contains(e.getKey()))
-            // filter out null values
-            .filter(e -> Objects.nonNull(e.getValue()))
-            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
-
-        aliasGroups.forEach((target, aliases) -> {
-            List<String> deprecated = aliases.stream()
-                .filter(configs::containsKey)
-                .collect(Collectors.toList());
-
-            if (deprecated.isEmpty()) {
-                // No deprecated key(s) found.
-                if (configs.containsKey(target)) {
-                    newConfigs.put(target, configs.get(target));
-                }
-                return;
-            }
-
-            String aliasString = String.join(", ", deprecated);
-
-            if (configs.containsKey(target)) {
-                // Ignore the deprecated key(s) because the actual key was set.
-                log.error(target + " was configured, as well as the deprecated 
alias(es) " +
-                          aliasString + ".  Using the value of " + target);
-                newConfigs.put(target, configs.get(target));
-            } else if (deprecated.size() > 1) {
-                log.error("The configuration keys " + aliasString + " are 
deprecated and may be " +
-                          "removed in the future.  Additionally, this 
configuration is ambiguous because " +
-                          "these configuration keys are all aliases for " + 
target + ".  Please update " +
-                          "your configuration to have only " + target + " 
set.");
-                newConfigs.put(target, configs.get(deprecated.get(0)));
-            } else {
-                log.warn("Configuration key " + deprecated.get(0) + " is 
deprecated and may be removed " +
-                         "in the future.  Please update your configuration to 
use " + target + " instead.");
-                newConfigs.put(target, configs.get(deprecated.get(0)));
-            }
-        });
-
-        return newConfigs;
-    }
-
     public static String configMapToRedactedString(Map<String, Object> map, 
ConfigDef configDef) {
         StringBuilder bld = new StringBuilder("{");
         List<String> keys = new ArrayList<>(map.keySet());
diff --git 
a/clients/src/test/java/org/apache/kafka/common/utils/ConfigUtilsTest.java 
b/clients/src/test/java/org/apache/kafka/common/utils/ConfigUtilsTest.java
index bb94f2611a1..441b815b638 100644
--- a/clients/src/test/java/org/apache/kafka/common/utils/ConfigUtilsTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/utils/ConfigUtilsTest.java
@@ -29,124 +29,9 @@ import java.util.Map;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
 
 public class ConfigUtilsTest {
 
-    @Test
-    public void testTranslateDeprecated() {
-        Map<String, Object> config = new HashMap<>();
-        config.put("foo.bar", "baz");
-        config.put("foo.bar.deprecated", "quux");
-        config.put("chicken", "1");
-        config.put("rooster", "2");
-        config.put("hen", "3");
-        config.put("heifer", "moo");
-        config.put("blah", "blah");
-        config.put("unexpected.non.string.object", 42);
-        Map<String, Object> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"},
-            {"chicken", "rooster", "hen"},
-            {"cow", "beef", "heifer", "steer"}
-        });
-        assertEquals("baz", newConfig.get("foo.bar"));
-        assertNull(newConfig.get("foobar.deprecated"));
-        assertEquals("1", newConfig.get("chicken"));
-        assertNull(newConfig.get("rooster"));
-        assertNull(newConfig.get("hen"));
-        assertEquals("moo", newConfig.get("cow"));
-        assertNull(newConfig.get("beef"));
-        assertNull(newConfig.get("heifer"));
-        assertNull(newConfig.get("steer"));
-        assertNull(config.get("cow"));
-        assertEquals("blah", config.get("blah"));
-        assertEquals("blah", newConfig.get("blah"));
-        assertEquals(42, newConfig.get("unexpected.non.string.object"));
-        assertEquals(42, config.get("unexpected.non.string.object"));
-
-    }
-
-    @Test
-    public void testAllowsNewKey() {
-        Map<String, String> config = new HashMap<>();
-        config.put("foo.bar", "baz");
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"},
-            {"chicken", "rooster", "hen"},
-            {"cow", "beef", "heifer", "steer"}
-        });
-        assertNotNull(newConfig);
-        assertEquals("baz", newConfig.get("foo.bar"));
-        assertNull(newConfig.get("foo.bar.deprecated"));
-    }
-
-    @Test
-    public void testAllowDeprecatedNulls() {
-        Map<String, String> config = new HashMap<>();
-        config.put("foo.bar.deprecated", null);
-        config.put("foo.bar", "baz");
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"}
-        });
-        assertNotNull(newConfig);
-        assertEquals("baz", newConfig.get("foo.bar"));
-        assertNull(newConfig.get("foo.bar.deprecated"));
-    }
-
-    @Test
-    public void testAllowNullOverride() {
-        Map<String, String> config = new HashMap<>();
-        config.put("foo.bar.deprecated", "baz");
-        config.put("foo.bar", null);
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"}
-        });
-        assertNotNull(newConfig);
-        assertNull(newConfig.get("foo.bar"));
-        assertNull(newConfig.get("foo.bar.deprecated"));
-    }
-
-    @Test
-    public void testNullMapEntriesWithoutAliasesDoNotThrowNPE() {
-        Map<String, String> config = new HashMap<>();
-        config.put("other", null);
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"}
-        });
-        assertNotNull(newConfig);
-        assertNull(newConfig.get("other"));
-    }
-
-    @Test
-    public void testDuplicateSynonyms() {
-        Map<String, String> config = new HashMap<>();
-        config.put("foo.bar", "baz");
-        config.put("foo.bar.deprecated", "derp");
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated"},
-            {"chicken", "foo.bar.deprecated"}
-        });
-        assertNotNull(newConfig);
-        assertEquals("baz", newConfig.get("foo.bar"));
-        assertEquals("derp", newConfig.get("chicken"));
-        assertNull(newConfig.get("foo.bar.deprecated"));
-    }
-
-    @Test
-    public void testMultipleDeprecations() {
-        Map<String, String> config = new HashMap<>();
-        config.put("foo.bar.deprecated", "derp");
-        config.put("foo.bar.even.more.deprecated", "very old configuration");
-        Map<String, String> newConfig = 
ConfigUtils.translateDeprecatedConfigs(config, new String[][]{
-            {"foo.bar", "foo.bar.deprecated", "foo.bar.even.more.deprecated"}
-        });
-        assertNotNull(newConfig);
-        assertEquals("derp", newConfig.get("foo.bar"));
-        assertNull(newConfig.get("foo.bar.deprecated"));
-        assertNull(newConfig.get("foo.bar.even.more.deprecated"));
-    }
-
     private static final ConfigDef CONFIG = new ConfigDef().
         define("myPassword", Type.PASSWORD, Importance.HIGH, "").
         define("myString", Type.STRING, Importance.HIGH, "").

Reply via email to