You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by vi...@apache.org on 2013/05/31 21:48:30 UTC

svn commit: r1488370 - in /hadoop/common/branches/branch-2/hadoop-mapreduce-project: ./ hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/ hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/te...

Author: vinodkv
Date: Fri May 31 19:48:30 2013
New Revision: 1488370

URL: http://svn.apache.org/r1488370
Log:
MAPREDUCE-5275. Bring back a couple of APIs in mapreduce.security.TokenCache for binary compatibility with 1.x mapreduce APIs. Contributed by Mayank Bansal.
svn merge --ignore-ancestry -c 1488369 ../../trunk/

Modified:
    hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/TokenCache.java
    hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java

Modified: hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt?rev=1488370&r1=1488369&r2=1488370&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt Fri May 31 19:48:30 2013
@@ -115,6 +115,9 @@ Release 2.0.5-beta - UNRELEASED
     MAPREDUCE-5176. Add annotation for tagging tasks as responsive to
     preemption. (Carlo Curino, cdouglas)
 
+    MAPREDUCE-5275. Bring back a couple of APIs in mapreduce.security.TokenCache
+    for binary compatibility with 1.x mapreduce APIs. (Mayank Bansal via vinodkv)
+
   OPTIMIZATIONS
 
     MAPREDUCE-4974. Optimising the LineRecordReader initialize() method 

Modified: hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/TokenCache.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/TokenCache.java?rev=1488370&r1=1488369&r2=1488370&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/TokenCache.java (original)
+++ hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/security/TokenCache.java Fri May 31 19:48:30 2013
@@ -177,6 +177,19 @@ public class TokenCache {
     }
     return ts;
   }
+  
+  /**
+   * load job token from a file
+   * 
+   * @param conf
+   * @throws IOException
+   */
+  @InterfaceAudience.Private
+  public static Credentials loadTokens(String jobTokenFile, Configuration conf)
+      throws IOException {
+    return loadTokens(jobTokenFile, new JobConf(conf));
+  }
+  
   /**
    * store job token
    * @param t
@@ -205,4 +218,16 @@ public class TokenCache {
   public static byte[] getShuffleSecretKey(Credentials credentials) {
     return getSecretKey(credentials, SHUFFLE_TOKEN);
   }
+
+  /**
+   * 
+   * @param namenode
+   * @return delegation token
+   */
+  public static
+      Token<?> getDelegationToken(
+          Credentials credentials, String namenode) {
+    return (Token<?>) credentials.getToken(new Text(
+      namenode));
+  }
 }

Modified: hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java?rev=1488370&r1=1488369&r2=1488370&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java (original)
+++ hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java Fri May 31 19:48:30 2013
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.*;
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
@@ -168,4 +169,28 @@ public class TestTokenCache {
     TokenCache.cleanUpTokenReferral(conf);
     assertNull(conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY));
   }
+  
+  @Test
+  public void testGetTokensForNamenodes() throws IOException,
+      URISyntaxException {
+    Path TEST_ROOT_DIR =
+        new Path(System.getProperty("test.build.data", "test/build/data"));
+    // ick, but need fq path minus file:/
+    String binaryTokenFile =
+        FileSystem.getLocal(conf)
+          .makeQualified(new Path(TEST_ROOT_DIR, "tokenFile")).toUri()
+          .getPath();
+
+    MockFileSystem fs1 = createFileSystemForServiceName("service1");
+    Credentials creds = new Credentials();
+    Token<?> token1 = fs1.getDelegationToken(renewer);
+    creds.addToken(token1.getService(), token1);
+    // wait to set, else the obtain tokens call above will fail with FNF
+    conf.set(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY, binaryTokenFile);
+    creds.writeTokenStorageFile(new Path(binaryTokenFile), conf);
+    TokenCache.obtainTokensForNamenodesInternal(fs1, creds, conf);
+    String fs_addr = fs1.getCanonicalServiceName();
+    Token<?> nnt = TokenCache.getDelegationToken(creds, fs_addr);
+    assertNotNull("Token for nn is null", nnt);
+  }
 }
\ No newline at end of file