|
@@ -155,13 +155,13 @@ public class TestDFSShell {
|
|
|
assertTrue(f1.exists());
|
|
|
assertTrue(f1.isFile());
|
|
|
assertEquals(0L, f1.length());
|
|
|
-
|
|
|
+
|
|
|
//copy to remote
|
|
|
final Path root = mkdir(dfs, new Path("/test/zeroSizeFile"));
|
|
|
final Path remotef = new Path(root, "dst");
|
|
|
show("copy local " + f1 + " to remote " + remotef);
|
|
|
dfs.copyFromLocalFile(false, false, new Path(f1.getPath()), remotef);
|
|
|
-
|
|
|
+
|
|
|
//getBlockSize() should not throw exception
|
|
|
show("Block size = " + dfs.getFileStatus(remotef).getBlockSize());
|
|
|
|
|
@@ -172,7 +172,7 @@ public class TestDFSShell {
|
|
|
assertTrue(f2.exists());
|
|
|
assertTrue(f2.isFile());
|
|
|
assertEquals(0L, f2.length());
|
|
|
-
|
|
|
+
|
|
|
f1.delete();
|
|
|
f2.delete();
|
|
|
} finally {
|
|
@@ -180,13 +180,13 @@ public class TestDFSShell {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testRecursiveRm() throws IOException {
|
|
|
Configuration conf = new HdfsConfiguration();
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
|
|
FileSystem fs = cluster.getFileSystem();
|
|
|
- assertTrue("Not a HDFS: " + fs.getUri(),
|
|
|
+ assertTrue("Not a HDFS: " + fs.getUri(),
|
|
|
fs instanceof DistributedFileSystem);
|
|
|
try {
|
|
|
fs.mkdirs(new Path(new Path("parent"), "child"));
|
|
@@ -201,12 +201,12 @@ public class TestDFSShell {
|
|
|
} catch(IOException e) {
|
|
|
assert(false);
|
|
|
}
|
|
|
- } finally {
|
|
|
+ } finally {
|
|
|
try { fs.close();}catch(IOException e){};
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testDu() throws IOException {
|
|
|
int replication = 2;
|
|
@@ -220,7 +220,7 @@ public class TestDFSShell {
|
|
|
System.setOut(psOut);
|
|
|
FsShell shell = new FsShell();
|
|
|
shell.setConf(conf);
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
Path myPath = new Path("/test/dir");
|
|
|
assertTrue(fs.mkdirs(myPath));
|
|
@@ -235,7 +235,7 @@ public class TestDFSShell {
|
|
|
Long myFileDiskUsed = myFileLength * replication;
|
|
|
Long myFile2Length = fs.getFileStatus(myFile2).getLen();
|
|
|
Long myFile2DiskUsed = myFile2Length * replication;
|
|
|
-
|
|
|
+
|
|
|
String[] args = new String[2];
|
|
|
args[0] = "-du";
|
|
|
args[1] = "/test/dir";
|
|
@@ -254,7 +254,7 @@ public class TestDFSShell {
|
|
|
assertThat(returnString, containsString(myFileDiskUsed.toString()));
|
|
|
assertThat(returnString, containsString(myFile2Length.toString()));
|
|
|
assertThat(returnString, containsString(myFile2DiskUsed.toString()));
|
|
|
-
|
|
|
+
|
|
|
// Check that -du -s reports the state of the snapshot
|
|
|
String snapshotName = "ss1";
|
|
|
Path snapshotPath = new Path(myPath, ".snapshot/" + snapshotName);
|
|
@@ -306,7 +306,7 @@ public class TestDFSShell {
|
|
|
System.setOut(psBackup);
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Test (timeout = 30000)
|
|
@@ -321,15 +321,15 @@ public class TestDFSShell {
|
|
|
try {
|
|
|
// remove left over crc files:
|
|
|
new File(TEST_ROOT_DIR, ".f1.crc").delete();
|
|
|
- new File(TEST_ROOT_DIR, ".f2.crc").delete();
|
|
|
+ new File(TEST_ROOT_DIR, ".f2.crc").delete();
|
|
|
final File f1 = createLocalFile(new File(TEST_ROOT_DIR, "f1"));
|
|
|
final File f2 = createLocalFile(new File(TEST_ROOT_DIR, "f2"));
|
|
|
-
|
|
|
+
|
|
|
final Path root = mkdir(dfs, new Path("/test/put"));
|
|
|
final Path dst = new Path(root, "dst");
|
|
|
-
|
|
|
+
|
|
|
show("begin");
|
|
|
-
|
|
|
+
|
|
|
final Thread copy2ndFileThread = new Thread() {
|
|
|
@Override
|
|
|
public void run() {
|
|
@@ -344,13 +344,13 @@ public class TestDFSShell {
|
|
|
assertTrue(false);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
//use SecurityManager to pause the copying of f1 and begin copying f2
|
|
|
SecurityManager sm = System.getSecurityManager();
|
|
|
System.out.println("SecurityManager = " + sm);
|
|
|
System.setSecurityManager(new SecurityManager() {
|
|
|
private boolean firstTime = true;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void checkPermission(Permission perm) {
|
|
|
if (firstTime) {
|
|
@@ -359,7 +359,7 @@ public class TestDFSShell {
|
|
|
String s = "" + Arrays.asList(t.getStackTrace());
|
|
|
if (s.contains("FileUtil.copyContent")) {
|
|
|
//pause at FileUtil.copyContent
|
|
|
-
|
|
|
+
|
|
|
firstTime = false;
|
|
|
copy2ndFileThread.start();
|
|
|
try {Thread.sleep(5000);} catch (InterruptedException e) {}
|
|
@@ -371,7 +371,7 @@ public class TestDFSShell {
|
|
|
show("copy local " + f1 + " to remote " + dst);
|
|
|
dfs.copyFromLocalFile(false, false, new Path(f1.getPath()), dst);
|
|
|
show("done");
|
|
|
-
|
|
|
+
|
|
|
try {copy2ndFileThread.join();} catch (InterruptedException e) { }
|
|
|
System.setSecurityManager(sm);
|
|
|
|
|
@@ -381,8 +381,8 @@ public class TestDFSShell {
|
|
|
srcs[0] = new Path(f1.getPath());
|
|
|
srcs[1] = new Path(f2.getPath());
|
|
|
dfs.copyFromLocalFile(false, false, srcs, destmultiple);
|
|
|
- srcs[0] = new Path(destmultiple,"f1");
|
|
|
- srcs[1] = new Path(destmultiple,"f2");
|
|
|
+ srcs[0] = new Path(destmultiple,"f1");
|
|
|
+ srcs[1] = new Path(destmultiple,"f2");
|
|
|
assertTrue(dfs.exists(srcs[0]));
|
|
|
assertTrue(dfs.exists(srcs[1]));
|
|
|
|
|
@@ -492,7 +492,7 @@ public class TestDFSShell {
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
returned = out.toString();
|
|
|
assertEquals(" -mkdir returned 1 ", 1, ret);
|
|
|
- assertTrue(" -mkdir returned File exists",
|
|
|
+ assertTrue(" -mkdir returned File exists",
|
|
|
(returned.lastIndexOf("File exists") != -1));
|
|
|
Path testFile = new Path("/testfile");
|
|
|
OutputStream outtmp = srcFs.create(testFile);
|
|
@@ -520,7 +520,7 @@ public class TestDFSShell {
|
|
|
argv[2] = "/testfiletest";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
returned = out.toString();
|
|
|
- assertTrue("no output from rename",
|
|
|
+ assertTrue("no output from rename",
|
|
|
(returned.lastIndexOf("Renamed") == -1));
|
|
|
out.reset();
|
|
|
argv[0] = "-mv";
|
|
@@ -557,7 +557,7 @@ public class TestDFSShell {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testURIPaths() throws Exception {
|
|
|
Configuration srcConf = new HdfsConfiguration();
|
|
@@ -580,14 +580,14 @@ public class TestDFSShell {
|
|
|
argv[1] = dstFs.getUri().toString() + "/";
|
|
|
int ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals("ls works on remote uri ", 0, ret);
|
|
|
- //check for rm -r
|
|
|
+ //check for rm -r
|
|
|
dstFs.mkdirs(new Path("/hadoopdir"));
|
|
|
argv = new String[2];
|
|
|
argv[0] = "-rmr";
|
|
|
argv[1] = dstFs.getUri().toString() + "/hadoopdir";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals("-rmr works on remote uri " + argv[1], 0, ret);
|
|
|
- //check du
|
|
|
+ //check du
|
|
|
argv[0] = "-du";
|
|
|
argv[1] = dstFs.getUri().toString() + "/";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
@@ -601,14 +601,14 @@ public class TestDFSShell {
|
|
|
argv[2] = dstFs.getUri().toString() + "/furi";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals(" put is working ", 0, ret);
|
|
|
- //check cp
|
|
|
+ //check cp
|
|
|
argv[0] = "-cp";
|
|
|
argv[1] = dstFs.getUri().toString() + "/furi";
|
|
|
argv[2] = srcFs.getUri().toString() + "/furi";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals(" cp is working ", 0, ret);
|
|
|
assertTrue(srcFs.exists(new Path("/furi")));
|
|
|
- //check cat
|
|
|
+ //check cat
|
|
|
argv = new String[2];
|
|
|
argv[0] = "-cat";
|
|
|
argv[1] = dstFs.getUri().toString() + "/furi";
|
|
@@ -626,7 +626,7 @@ public class TestDFSShell {
|
|
|
confirmOwner(null, "herbivores", dstFs, parent, path);
|
|
|
runCmd(shell, "-chown", "-R", ":reptiles", dstFs.getUri().toString() + "/");
|
|
|
confirmOwner(null, "reptiles", dstFs, root, parent, path);
|
|
|
- //check if default hdfs:/// works
|
|
|
+ //check if default hdfs:/// works
|
|
|
argv[0] = "-cat";
|
|
|
argv[1] = "hdfs:///furi";
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
@@ -757,7 +757,7 @@ public class TestDFSShell {
|
|
|
assertTrue("Output doesn't match input",
|
|
|
Arrays.equals(writebytes, out.toByteArray()));
|
|
|
out.reset();
|
|
|
-
|
|
|
+
|
|
|
// Test a plain text.
|
|
|
OutputStream pout = fs.create(new Path(root, "file.txt"));
|
|
|
writebytes = "bar".getBytes();
|
|
@@ -805,8 +805,8 @@ public class TestDFSShell {
|
|
|
}
|
|
|
|
|
|
File localroot = new File(TEST_ROOT_DIR, "copyToLocal");
|
|
|
- File localroot2 = new File(TEST_ROOT_DIR, "copyToLocal2");
|
|
|
-
|
|
|
+ File localroot2 = new File(TEST_ROOT_DIR, "copyToLocal2");
|
|
|
+
|
|
|
File f1 = new File(localroot, "f1");
|
|
|
assertTrue("Copying failed.", f1.isFile());
|
|
|
|
|
@@ -821,9 +821,9 @@ public class TestDFSShell {
|
|
|
|
|
|
File f4 = new File(sub, "f4");
|
|
|
assertTrue("Copying failed.", f4.isFile());
|
|
|
-
|
|
|
+
|
|
|
File f5 = new File(localroot2, "f1");
|
|
|
- assertTrue("Copying failed.", f5.isFile());
|
|
|
+ assertTrue("Copying failed.", f5.isFile());
|
|
|
|
|
|
f1.delete();
|
|
|
f2.delete();
|
|
@@ -836,12 +836,12 @@ public class TestDFSShell {
|
|
|
// destination files
|
|
|
{
|
|
|
String[] args = {"-copyToLocal", "nosuchfile", TEST_ROOT_DIR};
|
|
|
- try {
|
|
|
+ try {
|
|
|
assertEquals(1, shell.run(args));
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run " +
|
|
|
e.getLocalizedMessage());
|
|
|
- }
|
|
|
+ }
|
|
|
File f6 = new File(TEST_ROOT_DIR, "nosuchfile");
|
|
|
assertTrue(!f6.exists());
|
|
|
}
|
|
@@ -867,7 +867,7 @@ public class TestDFSShell {
|
|
|
String path = "/test/" + name;
|
|
|
Path root = mkdir(fs, new Path(path));
|
|
|
Path sub = mkdir(fs, new Path(root, "sub"));
|
|
|
- Path root2 = mkdir(fs, new Path(path + "2"));
|
|
|
+ Path root2 = mkdir(fs, new Path(path + "2"));
|
|
|
|
|
|
writeFile(fs, new Path(root, "f1"));
|
|
|
writeFile(fs, new Path(root, "f2"));
|
|
@@ -900,7 +900,7 @@ public class TestDFSShell {
|
|
|
localpath = localpath.makeQualified(localfs.getUri(),
|
|
|
localfs.getWorkingDirectory());
|
|
|
localfs.mkdirs(localpath);
|
|
|
-
|
|
|
+
|
|
|
final String localstr = localpath.toString();
|
|
|
System.out.println("localstr=" + localstr);
|
|
|
runCount(localstr, 1, 0, shell);
|
|
@@ -915,7 +915,7 @@ public class TestDFSShell {
|
|
|
}
|
|
|
private static void runCount(String path, long dirs, long files, FsShell shell
|
|
|
) throws IOException {
|
|
|
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
PrintStream out = new PrintStream(bytes);
|
|
|
PrintStream oldOut = System.out;
|
|
|
System.setOut(out);
|
|
@@ -956,15 +956,15 @@ public class TestDFSShell {
|
|
|
throw new IOException(StringUtils.stringifyException(e));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Test chmod.
|
|
|
*/
|
|
|
- void testChmod(Configuration conf, FileSystem fs, String chmodDir)
|
|
|
+ void testChmod(Configuration conf, FileSystem fs, String chmodDir)
|
|
|
throws IOException {
|
|
|
FsShell shell = new FsShell();
|
|
|
shell.setConf(conf);
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
//first make dir
|
|
|
Path dir = new Path(chmodDir);
|
|
@@ -1039,8 +1039,8 @@ public class TestDFSShell {
|
|
|
LOG.info("Permission change result: " + result);
|
|
|
assertEquals(expected, result);
|
|
|
}
|
|
|
-
|
|
|
- private void confirmOwner(String owner, String group,
|
|
|
+
|
|
|
+ private void confirmOwner(String owner, String group,
|
|
|
FileSystem fs, Path... paths) throws IOException {
|
|
|
for(Path path : paths) {
|
|
|
if (owner != null) {
|
|
@@ -1051,68 +1051,68 @@ public class TestDFSShell {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testFilePermissions() throws IOException {
|
|
|
Configuration conf = new HdfsConfiguration();
|
|
|
-
|
|
|
+
|
|
|
//test chmod on local fs
|
|
|
FileSystem fs = FileSystem.getLocal(conf);
|
|
|
- testChmod(conf, fs,
|
|
|
+ testChmod(conf, fs,
|
|
|
(new File(TEST_ROOT_DIR, "chmodTest")).getAbsolutePath());
|
|
|
-
|
|
|
+
|
|
|
conf.set(DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, "true");
|
|
|
-
|
|
|
+
|
|
|
//test chmod on DFS
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
|
|
fs = cluster.getFileSystem();
|
|
|
testChmod(conf, fs, "/tmp/chmodTest");
|
|
|
-
|
|
|
+
|
|
|
// test chown and chgrp on DFS:
|
|
|
-
|
|
|
+
|
|
|
FsShell shell = new FsShell();
|
|
|
shell.setConf(conf);
|
|
|
fs = cluster.getFileSystem();
|
|
|
-
|
|
|
+
|
|
|
/* For dfs, I am the super user and I can change owner of any file to
|
|
|
* anything. "-R" option is already tested by chmod test above.
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
String file = "/tmp/chownTest";
|
|
|
Path path = new Path(file);
|
|
|
Path parent = new Path("/tmp");
|
|
|
Path root = new Path("/");
|
|
|
TestDFSShell.writeFile(fs, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chgrp", "-R", "herbivores", "/*", "unknownFile*");
|
|
|
confirmOwner(null, "herbivores", fs, parent, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chgrp", "mammals", file);
|
|
|
confirmOwner(null, "mammals", fs, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chown", "-R", ":reptiles", "/");
|
|
|
confirmOwner(null, "reptiles", fs, root, parent, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chown", "python:", "/nonExistentFile", file);
|
|
|
confirmOwner("python", "reptiles", fs, path);
|
|
|
|
|
|
runCmd(shell, "-chown", "-R", "hadoop:toys", "unknownFile", "/");
|
|
|
confirmOwner("hadoop", "toys", fs, root, parent, path);
|
|
|
-
|
|
|
+
|
|
|
// Test different characters in names
|
|
|
|
|
|
runCmd(shell, "-chown", "hdfs.user", file);
|
|
|
confirmOwner("hdfs.user", null, fs, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chown", "_Hdfs.User-10:_hadoop.users--", file);
|
|
|
confirmOwner("_Hdfs.User-10", "_hadoop.users--", fs, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chown", "hdfs/hadoop-core@apache.org:asf-projects", file);
|
|
|
confirmOwner("hdfs/hadoop-core@apache.org", "asf-projects", fs, path);
|
|
|
-
|
|
|
+
|
|
|
runCmd(shell, "-chgrp", "hadoop-core@apache.org/100", file);
|
|
|
confirmOwner(null, "hadoop-core@apache.org/100", fs, path);
|
|
|
-
|
|
|
+
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
/**
|
|
@@ -1142,7 +1142,7 @@ public class TestDFSShell {
|
|
|
Path myFile = new Path("/test/mkdirs/myFile");
|
|
|
writeFile(fileSys, myFile);
|
|
|
assertTrue(fileSys.exists(myFile));
|
|
|
- Path myFile2 = new Path("/test/mkdirs/myFile2");
|
|
|
+ Path myFile2 = new Path("/test/mkdirs/myFile2");
|
|
|
writeFile(fileSys, myFile2);
|
|
|
assertTrue(fileSys.exists(myFile2));
|
|
|
|
|
@@ -1156,7 +1156,7 @@ public class TestDFSShell {
|
|
|
val = shell.run(args);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run " +
|
|
|
- e.getLocalizedMessage());
|
|
|
+ e.getLocalizedMessage());
|
|
|
}
|
|
|
assertTrue(val == 0);
|
|
|
assertFalse(fileSys.exists(myFile));
|
|
@@ -1174,13 +1174,13 @@ public class TestDFSShell {
|
|
|
String[] args = new String[3];
|
|
|
args[0] = "-cat";
|
|
|
args[1] = "/test/mkdirs/myFile";
|
|
|
- args[2] = "/test/mkdirs/myFile2";
|
|
|
+ args[2] = "/test/mkdirs/myFile2";
|
|
|
int val = -1;
|
|
|
try {
|
|
|
val = shell.run(args);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run: " +
|
|
|
- StringUtils.stringifyException(e));
|
|
|
+ StringUtils.stringifyException(e));
|
|
|
}
|
|
|
assertTrue(val == 0);
|
|
|
}
|
|
@@ -1196,7 +1196,7 @@ public class TestDFSShell {
|
|
|
val = shell.run(args);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run " +
|
|
|
- e.getLocalizedMessage());
|
|
|
+ e.getLocalizedMessage());
|
|
|
}
|
|
|
assertTrue(val != 0);
|
|
|
}
|
|
@@ -1211,7 +1211,7 @@ public class TestDFSShell {
|
|
|
val = shell.run(args);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run " +
|
|
|
- e.getLocalizedMessage());
|
|
|
+ e.getLocalizedMessage());
|
|
|
}
|
|
|
assertTrue(val != 0);
|
|
|
}
|
|
@@ -1226,7 +1226,7 @@ public class TestDFSShell {
|
|
|
val = shell.run(args);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("Exception raised from DFSShell.run " +
|
|
|
- e.getLocalizedMessage());
|
|
|
+ e.getLocalizedMessage());
|
|
|
}
|
|
|
assertTrue(val == 0);
|
|
|
}
|
|
@@ -1480,7 +1480,7 @@ public class TestDFSShell {
|
|
|
for(Block b : e.getValue()) {
|
|
|
files.add(DataNodeTestUtils.getFile(dn, poolId, b.getBlockId()));
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
return files;
|
|
|
}
|
|
@@ -1493,7 +1493,7 @@ public class TestDFSShell {
|
|
|
PrintWriter out = new PrintWriter(f);
|
|
|
out.print(content);
|
|
|
out.flush();
|
|
|
- out.close();
|
|
|
+ out.close();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1503,7 +1503,7 @@ public class TestDFSShell {
|
|
|
|
|
|
@Test (timeout = 30000)
|
|
|
public void testRemoteException() throws Exception {
|
|
|
- UserGroupInformation tmpUGI =
|
|
|
+ UserGroupInformation tmpUGI =
|
|
|
UserGroupInformation.createUserForTesting("tmpname", new String[] {"mygroup"});
|
|
|
MiniDFSCluster dfs = null;
|
|
|
PrintStream bak = null;
|
|
@@ -1515,7 +1515,7 @@ public class TestDFSShell {
|
|
|
fs.mkdirs(p);
|
|
|
fs.setPermission(p, new FsPermission((short)0700));
|
|
|
bak = System.err;
|
|
|
-
|
|
|
+
|
|
|
tmpUGI.doAs(new PrivilegedExceptionAction<Object>() {
|
|
|
@Override
|
|
|
public Object run() throws Exception {
|
|
@@ -1529,9 +1529,9 @@ public class TestDFSShell {
|
|
|
int ret = ToolRunner.run(fshell, args);
|
|
|
assertEquals("returned should be 1", 1, ret);
|
|
|
String str = out.toString();
|
|
|
- assertTrue("permission denied printed",
|
|
|
+ assertTrue("permission denied printed",
|
|
|
str.indexOf("Permission denied") != -1);
|
|
|
- out.reset();
|
|
|
+ out.reset();
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
@@ -1544,7 +1544,7 @@ public class TestDFSShell {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testGet() throws IOException {
|
|
|
GenericTestUtils.setLogLevel(FSInputChecker.LOG, Level.ALL);
|
|
@@ -1563,7 +1563,7 @@ public class TestDFSShell {
|
|
|
String dst = new File(TEST_ROOT_DIR, fname + ++count)
|
|
|
.getAbsolutePath();
|
|
|
String[] args = new String[options.length + 3];
|
|
|
- args[0] = "-get";
|
|
|
+ args[0] = "-get";
|
|
|
args[args.length - 2] = remotef.toString();
|
|
|
args[args.length - 1] = dst;
|
|
|
for(int i = 0; i < options.length; i++) {
|
|
@@ -1574,9 +1574,9 @@ public class TestDFSShell {
|
|
|
try {
|
|
|
assertEquals(exitcode, shell.run(args));
|
|
|
} catch (Exception e) {
|
|
|
- assertTrue(StringUtils.stringifyException(e), false);
|
|
|
+ assertTrue(StringUtils.stringifyException(e), false);
|
|
|
}
|
|
|
- return exitcode == 0? DFSTestUtil.readFile(new File(dst)): null;
|
|
|
+ return exitcode == 0? DFSTestUtil.readFile(new File(dst)): null;
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -1645,9 +1645,9 @@ public class TestDFSShell {
|
|
|
try {
|
|
|
final String root = createTree(dfs, "lsr");
|
|
|
dfs.mkdirs(new Path(root, "zzz"));
|
|
|
-
|
|
|
+
|
|
|
runLsr(new FsShell(conf), root, 0);
|
|
|
-
|
|
|
+
|
|
|
final Path sub = new Path(root, "sub");
|
|
|
dfs.setPermission(sub, new FsPermission((short)0));
|
|
|
|
|
@@ -1670,7 +1670,7 @@ public class TestDFSShell {
|
|
|
private static String runLsr(final FsShell shell, String root, int returnvalue
|
|
|
) throws Exception {
|
|
|
System.out.println("root=" + root + ", returnvalue=" + returnvalue);
|
|
|
- final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
final PrintStream out = new PrintStream(bytes);
|
|
|
final PrintStream oldOut = System.out;
|
|
|
final PrintStream oldErr = System.err;
|
|
@@ -1688,7 +1688,7 @@ public class TestDFSShell {
|
|
|
System.out.println("results:\n" + results);
|
|
|
return results;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* default setting is file:// which is not a DFS
|
|
|
* so DFSAdmin should throw and catch InvalidArgumentException
|
|
@@ -1703,7 +1703,7 @@ public class TestDFSShell {
|
|
|
int res = admin.run(new String[] {"-refreshNodes"});
|
|
|
assertEquals("expected to fail -1", res , -1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Preserve Copy Option is -ptopxa (timestamps, ownership, permission, XATTR,
|
|
|
// ACLs)
|
|
|
@Test (timeout = 120000)
|
|
@@ -1737,15 +1737,15 @@ public class TestDFSShell {
|
|
|
final String owner = status.getOwner();
|
|
|
final String group = status.getGroup();
|
|
|
final FsPermission perm = status.getPermission();
|
|
|
-
|
|
|
+
|
|
|
fs.setXAttr(src, USER_A1, USER_A1_VALUE);
|
|
|
fs.setXAttr(src, TRUSTED_A1, TRUSTED_A1_VALUE);
|
|
|
-
|
|
|
+
|
|
|
shell = new FsShell(conf);
|
|
|
-
|
|
|
+
|
|
|
// -p
|
|
|
Path target1 = new Path(hdfsTestDir, "targetfile1");
|
|
|
- String[] argv = new String[] { "-cp", "-p", src.toUri().toString(),
|
|
|
+ String[] argv = new String[] { "-cp", "-p", src.toUri().toString(),
|
|
|
target1.toUri().toString() };
|
|
|
int ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals("cp -p is not working", SUCCESS, ret);
|
|
@@ -1764,7 +1764,7 @@ public class TestDFSShell {
|
|
|
|
|
|
// -ptop
|
|
|
Path target2 = new Path(hdfsTestDir, "targetfile2");
|
|
|
- argv = new String[] { "-cp", "-ptop", src.toUri().toString(),
|
|
|
+ argv = new String[] { "-cp", "-ptop", src.toUri().toString(),
|
|
|
target2.toUri().toString() };
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals("cp -ptop is not working", SUCCESS, ret);
|
|
@@ -1783,7 +1783,7 @@ public class TestDFSShell {
|
|
|
|
|
|
// -ptopx
|
|
|
Path target3 = new Path(hdfsTestDir, "targetfile3");
|
|
|
- argv = new String[] { "-cp", "-ptopx", src.toUri().toString(),
|
|
|
+ argv = new String[] { "-cp", "-ptopx", src.toUri().toString(),
|
|
|
target3.toUri().toString() };
|
|
|
ret = ToolRunner.run(shell, argv);
|
|
|
assertEquals("cp -ptopx is not working", SUCCESS, ret);
|
|
@@ -2317,6 +2317,77 @@ public class TestDFSShell {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /* [refs HDFS-5033]
|
|
|
+ *
|
|
|
+ * return a "Permission Denied" message instead of "No such file or Directory"
|
|
|
+ * when trying to put/copyFromLocal a file that doesn't have read access
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @Test (timeout = 30000)
|
|
|
+ public void testCopyFromLocalWithPermissionDenied() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
|
|
+ .format(true).build();
|
|
|
+ FsShell shell = null;
|
|
|
+ FileSystem fs = null;
|
|
|
+ PrintStream bak = null;
|
|
|
+
|
|
|
+ final File localFile = new File(TEST_ROOT_DIR, "testFileWithNoReadPermissions");
|
|
|
+ final String localfilepath = new Path(localFile.getAbsolutePath()).toUri().toString();
|
|
|
+ final String testdir = "/tmp/TestDFSShell-CopyFromLocalWithPermissionDenied-"
|
|
|
+ + counter.getAndIncrement();
|
|
|
+ final Path hdfsTestDir = new Path(testdir);
|
|
|
+ try {
|
|
|
+ fs = cluster.getFileSystem();
|
|
|
+ fs.mkdirs(hdfsTestDir);
|
|
|
+ localFile.createNewFile();
|
|
|
+ localFile.setReadable(false);
|
|
|
+ writeFile(fs, new Path(testdir, "testFileForPut"));
|
|
|
+ shell = new FsShell();
|
|
|
+
|
|
|
+ // capture system error messages, snarfed from testErrOutPut()
|
|
|
+ bak = System.err;
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
+ PrintStream tmp = new PrintStream(out);
|
|
|
+ System.setErr(tmp);
|
|
|
+
|
|
|
+ // Tests for put
|
|
|
+ String[] argv = new String[] { "-put", localfilepath, testdir };
|
|
|
+ int res = ToolRunner.run(shell, argv);
|
|
|
+ assertEquals("put is working", ERROR, res);
|
|
|
+ String returned = out.toString();
|
|
|
+ assertTrue(" outputs Permission denied error message",
|
|
|
+ (returned.lastIndexOf("Permission denied") != -1));
|
|
|
+
|
|
|
+ // Tests for copyFromLocal
|
|
|
+ argv = new String[] { "-copyFromLocal", localfilepath, testdir };
|
|
|
+ res = ToolRunner.run(shell, argv);
|
|
|
+ assertEquals("copyFromLocal -f is working", ERROR, res);
|
|
|
+ returned = out.toString();
|
|
|
+ assertTrue(" outputs Permission denied error message",
|
|
|
+ (returned.lastIndexOf("Permission denied") != -1));
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ if (bak != null) {
|
|
|
+ System.setErr(bak);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != shell)
|
|
|
+ shell.close();
|
|
|
+
|
|
|
+ if (localFile.exists())
|
|
|
+ localFile.delete();
|
|
|
+
|
|
|
+ if (null != fs) {
|
|
|
+ fs.delete(hdfsTestDir, true);
|
|
|
+ fs.close();
|
|
|
+ }
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// setrep for file and directory.
|
|
|
@Test (timeout = 30000)
|
|
|
public void testSetrep() throws Exception {
|
|
@@ -2506,7 +2577,7 @@ public class TestDFSShell {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Test (timeout = 30000)
|
|
|
public void testSetXAttrPermission() throws Exception {
|
|
|
UserGroupInformation user = UserGroupInformation.
|
|
@@ -2517,16 +2588,16 @@ public class TestDFSShell {
|
|
|
final Configuration conf = new HdfsConfiguration();
|
|
|
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
|
|
|
cluster.waitActive();
|
|
|
-
|
|
|
+
|
|
|
FileSystem fs = cluster.getFileSystem();
|
|
|
Path p = new Path("/foo");
|
|
|
fs.mkdirs(p);
|
|
|
bak = System.err;
|
|
|
-
|
|
|
+
|
|
|
final FsShell fshell = new FsShell(conf);
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
System.setErr(new PrintStream(out));
|
|
|
-
|
|
|
+
|
|
|
// No permission to write xattr
|
|
|
fs.setPermission(p, new FsPermission((short) 0700));
|
|
|
user.doAs(new PrivilegedExceptionAction<Object>() {
|
|
@@ -2536,18 +2607,18 @@ public class TestDFSShell {
|
|
|
"-setfattr", "-n", "user.a1", "-v", "1234", "/foo"});
|
|
|
assertEquals("Returned should be 1", 1, ret);
|
|
|
String str = out.toString();
|
|
|
- assertTrue("Permission denied printed",
|
|
|
+ assertTrue("Permission denied printed",
|
|
|
str.indexOf("Permission denied") != -1);
|
|
|
out.reset();
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
int ret = ToolRunner.run(fshell, new String[]{
|
|
|
"-setfattr", "-n", "user.a1", "-v", "1234", "/foo"});
|
|
|
assertEquals("Returned should be 0", 0, ret);
|
|
|
out.reset();
|
|
|
-
|
|
|
+
|
|
|
// No permission to read and remove
|
|
|
fs.setPermission(p, new FsPermission((short) 0750));
|
|
|
user.doAs(new PrivilegedExceptionAction<Object>() {
|
|
@@ -2560,7 +2631,7 @@ public class TestDFSShell {
|
|
|
String str = out.toString();
|
|
|
assertTrue("Permission denied printed",
|
|
|
str.indexOf("Permission denied") != -1);
|
|
|
- out.reset();
|
|
|
+ out.reset();
|
|
|
// Remove
|
|
|
ret = ToolRunner.run(fshell, new String[]{
|
|
|
"-setfattr", "-x", "user.a1", "/foo"});
|
|
@@ -2568,7 +2639,7 @@ public class TestDFSShell {
|
|
|
str = out.toString();
|
|
|
assertTrue("Permission denied printed",
|
|
|
str.indexOf("Permission denied") != -1);
|
|
|
- out.reset();
|
|
|
+ out.reset();
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
@@ -2683,28 +2754,28 @@ public class TestDFSShell {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
* Test to make sure that user namespace xattrs can be set only if path has
|
|
|
* access and for sticky directorries, only owner/privileged user can write.
|
|
|
* Trusted namespace xattrs can be set only with privileged users.
|
|
|
- *
|
|
|
+ *
|
|
|
* As user1: Create a directory (/foo) as user1, chown it to user1 (and
|
|
|
* user1's group), grant rwx to "other".
|
|
|
- *
|
|
|
+ *
|
|
|
* As user2: Set an xattr (should pass with path access).
|
|
|
- *
|
|
|
+ *
|
|
|
* As user1: Set an xattr (should pass).
|
|
|
- *
|
|
|
+ *
|
|
|
* As user2: Read the xattr (should pass). Remove the xattr (should pass with
|
|
|
* path access).
|
|
|
- *
|
|
|
+ *
|
|
|
* As user1: Read the xattr (should pass). Remove the xattr (should pass).
|
|
|
- *
|
|
|
+ *
|
|
|
* As user1: Change permissions only to owner
|
|
|
- *
|
|
|
+ *
|
|
|
* As User2: Set an Xattr (Should fail set with no path access) Remove an
|
|
|
* Xattr (Should fail with no path access)
|
|
|
- *
|
|
|
+ *
|
|
|
* As SuperUser: Set an Xattr with Trusted (Should pass)
|
|
|
*/
|
|
|
@Test (timeout = 30000)
|
|
@@ -2742,7 +2813,7 @@ public class TestDFSShell {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
//Test 2. Give access to others
|
|
|
user1.doAs(new PrivilegedExceptionAction<Object>() {
|
|
|
@Override
|
|
@@ -2809,7 +2880,7 @@ public class TestDFSShell {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// Test 7. Change permission to have path access only to owner(user1)
|
|
|
user1.doAs(new PrivilegedExceptionAction<Object>() {
|
|
|
@Override
|
|
@@ -2822,7 +2893,7 @@ public class TestDFSShell {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// Test 8. There should be no permissions to set for
|
|
|
// the non-owning user with no path access.
|
|
|
user2.doAs(new PrivilegedExceptionAction<Object>() {
|
|
@@ -2839,7 +2910,7 @@ public class TestDFSShell {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// Test 9. There should be no permissions to remove for
|
|
|
// the non-owning user with no path access.
|
|
|
user2.doAs(new PrivilegedExceptionAction<Object>() {
|
|
@@ -2856,7 +2927,7 @@ public class TestDFSShell {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// Test 10. Superuser should be allowed to set with trusted namespace
|
|
|
SUPERUSER.doAs(new PrivilegedExceptionAction<Object>() {
|
|
|
@Override
|