HDFS-10850. getEZForPath should NOT throw FNF. Contributed by Andrew Wang.
(cherry picked from commit 0670149c88
)
This commit is contained in:
parent
25df276c6b
commit
10222cd54e
|
@ -2807,8 +2807,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(FileNotFoundException.class,
|
||||
AccessControlException.class, UnresolvedPathException.class);
|
||||
throw re.unwrapRemoteException(AccessControlException.class,
|
||||
UnresolvedPathException.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -327,14 +327,13 @@ public class HdfsAdmin {
|
|||
* Get the path of the encryption zone for a given file or directory.
|
||||
*
|
||||
* @param path The path to get the ez for.
|
||||
*
|
||||
* @return The EncryptionZone of the ez, or null if path is not in an ez.
|
||||
* @return An EncryptionZone, or null if path does not exist or is not in an
|
||||
* ez.
|
||||
* @throws IOException if there was a general IO exception
|
||||
* @throws AccessControlException if the caller does not have access to path
|
||||
* @throws FileNotFoundException if the path does not exist
|
||||
*/
|
||||
public EncryptionZone getEncryptionZoneForPath(Path path)
|
||||
throws IOException, AccessControlException, FileNotFoundException {
|
||||
throws IOException, AccessControlException {
|
||||
return dfs.getEZForPath(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ 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.security.PrivilegedExceptionAction;
|
||||
|
@ -184,9 +183,6 @@ final class FSDirEncryptionZoneOp {
|
|||
fsd.readLock();
|
||||
try {
|
||||
iip = fsd.resolvePath(pc, srcArg);
|
||||
if (iip.getLastINode() == null) {
|
||||
throw new FileNotFoundException("Path not found: " + iip.getPath());
|
||||
}
|
||||
if (fsd.isPermissionEnabled()) {
|
||||
fsd.checkPathAccess(pc, iip, FsAction.READ);
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
|
@ -604,13 +605,8 @@ public class TestEncryptionZones {
|
|||
assertExceptionContains("Permission denied:", e);
|
||||
}
|
||||
|
||||
try {
|
||||
userAdmin.getEncryptionZoneForPath(nonexistent);
|
||||
fail("FileNotFoundException should be thrown for a non-existent"
|
||||
+ " file path");
|
||||
} catch (FileNotFoundException e) {
|
||||
assertExceptionContains("Path not found: " + nonexistent, e);
|
||||
}
|
||||
assertNull("expected null for nonexistent path",
|
||||
userAdmin.getEncryptionZoneForPath(nonexistent));
|
||||
|
||||
// Check operation with non-ez paths
|
||||
assertNull("expected null for non-ez path",
|
||||
|
@ -638,20 +634,10 @@ public class TestEncryptionZones {
|
|||
assertEquals("expected ez path", allPath.toString(),
|
||||
userAdmin.getEncryptionZoneForPath(
|
||||
new Path(snapshottedAllPath)).getPath().toString());
|
||||
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);
|
||||
}
|
||||
assertNull("expected null for deleted file path",
|
||||
userAdmin.getEncryptionZoneForPath(allPathFile));
|
||||
assertNull("expected null for deleted directory path",
|
||||
userAdmin.getEncryptionZoneForPath(allPath));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -1498,25 +1484,18 @@ public class TestEncryptionZones {
|
|||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testGetEncryptionZoneOnANonExistentZoneFile() throws Exception {
|
||||
final Path ez = new Path("/ez");
|
||||
fs.mkdirs(ez);
|
||||
dfsAdmin.createEncryptionZone(ez, TEST_KEY, NO_TRASH);
|
||||
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);
|
||||
}
|
||||
public void testGetEncryptionZoneOnANonExistentPaths() throws Exception {
|
||||
final Path ezPath = new Path("/ez");
|
||||
fs.mkdirs(ezPath);
|
||||
dfsAdmin.createEncryptionZone(ezPath, TEST_KEY, NO_TRASH);
|
||||
Path zoneFile = new Path(ezPath, "file");
|
||||
EncryptionZone ez = fs.getEZForPath(zoneFile);
|
||||
assertNotNull("Expected EZ for non-existent path in EZ", ez);
|
||||
ez = dfsAdmin.getEncryptionZoneForPath(zoneFile);
|
||||
assertNotNull("Expected EZ for non-existent path in EZ", ez);
|
||||
ez = dfsAdmin.getEncryptionZoneForPath(
|
||||
new Path("/does/not/exist"));
|
||||
assertNull("Expected null for non-existent path not in EZ", ez);
|
||||
}
|
||||
|
||||
@Test(timeout = 120000)
|
||||
|
|
Loading…
Reference in New Issue