You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by bo...@apache.org on 2010/06/23 23:59:44 UTC
svn commit: r957364 - in /hadoop/hdfs/trunk: CHANGES.txt
src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java
src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java
Author: boryas
Date: Wed Jun 23 21:59:43 2010
New Revision: 957364
URL: http://svn.apache.org/viewvc?rev=957364&view=rev
Log:
HDFS-1036. in DelegationTokenFetch dfs.getURI returns no port
Modified:
hadoop/hdfs/trunk/CHANGES.txt
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java
Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=957364&r1=957363&r2=957364&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed Jun 23 21:59:43 2010
@@ -94,6 +94,8 @@ Trunk (unreleased changes)
HDFS-1192. refreshSuperUserGroupsConfiguration should use server side
configuration for the refresh (for HADOOP-6815) (boryas)
+ HDFS-1036. in DelegationTokenFetch dfs.getURI returns no port (boryas)
+
Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java?rev=957364&r1=957363&r2=957364&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java Wed Jun 23 21:59:43 2010
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.security.PrivilegedExceptionAction;
@@ -31,11 +32,11 @@ import org.apache.hadoop.classification.
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.DistributedFileSystem;
-import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.server.namenode.DelegationTokenServlet;
import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.security.TokenStorage;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
@@ -55,6 +56,7 @@ public class DelegationTokenFetcher {
private final DistributedFileSystem dfs;
private final UserGroupInformation ugi;
private final DataOutputStream out;
+ private final Configuration conf;
/**
* Command-line interface
@@ -87,7 +89,7 @@ public class DelegationTokenFetcher {
out = new DataOutputStream(new FileOutputStream(args[0]));
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
- new DelegationTokenFetcher(dfs, out, ugi).go();
+ new DelegationTokenFetcher(dfs, out, ugi, conf).go();
out.flush();
System.out.println("Succesfully wrote token of size " +
@@ -105,10 +107,11 @@ public class DelegationTokenFetcher {
}
public DelegationTokenFetcher(DistributedFileSystem dfs,
- DataOutputStream out, UserGroupInformation ugi) {
+ DataOutputStream out, UserGroupInformation ugi, Configuration conf) {
checkNotNull("dfs", dfs); this.dfs = dfs;
checkNotNull("out", out); this.out = out;
checkNotNull("ugi", ugi); this.ugi = ugi;
+ checkNotNull("conf",conf); this.conf = conf;
}
private void checkNotNull(String s, Object o) {
@@ -122,9 +125,9 @@ public class DelegationTokenFetcher {
dfs.getDelegationToken(new Text(fullName));
// Reconstruct the ip:port of the Namenode
+ URI uri = FileSystem.getDefaultUri(conf);
String nnAddress =
- InetAddress.getByName(dfs.getUri().getHost()).getHostAddress()
- + ":" + dfs.getUri().getPort();
+ InetAddress.getByName(uri.getHost()).getHostAddress() + ":" + uri.getPort();
token.setService(new Text(nnAddress));
TokenStorage ts = new TokenStorage();
Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java?rev=957364&r1=957363&r2=957364&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java (original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/tools/TestDelegationTokenFetcher.java Wed Jun 23 21:59:43 2010
@@ -28,6 +28,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.URI;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.tools.DelegationTokenFetcher;
@@ -43,12 +45,14 @@ public class TestDelegationTokenFetcher
private DistributedFileSystem dfs;
private DataOutputStream out;
private UserGroupInformation ugi;
+ private Configuration conf;
@Before
public void init() {
dfs = mock(DistributedFileSystem.class);
out = mock(DataOutputStream.class);
ugi = mock(UserGroupInformation.class);
+ conf = new Configuration();
}
/**
@@ -60,6 +64,8 @@ public class TestDelegationTokenFetcher
final String LONG_NAME = "TheDoctor@TARDIS";
final String SHORT_NAME = "TheDoctor";
final String SERVICE_VALUE = "localhost:2005";
+ URI uri = new URI("hdfs://" + SERVICE_VALUE);
+ FileSystem.setDefaultUri(conf, uri);
// Mock out the user's long and short names.
when(ugi.getUserName()).thenReturn(LONG_NAME);
@@ -69,15 +75,11 @@ public class TestDelegationTokenFetcher
// for this particular user.
Token<DelegationTokenIdentifier> t = new Token<DelegationTokenIdentifier>();
when(dfs.getDelegationToken(eq(new Text(LONG_NAME)))).thenReturn(t);
-
- // Mock the NN's URI, which is stored as the service value
- URI uri = new URI("hdfs://" + SERVICE_VALUE);
- when(dfs.getUri()).thenReturn(uri);
// Now, actually let the TokenFetcher go fetch the token.
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
out = new DataOutputStream(baos);
- new DelegationTokenFetcher(dfs, out, ugi).go();
+ new DelegationTokenFetcher(dfs, out, ugi, conf).go();
// now read the data back in and verify correct values
TokenStorage ts = new TokenStorage();
@@ -93,7 +95,7 @@ public class TestDelegationTokenFetcher
private void checkWithNullParam(String s) {
try {
- new DelegationTokenFetcher(dfs, out, ugi);
+ new DelegationTokenFetcher(dfs, out, ugi, conf);
} catch (IllegalArgumentException iae) {
assertEquals("Expected exception message not received",
s + " cannot be null.", iae.getMessage());