HDFS-9433. DFS getEZForPath API on a non-existent file should throw FileNotFoundException (Rakesh R via umamahesh)
This commit is contained in:
parent
8676a118a1
commit
411e2b2e7c
|
@ -2671,8 +2671,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(AccessControlException.class,
|
throw re.unwrapRemoteException(FileNotFoundException.class,
|
||||||
UnresolvedPathException.class);
|
AccessControlException.class, UnresolvedPathException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2365,6 +2365,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
HDFS-9423. Fix intermittent failure of TestEditLogTailer.
|
HDFS-9423. Fix intermittent failure of TestEditLogTailer.
|
||||||
(Masatake Iwasaki via waltersu4549)
|
(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
|
Release 2.7.3 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -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 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.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
|
@ -172,6 +173,9 @@ final class FSDirEncryptionZoneOp {
|
||||||
try {
|
try {
|
||||||
src = fsd.resolvePath(pc, srcArg, pathComponents);
|
src = fsd.resolvePath(pc, srcArg, pathComponents);
|
||||||
iip = fsd.getINodesInPath(src, true);
|
iip = fsd.getINodesInPath(src, true);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
|
@ -475,8 +476,13 @@ public class TestEncryptionZones {
|
||||||
assertExceptionContains("Permission denied:", e);
|
assertExceptionContains("Permission denied:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNull("expected null for nonexistent path",
|
try {
|
||||||
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",
|
||||||
|
@ -504,10 +510,20 @@ 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());
|
||||||
assertNull("expected null for deleted file path",
|
try {
|
||||||
userAdmin.getEncryptionZoneForPath(allPathFile));
|
userAdmin.getEncryptionZoneForPath(allPathFile);
|
||||||
assertNull("expected null for deleted directory path",
|
fail("FileNotFoundException should be thrown for a non-existent"
|
||||||
userAdmin.getEncryptionZoneForPath(allPath));
|
+ " 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;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1331,4 +1347,26 @@ public class TestEncryptionZones {
|
||||||
assertEquals("Got unexpected ez path", "/somewhere/base/zone", dfsAdmin
|
assertEquals("Got unexpected ez path", "/somewhere/base/zone", dfsAdmin
|
||||||
.getEncryptionZoneForPath(zoneDir).getPath().toString());
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue