HDFS-8627. NPE thrown if unable to fetch token from Namenode (Contributed by J.Andreina)
This commit is contained in:
parent
6d99017f38
commit
7ba5bbac02
|
@ -338,6 +338,9 @@ Trunk (Unreleased)
|
||||||
|
|
||||||
HDFS-8412. Fix the test failures in HTTPFS. (umamahesh)
|
HDFS-8412. Fix the test failures in HTTPFS. (umamahesh)
|
||||||
|
|
||||||
|
HDFS-8627. NPE thrown if unable to fetch token from Namenode
|
||||||
|
(J.Andreina via vinayakumarb)
|
||||||
|
|
||||||
Release 2.8.0 - UNRELEASED
|
Release 2.8.0 - UNRELEASED
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
|
|
|
@ -176,14 +176,17 @@ public class DelegationTokenFetcher {
|
||||||
final String renewer, final Path tokenFile)
|
final String renewer, final Path tokenFile)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Token<?> token = fs.getDelegationToken(renewer);
|
Token<?> token = fs.getDelegationToken(renewer);
|
||||||
|
if (null != token) {
|
||||||
|
Credentials cred = new Credentials();
|
||||||
|
cred.addToken(token.getKind(), token);
|
||||||
|
cred.writeTokenStorageFile(tokenFile, conf);
|
||||||
|
|
||||||
Credentials cred = new Credentials();
|
if (LOG.isDebugEnabled()) {
|
||||||
cred.addToken(token.getKind(), token);
|
LOG.debug("Fetched token " + fs.getUri() + " for " +
|
||||||
cred.writeTokenStorageFile(tokenFile, conf);
|
token.getService() + " into " + tokenFile);
|
||||||
|
}
|
||||||
if (LOG.isDebugEnabled()) {
|
} else {
|
||||||
LOG.debug("Fetched token " + fs.getUri() + " for " + token.getService()
|
System.err.println("ERROR: Failed to fetch token from " + fs.getUri());
|
||||||
+ " into " + tokenFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,4 +90,19 @@ public class TestDelegationTokenFetcher {
|
||||||
DelegationTokenFetcher.cancelTokens(conf, p);
|
DelegationTokenFetcher.cancelTokens(conf, p);
|
||||||
Assert.assertEquals(testToken, FakeRenewer.getLastCanceled());
|
Assert.assertEquals(testToken, FakeRenewer.getLastCanceled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If token returned is null, saveDelegationToken should not
|
||||||
|
* throw nullPointerException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReturnedTokenIsNull() throws Exception {
|
||||||
|
WebHdfsFileSystem fs = mock(WebHdfsFileSystem.class);
|
||||||
|
doReturn(null).when(fs).getDelegationToken(anyString());
|
||||||
|
Path p = new Path(f.getRoot().getAbsolutePath(), tokenFile);
|
||||||
|
DelegationTokenFetcher.saveDelegationToken(conf, fs, null, p);
|
||||||
|
// When Token returned is null, TokenFile should not exist
|
||||||
|
Assert.assertFalse(p.getFileSystem(conf).exists(p));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue