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/ git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1488370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ab4b602ca6
commit
297e916f41
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue