HDFS-3268. FileContext API mishandles token service and incompatible with HA. Contributed by Daryn Sharp.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1326748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44ca988753
commit
2ae5006128
|
@ -397,6 +397,9 @@ Release 2.0.0 - UNRELEASED
|
||||||
|
|
||||||
HDFS-3280. DFSOutputStream.sync should not be synchronized (todd)
|
HDFS-3280. DFSOutputStream.sync should not be synchronized (todd)
|
||||||
|
|
||||||
|
HDFS-3268. FileContext API mishandles token service and incompatible with
|
||||||
|
HA (Daryn Sharp via todd)
|
||||||
|
|
||||||
BREAKDOWN OF HDFS-1623 SUBTASKS
|
BREAKDOWN OF HDFS-1623 SUBTASKS
|
||||||
|
|
||||||
HDFS-2179. Add fencing framework and mechanisms for NameNode HA. (todd)
|
HDFS-2179. Add fencing framework and mechanisms for NameNode HA. (todd)
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -391,11 +390,15 @@ public class Hdfs extends AbstractFileSystem {
|
||||||
return new Path(dfs.getLinkTarget(getUriPath(p)));
|
return new Path(dfs.getLinkTarget(getUriPath(p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCanonicalServiceName() {
|
||||||
|
return dfs.getCanonicalServiceName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override //AbstractFileSystem
|
@Override //AbstractFileSystem
|
||||||
public List<Token<?>> getDelegationTokens(String renewer) throws IOException {
|
public List<Token<?>> getDelegationTokens(String renewer) throws IOException {
|
||||||
Token<DelegationTokenIdentifier> result = dfs
|
Token<DelegationTokenIdentifier> result = dfs
|
||||||
.getDelegationToken(renewer == null ? null : new Text(renewer));
|
.getDelegationToken(renewer == null ? null : new Text(renewer));
|
||||||
result.setService(new Text(this.getCanonicalServiceName()));
|
|
||||||
List<Token<?>> tokenList = new ArrayList<Token<?>>();
|
List<Token<?>> tokenList = new ArrayList<Token<?>>();
|
||||||
tokenList.add(result);
|
tokenList.add(result);
|
||||||
return tokenList;
|
return tokenList;
|
||||||
|
|
|
@ -641,6 +641,16 @@ public class DFSClient implements java.io.Closeable {
|
||||||
return serverDefaults;
|
return serverDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a canonical token service name for this client's tokens. Null should
|
||||||
|
* be returned if the client is not using tokens.
|
||||||
|
* @return the token service for the client
|
||||||
|
*/
|
||||||
|
@InterfaceAudience.LimitedPrivate( { "HDFS" })
|
||||||
|
public String getCanonicalServiceName() {
|
||||||
|
return (dtService != null) ? dtService.toString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ClientProtocol#getDelegationToken(Text)
|
* @see ClientProtocol#getDelegationToken(Text)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -848,12 +848,7 @@ public class DistributedFileSystem extends FileSystem {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getCanonicalServiceName() {
|
public String getCanonicalServiceName() {
|
||||||
URI uri = getUri();
|
return dfs.getCanonicalServiceName();
|
||||||
if (HAUtil.isLogicalUri(getConf(), uri)) {
|
|
||||||
return HAUtil.buildTokenServiceForLogicalUri(uri).toString();
|
|
||||||
} else {
|
|
||||||
return super.getCanonicalServiceName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Collection;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.AbstractFileSystem;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||||
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||||
|
@ -223,6 +224,21 @@ public class TestDelegationTokensWithHA {
|
||||||
token.cancel(dfs.getConf());
|
token.cancel(dfs.getConf());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHdfsGetCanonicalServiceName() throws Exception {
|
||||||
|
Configuration conf = dfs.getConf();
|
||||||
|
URI haUri = HATestUtil.getLogicalUri(cluster);
|
||||||
|
AbstractFileSystem afs = AbstractFileSystem.createFileSystem(haUri, conf);
|
||||||
|
String haService = HAUtil.buildTokenServiceForLogicalUri(haUri).toString();
|
||||||
|
assertEquals(haService, afs.getCanonicalServiceName());
|
||||||
|
Token<?> token = afs.getDelegationTokens(
|
||||||
|
UserGroupInformation.getCurrentUser().getShortUserName()).get(0);
|
||||||
|
assertEquals(haService, token.getService().toString());
|
||||||
|
// make sure the logical uri is handled correctly
|
||||||
|
token.renew(conf);
|
||||||
|
token.cancel(conf);
|
||||||
|
}
|
||||||
|
|
||||||
enum TokenTestAction {
|
enum TokenTestAction {
|
||||||
RENEW, CANCEL;
|
RENEW, CANCEL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue