You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by st...@apache.org on 2021/12/03 16:45:18 UTC

[hadoop] branch trunk updated: HADOOP-18021. Provide a public wrapper of Configuration#substituteVars (#3710)

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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new 47ea0d7  HADOOP-18021. Provide a public wrapper of Configuration#substituteVars (#3710)
47ea0d7 is described below

commit 47ea0d734fa290e2fac1b4d09f42a128c7294fd9
Author: Andras Gyori <gy...@gmail.com>
AuthorDate: Fri Dec 3 17:44:58 2021 +0100

    HADOOP-18021. Provide a public wrapper of Configuration#substituteVars (#3710)
    
    
    Contributed by Andras Gyori
---
 .../java/org/apache/hadoop/conf/Configuration.java   | 20 +++++++++++++++++++-
 .../org/apache/hadoop/conf/TestConfiguration.java    | 11 +++++++++++
 .../scheduler/capacity/UserWeights.java              |  2 +-
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
index 7ceaad3..28be4be 100755
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
@@ -1100,6 +1100,20 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
   }
 
   /**
+   * Provides a public wrapper over substituteVars in order to avoid compatibility issues.
+   * See HADOOP-18021 for further details.
+   *
+   * @param expr the literal value of a config key
+   * @return null if expr is null, otherwise the value resulting from expanding
+   * expr using the algorithm above.
+   * @throws IllegalArgumentException when more than
+   * {@link Configuration#MAX_SUBST} replacements are required
+   */
+  public String substituteCommonVariables(String expr) {
+    return substituteVars(expr);
+  }
+
+  /**
    * Attempts to repeatedly expand the value {@code expr} by replacing the
    * left-most substring of the form "${var}" in the following precedence order
    * <ol>
@@ -1120,13 +1134,17 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
    * If a cycle is detected then the original expr is returned. Loops
    * involving multiple substitutions are not detected.
    *
+   * In order not to introduce breaking changes (as Oozie for example contains a method with the
+   * same name and same signature) do not make this method public, use substituteCommonVariables
+   * in this case.
+   *
    * @param expr the literal value of a config key
    * @return null if expr is null, otherwise the value resulting from expanding
    * expr using the algorithm above.
    * @throws IllegalArgumentException when more than
    * {@link Configuration#MAX_SUBST} replacements are required
    */
-  public String substituteVars(String expr) {
+  private String substituteVars(String expr) {
     if (expr == null) {
       return null;
     }
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
index 3748eed..731fbc4 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
@@ -444,6 +444,17 @@ public class TestConfiguration {
     assertTrue(mock.getInt("my.int", -1) == 42);
   }
 
+  /**
+   * Checks if variable substitution is accessible via a public API.
+   */
+  @Test
+  public void testCommonVariableSubstitution() {
+    conf.set("intvar", String.valueOf(42));
+    String intVar = conf.substituteCommonVariables("${intvar}");
+
+    assertEquals("42", intVar);
+  }
+
   @Test
   public void testEnvDefault() throws IOException {
     Configuration mock = Mockito.spy(conf);
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/UserWeights.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/UserWeights.java
index 7bdc1bc..a9d7552 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/UserWeights.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/UserWeights.java
@@ -54,7 +54,7 @@ public final class UserWeights {
       if (m.find()) {
         String userName = item.getKey().replaceFirst("\\." + USER_WEIGHT, "");
         if (!userName.isEmpty()) {
-          String value = conf.substituteVars(item.getValue());
+          String value = conf.substituteCommonVariables(item.getValue());
           userWeights.data.put(userName, new Float(value));
         }
       }

---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org