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