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
This commit is contained in:
parent
97c4668312
commit
6d4ab86412
|
@ -1529,6 +1529,8 @@ Release 0.23.7 - UNRELEASED
|
||||||
HADOOP-9209. Add shell command to dump file checksums (Todd Lipcon via
|
HADOOP-9209. Add shell command to dump file checksums (Todd Lipcon via
|
||||||
jeagles)
|
jeagles)
|
||||||
|
|
||||||
|
HADOOP-9374. Add tokens from -tokenCacheFile into UGI (daryn)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-8462. Native-code implementation of bzip2 codec. (Govind Kamat via
|
HADOOP-8462. Native-code implementation of bzip2 codec. (Govind Kamat via
|
||||||
|
|
|
@ -42,6 +42,8 @@ import org.apache.hadoop.classification.InterfaceStability;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
|
import org.apache.hadoop.security.Credentials;
|
||||||
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>GenericOptionsParser</code> is a utility to parse command line
|
* <code>GenericOptionsParser</code> is a utility to parse command line
|
||||||
|
@ -321,15 +323,17 @@ public class GenericOptionsParser {
|
||||||
String fileName = line.getOptionValue("tokenCacheFile");
|
String fileName = line.getOptionValue("tokenCacheFile");
|
||||||
// check if the local file exists
|
// check if the local file exists
|
||||||
FileSystem localFs = FileSystem.getLocal(conf);
|
FileSystem localFs = FileSystem.getLocal(conf);
|
||||||
Path p = new Path(fileName);
|
Path p = localFs.makeQualified(new Path(fileName));
|
||||||
if (!localFs.exists(p)) {
|
if (!localFs.exists(p)) {
|
||||||
throw new FileNotFoundException("File "+fileName+" does not exist.");
|
throw new FileNotFoundException("File "+fileName+" does not exist.");
|
||||||
}
|
}
|
||||||
if(LOG.isDebugEnabled()) {
|
if(LOG.isDebugEnabled()) {
|
||||||
LOG.debug("setting conf tokensFile: " + fileName);
|
LOG.debug("setting conf tokensFile: " + fileName);
|
||||||
}
|
}
|
||||||
conf.set("mapreduce.job.credentials.json", localFs.makeQualified(p)
|
UserGroupInformation.getCurrentUser().addCredentials(
|
||||||
.toString(), "from -tokenCacheFile command line option");
|
Credentials.readTokenStorageFile(p, conf));
|
||||||
|
conf.set("mapreduce.job.credentials.json", p.toString(),
|
||||||
|
"from -tokenCacheFile command line option");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,11 @@ import junit.framework.TestCase;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
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.Option;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
|
@ -164,13 +169,25 @@ public class TestGenericOptionsParser extends TestCase {
|
||||||
th instanceof FileNotFoundException);
|
th instanceof FileNotFoundException);
|
||||||
|
|
||||||
// create file
|
// create file
|
||||||
Path tmpPath = new Path(tmpFile.toString());
|
Path tmpPath = localFs.makeQualified(new Path(tmpFile.toString()));
|
||||||
localFs.create(tmpPath);
|
Token<?> token = new Token<AbstractDelegationTokenIdentifier>(
|
||||||
|
"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);
|
new GenericOptionsParser(conf, args);
|
||||||
String fileName = conf.get("mapreduce.job.credentials.json");
|
String fileName = conf.get("mapreduce.job.credentials.json");
|
||||||
assertNotNull("files is null", fileName);
|
assertNotNull("files is null", fileName);
|
||||||
assertEquals("files option does not match",
|
assertEquals("files option does not match", tmpPath.toString(), fileName);
|
||||||
localFs.makeQualified(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);
|
localFs.delete(new Path(testDir.getAbsolutePath()), true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue