HDFS-9433. DFS getEZForPath API on a non-existent file should throw FileNotFoundException (Rakesh R via umamahesh)

This commit is contained in:
Uma Mahesh 2015-11-23 17:54:31 -08:00
parent 8676a118a1
commit 411e2b2e7c
4 changed files with 53 additions and 8 deletions

View File

@ -2671,8 +2671,8 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
try (TraceScope ignored = newPathTraceScope("getEZForPath", src)) {
return namenode.getEZForPath(src);
} catch (RemoteException re) {
throw re.unwrapRemoteException(AccessControlException.class,
UnresolvedPathException.class);
throw re.unwrapRemoteException(FileNotFoundException.class,
AccessControlException.class, UnresolvedPathException.class);
}
}

View File

@ -2365,6 +2365,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9423. Fix intermittent failure of TestEditLogTailer.
(Masatake Iwasaki via waltersu4549)
HDFS-9433. DFS getEZForPath API on a non-existent file should throw FileNotFoundException
(Rakesh R via umamahesh)
Release 2.7.3 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.CRYPTO_XATTR_FILE_ENCRYPTION_INFO;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.AbstractMap;
@ -172,6 +173,9 @@ final class FSDirEncryptionZoneOp {
try {
src = fsd.resolvePath(pc, srcArg, pathComponents);
iip = fsd.getINodesInPath(src, true);
if (iip.getLastINode() == null) {
throw new FileNotFoundException("Path not found: " + iip.getPath());
}
if (fsd.isPermissionEnabled()) {
fsd.checkPathAccess(pc, iip, FsAction.READ);
}

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
@ -475,8 +476,13 @@ public class TestEncryptionZones {
assertExceptionContains("Permission denied:", e);
}
assertNull("expected null for nonexistent path",
userAdmin.getEncryptionZoneForPath(nonexistent));
try {
userAdmin.getEncryptionZoneForPath(nonexistent);
fail("FileNotFoundException should be thrown for a non-existent"
+ " file path");
} catch (FileNotFoundException e) {
assertExceptionContains("Path not found: " + nonexistent, e);
}
// Check operation with non-ez paths
assertNull("expected null for non-ez path",
@ -504,10 +510,20 @@ public class TestEncryptionZones {
assertEquals("expected ez path", allPath.toString(),
userAdmin.getEncryptionZoneForPath(
new Path(snapshottedAllPath)).getPath().toString());
assertNull("expected null for deleted file path",
userAdmin.getEncryptionZoneForPath(allPathFile));
assertNull("expected null for deleted directory path",
userAdmin.getEncryptionZoneForPath(allPath));
try {
userAdmin.getEncryptionZoneForPath(allPathFile);
fail("FileNotFoundException should be thrown for a non-existent"
+ " file path");
} catch (FileNotFoundException e) {
assertExceptionContains("Path not found: " + allPathFile, e);
}
try {
userAdmin.getEncryptionZoneForPath(allPath);
fail("FileNotFoundException should be thrown for a non-existent"
+ " file path");
} catch (FileNotFoundException e) {
assertExceptionContains("Path not found: " + allPath, e);
}
return null;
}
});
@ -1331,4 +1347,26 @@ public class TestEncryptionZones {
assertEquals("Got unexpected ez path", "/somewhere/base/zone", dfsAdmin
.getEncryptionZoneForPath(zoneDir).getPath().toString());
}
@Test(timeout = 60000)
public void testGetEncryptionZoneOnANonExistentZoneFile() throws Exception {
final Path ez = new Path("/ez");
fs.mkdirs(ez);
dfsAdmin.createEncryptionZone(ez, TEST_KEY);
Path zoneFile = new Path(ez, "file");
try {
fs.getEZForPath(zoneFile);
fail("FileNotFoundException should be thrown for a non-existent"
+ " file path");
} catch (FileNotFoundException e) {
assertExceptionContains("Path not found: " + zoneFile, e);
}
try {
dfsAdmin.getEncryptionZoneForPath(zoneFile);
fail("FileNotFoundException should be thrown for a non-existent"
+ " file path");
} catch (FileNotFoundException e) {
assertExceptionContains("Path not found: " + zoneFile, e);
}
}
}