|
@@ -26,6 +26,7 @@ import static org.junit.Assert.fail;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
|
import org.apache.commons.logging.impl.Log4JLogger;
|
|
import org.apache.commons.logging.impl.Log4JLogger;
|
|
@@ -37,6 +38,7 @@ import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
|
+import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.log4j.Level;
|
|
import org.apache.log4j.Level;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
@@ -399,15 +401,40 @@ public class TestDistributedFileSystem {
|
|
RAN.setSeed(seed);
|
|
RAN.setSeed(seed);
|
|
|
|
|
|
final Configuration conf = getTestConfiguration();
|
|
final Configuration conf = getTestConfiguration();
|
|
|
|
+ conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
|
|
conf.set(DFSConfigKeys.DFS_DATANODE_HOST_NAME_KEY, "localhost");
|
|
conf.set(DFSConfigKeys.DFS_DATANODE_HOST_NAME_KEY, "localhost");
|
|
|
|
|
|
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
|
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
|
final FileSystem hdfs = cluster.getFileSystem();
|
|
final FileSystem hdfs = cluster.getFileSystem();
|
|
- final String hftpuri = "hftp://" + conf.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);
|
|
|
|
|
|
+
|
|
|
|
+ final String nnAddr = conf.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);
|
|
|
|
+ final UserGroupInformation current = UserGroupInformation.getCurrentUser();
|
|
|
|
+ final UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
|
|
|
|
+ current.getShortUserName() + "x", new String[]{"user"});
|
|
|
|
+
|
|
|
|
+ //hftp
|
|
|
|
+ final String hftpuri = "hftp://" + nnAddr;
|
|
System.out.println("hftpuri=" + hftpuri);
|
|
System.out.println("hftpuri=" + hftpuri);
|
|
- final FileSystem hftp = new Path(hftpuri).getFileSystem(conf);
|
|
|
|
|
|
+ final FileSystem hftp = ugi.doAs(
|
|
|
|
+ new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ @Override
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return new Path(hftpuri).getFileSystem(conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ //webhdfs
|
|
|
|
+ final String webhdfsuri = WebHdfsFileSystem.SCHEME + "://" + nnAddr;
|
|
|
|
+ System.out.println("webhdfsuri=" + webhdfsuri);
|
|
|
|
+ final FileSystem webhdfs = ugi.doAs(
|
|
|
|
+ new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ @Override
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return new Path(webhdfsuri).getFileSystem(conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- final String dir = "/filechecksum";
|
|
|
|
|
|
+ final Path dir = new Path("/filechecksum");
|
|
final int block_size = 1024;
|
|
final int block_size = 1024;
|
|
final int buffer_size = conf.getInt("io.file.buffer.size", 4096);
|
|
final int buffer_size = conf.getInt("io.file.buffer.size", 4096);
|
|
conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, 512);
|
|
conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, 512);
|
|
@@ -431,7 +458,8 @@ public class TestDistributedFileSystem {
|
|
//compute checksum
|
|
//compute checksum
|
|
final FileChecksum hdfsfoocs = hdfs.getFileChecksum(foo);
|
|
final FileChecksum hdfsfoocs = hdfs.getFileChecksum(foo);
|
|
System.out.println("hdfsfoocs=" + hdfsfoocs);
|
|
System.out.println("hdfsfoocs=" + hdfsfoocs);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ //hftp
|
|
final FileChecksum hftpfoocs = hftp.getFileChecksum(foo);
|
|
final FileChecksum hftpfoocs = hftp.getFileChecksum(foo);
|
|
System.out.println("hftpfoocs=" + hftpfoocs);
|
|
System.out.println("hftpfoocs=" + hftpfoocs);
|
|
|
|
|
|
@@ -439,6 +467,14 @@ public class TestDistributedFileSystem {
|
|
final FileChecksum qfoocs = hftp.getFileChecksum(qualified);
|
|
final FileChecksum qfoocs = hftp.getFileChecksum(qualified);
|
|
System.out.println("qfoocs=" + qfoocs);
|
|
System.out.println("qfoocs=" + qfoocs);
|
|
|
|
|
|
|
|
+ //webhdfs
|
|
|
|
+ final FileChecksum webhdfsfoocs = webhdfs.getFileChecksum(foo);
|
|
|
|
+ System.out.println("webhdfsfoocs=" + webhdfsfoocs);
|
|
|
|
+
|
|
|
|
+ final Path webhdfsqualified = new Path(webhdfsuri + dir, "foo" + n);
|
|
|
|
+ final FileChecksum webhdfs_qfoocs = webhdfs.getFileChecksum(webhdfsqualified);
|
|
|
|
+ System.out.println("webhdfs_qfoocs=" + webhdfs_qfoocs);
|
|
|
|
+
|
|
//write another file
|
|
//write another file
|
|
final Path bar = new Path(dir, "bar" + n);
|
|
final Path bar = new Path(dir, "bar" + n);
|
|
{
|
|
{
|
|
@@ -454,24 +490,40 @@ public class TestDistributedFileSystem {
|
|
assertEquals(hdfsfoocs.hashCode(), barhashcode);
|
|
assertEquals(hdfsfoocs.hashCode(), barhashcode);
|
|
assertEquals(hdfsfoocs, barcs);
|
|
assertEquals(hdfsfoocs, barcs);
|
|
|
|
|
|
|
|
+ //hftp
|
|
assertEquals(hftpfoocs.hashCode(), barhashcode);
|
|
assertEquals(hftpfoocs.hashCode(), barhashcode);
|
|
assertEquals(hftpfoocs, barcs);
|
|
assertEquals(hftpfoocs, barcs);
|
|
|
|
|
|
assertEquals(qfoocs.hashCode(), barhashcode);
|
|
assertEquals(qfoocs.hashCode(), barhashcode);
|
|
assertEquals(qfoocs, barcs);
|
|
assertEquals(qfoocs, barcs);
|
|
|
|
+
|
|
|
|
+ //webhdfs
|
|
|
|
+ assertEquals(webhdfsfoocs.hashCode(), barhashcode);
|
|
|
|
+ assertEquals(webhdfsfoocs, barcs);
|
|
|
|
+
|
|
|
|
+ assertEquals(webhdfs_qfoocs.hashCode(), barhashcode);
|
|
|
|
+ assertEquals(webhdfs_qfoocs, barcs);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ hdfs.setPermission(dir, new FsPermission((short)0));
|
|
{ //test permission error on hftp
|
|
{ //test permission error on hftp
|
|
- hdfs.setPermission(new Path(dir), new FsPermission((short)0));
|
|
|
|
try {
|
|
try {
|
|
- final String username = UserGroupInformation.getCurrentUser().getShortUserName() + "1";
|
|
|
|
- final HftpFileSystem hftp2 = cluster.getHftpFileSystemAs(username, conf, 0, "somegroup");
|
|
|
|
- hftp2.getFileChecksum(qualified);
|
|
|
|
|
|
+ hftp.getFileChecksum(qualified);
|
|
|
|
+ fail();
|
|
|
|
+ } catch(IOException ioe) {
|
|
|
|
+ FileSystem.LOG.info("GOOD: getting an exception", ioe);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ { //test permission error on webhdfs
|
|
|
|
+ try {
|
|
|
|
+ webhdfs.getFileChecksum(webhdfsqualified);
|
|
fail();
|
|
fail();
|
|
} catch(IOException ioe) {
|
|
} catch(IOException ioe) {
|
|
FileSystem.LOG.info("GOOD: getting an exception", ioe);
|
|
FileSystem.LOG.info("GOOD: getting an exception", ioe);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ hdfs.setPermission(dir, new FsPermission((short)0777));
|
|
}
|
|
}
|
|
cluster.shutdown();
|
|
cluster.shutdown();
|
|
}
|
|
}
|