hadoop-yarn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From junping...@apache.org
Subject svn commit: r1592295 - in /hadoop/common/branches/branch-2.4/hadoop-yarn-project: CHANGES.txt hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java
Date Sat, 03 May 2014 23:32:02 GMT
Author: junping_du
Date: Sat May  3 23:32:02 2014
New Revision: 1592295

URL: http://svn.apache.org/r1592295
Log:
Merge r1592198 from branch-2: YARN-1201. TestAMAuthorization fails with local hostname cannot
be resolved. (Wangda Tan via junping_du)

Modified:
    hadoop/common/branches/branch-2.4/hadoop-yarn-project/CHANGES.txt
    hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java

Modified: hadoop/common/branches/branch-2.4/hadoop-yarn-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.4/hadoop-yarn-project/CHANGES.txt?rev=1592295&r1=1592294&r2=1592295&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.4/hadoop-yarn-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2.4/hadoop-yarn-project/CHANGES.txt Sat May  3 23:32:02
2014
@@ -85,6 +85,9 @@ Release 2.4.1 - UNRELEASED
     YARN-1929. Fixed a deadlock in ResourceManager that occurs when failover
     happens right at the time of shutdown. (Karthik Kambatla via vinodkv)
 
+    YARN-1201. TestAMAuthorization fails with local hostname cannot be resolved. 
+    (Wangda Tan via junping_du)
+
 Release 2.4.0 - 2014-04-07 
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java?rev=1592295&r1=1592294&r2=1592295&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java
(original)
+++ hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java
Sat May  3 23:32:02 2014
@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.io.DataInputByteBuffer;
+import org.apache.hadoop.security.AccessControlException;
 import org.apache.hadoop.security.Credentials;
 import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.UserGroupInformation;
@@ -272,21 +273,62 @@ public class TestAMAuthorization {
       client.registerApplicationMaster(request);
       Assert.fail("Should fail with authorization error");
     } catch (Exception e) {
-      // Because there are no tokens, the request should be rejected as the
-      // server side will assume we are trying simple auth.
-      String expectedMessage = "";
-      if (UserGroupInformation.isSecurityEnabled()) {
-        expectedMessage = "Client cannot authenticate via:[TOKEN]";
+      if (isCause(AccessControlException.class, e)) {
+        // Because there are no tokens, the request should be rejected as the
+        // server side will assume we are trying simple auth.
+        String expectedMessage = "";
+        if (UserGroupInformation.isSecurityEnabled()) {
+          expectedMessage = "Client cannot authenticate via:[TOKEN]";
+        } else {
+          expectedMessage =
+              "SIMPLE authentication is not enabled.  Available:[TOKEN]";
+        }
+        Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage)); 
       } else {
-        expectedMessage =
-            "SIMPLE authentication is not enabled.  Available:[TOKEN]";
+        throw e;
       }
-      Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage));
     }
 
     // TODO: Add validation of invalid authorization when there's more data in
     // the AMRMToken
   }
+  
+  /**
+   * Identify if an expected throwable included in an exception stack. We use
+   * this because sometimes, an exception will be wrapped to another exception
+   * before thrown. Like,
+   * 
+   * <pre>
+   * {@code
+   * void methodA() throws IOException {
+   *   try {
+   *     // something
+   *   } catch (AccessControlException e) {
+   *     // do process
+   *     throw new IOException(e)
+   *   }
+   * }
+   * </pre>
+   * 
+   * So we cannot simply catch AccessControlException by using
+   * <pre>
+   * {@code
+   * try {
+   *   methodA()
+   * } catch (AccessControlException e) {
+   *   // do something
+   * }
+   * </pre>
+   * 
+   * This method is useful in such cases.
+   */
+  private static boolean isCause(
+      Class<? extends Throwable> expected,
+      Throwable e
+  ) {
+    return (e != null)
+        && (expected.isInstance(e) || isCause(expected, e.getCause()));
+  }
 
   private void waitForLaunchedState(RMAppAttempt attempt)
       throws InterruptedException {



Mime
View raw message