From 6d4ab86412dbe763e53368e267bc068e6cde075b Mon Sep 17 00:00:00 2001 From: Daryn Sharp Date: Thu, 7 Mar 2013 19:22:44 +0000 Subject: [PATCH] HADOOP-9374. Add tokens from -tokenCacheFile into UGI (daryn) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1454019 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 2 ++ .../hadoop/util/GenericOptionsParser.java | 10 +++++--- .../hadoop/util/TestGenericOptionsParser.java | 25 ++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 5436ce8d97..b2fd8d3c9a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1529,6 +1529,8 @@ Release 0.23.7 - UNRELEASED HADOOP-9209. Add shell command to dump file checksums (Todd Lipcon via jeagles) + HADOOP-9374. Add tokens from -tokenCacheFile into UGI (daryn) + OPTIMIZATIONS HADOOP-8462. Native-code implementation of bzip2 codec. (Govind Kamat via diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java index b3eabf0452..a0cb6cccc1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java @@ -42,6 +42,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.security.UserGroupInformation; /** * GenericOptionsParser is a utility to parse command line @@ -321,15 +323,17 @@ private void processGeneralOptions(Configuration conf, String fileName = line.getOptionValue("tokenCacheFile"); // check if the local file exists FileSystem localFs = FileSystem.getLocal(conf); - Path p = new Path(fileName); + Path p = localFs.makeQualified(new Path(fileName)); if (!localFs.exists(p)) { throw new FileNotFoundException("File "+fileName+" does not exist."); } if(LOG.isDebugEnabled()) { LOG.debug("setting conf tokensFile: " + fileName); } - conf.set("mapreduce.job.credentials.json", localFs.makeQualified(p) - .toString(), "from -tokenCacheFile command line option"); + UserGroupInformation.getCurrentUser().addCredentials( + Credentials.readTokenStorageFile(p, conf)); + conf.set("mapreduce.job.credentials.json", p.toString(), + "from -tokenCacheFile command line option"); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java index 9b767a812b..b58bb190b4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java @@ -27,6 +27,11 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.token.Token; +import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; @@ -164,13 +169,25 @@ public void testTokenCacheOption() throws IOException { th instanceof FileNotFoundException); // create file - Path tmpPath = new Path(tmpFile.toString()); - localFs.create(tmpPath); + Path tmpPath = localFs.makeQualified(new Path(tmpFile.toString())); + Token token = new Token( + "identifier".getBytes(), "password".getBytes(), + new Text("token-kind"), new Text("token-service")); + Credentials creds = new Credentials(); + creds.addToken(new Text("token-alias"), token); + creds.writeTokenStorageFile(tmpPath, conf); + new GenericOptionsParser(conf, args); String fileName = conf.get("mapreduce.job.credentials.json"); assertNotNull("files is null", fileName); - assertEquals("files option does not match", - localFs.makeQualified(tmpPath).toString(), fileName); + assertEquals("files option does not match", tmpPath.toString(), fileName); + + Credentials ugiCreds = + UserGroupInformation.getCurrentUser().getCredentials(); + assertEquals(1, ugiCreds.numberOfTokens()); + Token ugiToken = ugiCreds.getToken(new Text("token-alias")); + assertNotNull(ugiToken); + assertEquals(token, ugiToken); localFs.delete(new Path(testDir.getAbsolutePath()), true); }