Browse Source

YARN-5833. Add validation to ensure default ports are unique in Configuration. (Konstantinos Karanasos via Subru).

Subru Krishnan 8 years ago
parent
commit
29e3b3417c

+ 47 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationFieldsBase.java

@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.conf;
 
+import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -146,6 +147,14 @@ public abstract class TestConfigurationFieldsBase {
    */
   private Set<String> xmlFieldsMissingInConfiguration = null;
 
+  /**
+   * A set of strings used to check for collision of default values.
+   * For each of the set's strings, the default values containing that string
+   * in their name should not coincide.
+   */
+  @SuppressWarnings("checkstyle:visibilitymodifier")
+  protected Set<String> filtersForDefaultValueCollisionCheck = new HashSet<>();
+
   /**
    * Member variable for debugging base class operation
    */
@@ -719,4 +728,42 @@ public abstract class TestConfigurationFieldsBase {
     System.out.println("=====");
     System.out.println();
   }
+
+  /**
+   * For each specified string, get the default parameter values whose names
+   * contain the string. Then check whether any of these default values collide.
+   * This is, for example, useful to make sure there is no collision of default
+   * ports across different services.
+   */
+  @Test
+  public void testDefaultValueCollision() {
+    for (String filter : filtersForDefaultValueCollisionCheck) {
+      System.out.println("Checking if any of the default values whose name " +
+          "contains string \"" + filter + "\" collide.");
+
+      // Map from filtered default value to name of the corresponding parameter.
+      Map<String, String> filteredValues = new HashMap<>();
+
+      int valuesChecked = 0;
+      for (Map.Entry<String, String> ent :
+          configurationDefaultVariables.entrySet()) {
+        // Apply the name filter to the default parameters.
+        if (ent.getKey().contains(filter)) {
+          // Check only for numerical values.
+          if (StringUtils.isNumeric(ent.getValue())) {
+            String crtValue =
+                filteredValues.putIfAbsent(ent.getValue(), ent.getKey());
+            assertTrue("Parameters " + ent.getKey() + " and " + crtValue +
+                " are using the same default value!", crtValue == null);
+          }
+          valuesChecked++;
+        }
+      }
+
+      System.out.println(
+          "Checked " + valuesChecked + " default values for collision.");
+    }
+
+
+  }
 }

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

@@ -1744,7 +1744,7 @@ public class YarnConfiguration extends Configuration {
 
   public static final String AMRM_PROXY_ADDRESS = NM_PREFIX
       + "amrmproxy.address";
-  public static final int DEFAULT_AMRM_PROXY_PORT = 8048;
+  public static final int DEFAULT_AMRM_PROXY_PORT = 8049;
   public static final String DEFAULT_AMRM_PROXY_ADDRESS = "0.0.0.0:"
       + DEFAULT_AMRM_PROXY_PORT;
 

+ 11 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfigurationFields.java

@@ -147,5 +147,16 @@ public class TestYarnConfigurationFields extends TestConfigurationFieldsBase {
 
     // Currently defined in RegistryConstants/core-site.xml
     xmlPrefixToSkipCompare.add("hadoop.registry");
+
+    // Add the filters used for checking for collision of default values.
+    initDefaultValueCollisionCheck();
+  }
+
+  /**
+   * Add filters used to perform the check of default values collision by
+   * {@link TestConfigurationFieldsBase#filtersForDefaultValueCollisionCheck}.
+   */
+  private void initDefaultValueCollisionCheck() {
+    filtersForDefaultValueCollisionCheck.add("_PORT");
   }
 }