瀏覽代碼

Merged r1173843 from branch-0.20-security for HADOOP-7661.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-205@1173854 13f79535-47bb-0310-9956-ffa450edef68
Jitendra Nath Pandey 14 年之前
父節點
當前提交
ec9fe3f035

+ 3 - 0
CHANGES.txt

@@ -166,6 +166,9 @@ Release 0.20.205.0 - 2011.09.12
     HADOOP-7615. Fixes to have contrib jars in the HADOOP_CLASSPATH
     for the binary layout case. (Eric Yang via ddas) 
 
+    HADOOP-7661. FileSystem.getCanonicalServiceName throws NPE for any 
+    file system uri that doesn't have an authority. (jitendra)
+
   IMPROVEMENTS
 
     MAPREDUCE-2187. Reporter sends progress during sort/merge. (Anupam Seth via

+ 6 - 3
src/core/org/apache/hadoop/fs/FileSystem.java

@@ -167,11 +167,14 @@ public abstract class FileSystem extends Configured implements Closeable {
   }
 
   /**
-   * Get a canonical name for this file system.
-   * @return a URI string that uniquely identifies this file system
+   * Get a canonical name for this file system. It returns the uri of the file
+   * system unless overridden by a FileSystem implementation. File Systems with
+   * a valid authority can choose to return host:port or ip:port.
+   * 
+   * @return A string that uniquely identifies this file system
    */
   public String getCanonicalServiceName() {
-    return SecurityUtil.buildDTServiceName(getUri(), getDefaultPort());
+    return getUri().toString();
   }
   
   /** @deprecated call #getUri() instead.*/

+ 6 - 0
src/core/org/apache/hadoop/fs/FilterFileSystem.java

@@ -23,6 +23,7 @@ import java.net.URI;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.util.Progressable;
 
 /****************************************************************
@@ -68,6 +69,11 @@ public class FilterFileSystem extends FileSystem {
   public URI getUri() {
     return fs.getUri();
   }
+  
+  @Override
+  public String getCanonicalServiceName() {
+    return fs.getCanonicalServiceName();
+  }
 
   /** @deprecated call #getUri() instead.*/
   public String getName() {

+ 6 - 0
src/hdfs/org/apache/hadoop/hdfs/DistributedFileSystem.java

@@ -39,6 +39,7 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.DFSClient.DFSOutputStream;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.security.AccessControlException;
+import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.security.token.SecretManager.InvalidToken;
 import org.apache.hadoop.util.Progressable;
@@ -65,6 +66,11 @@ public class DistributedFileSystem extends FileSystem {
   public DistributedFileSystem() {
   }
 
+  @Override
+  public String getCanonicalServiceName() {
+    return SecurityUtil.buildDTServiceName(getUri(), getDefaultPort());
+  }
+  
   /** @deprecated */
   public DistributedFileSystem(InetSocketAddress namenode,
     Configuration conf) throws IOException {

+ 7 - 0
src/test/org/apache/hadoop/fs/TestLocalFileSystem.java

@@ -19,6 +19,7 @@ package org.apache.hadoop.fs;
 
 import org.apache.hadoop.conf.Configuration;
 import java.io.*;
+
 import junit.framework.*;
 
 /**
@@ -153,4 +154,10 @@ public class TestLocalFileSystem extends TestCase {
     assertEquals(path.makeQualified(fs), status.getPath());
     cleanupFile(fs, path);
   }
+  
+  public void testGetCanonicalServiceName() throws IOException {
+    Configuration conf = new Configuration();
+    FileSystem fs = FileSystem.getLocal(conf);
+    assertEquals(fs.getUri().toString(), fs.getCanonicalServiceName());
+  }
 }