Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 87C26200B8F for ; Fri, 30 Sep 2016 15:53:15 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 866B2160AD9; Fri, 30 Sep 2016 13:53:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A3449160AC4 for ; Fri, 30 Sep 2016 15:53:14 +0200 (CEST) Received: (qmail 26632 invoked by uid 500); 30 Sep 2016 13:53:13 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 26623 invoked by uid 99); 30 Sep 2016 13:53:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Sep 2016 13:53:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9CC31E0061; Fri, 30 Sep 2016 13:53:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kihwal@apache.org To: common-commits@hadoop.apache.org Message-Id: <481850cbe6a048b3a6f519c4635f31fc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-10850. getEZForPath should NOT throw FNF. Contributed by Andrew Wang. Date: Fri, 30 Sep 2016 13:53:13 +0000 (UTC) archived-at: Fri, 30 Sep 2016 13:53:15 -0000 Repository: hadoop Updated Branches: refs/heads/trunk 82c55dcbc -> 0670149c8 HDFS-10850. getEZForPath should NOT throw FNF. Contributed by Andrew Wang. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0670149c Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0670149c Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0670149c Branch: refs/heads/trunk Commit: 0670149c88852cd7c4d6774bff06c7c588558739 Parents: 82c55dc Author: Kihwal Lee Authored: Fri Sep 30 08:44:18 2016 -0500 Committer: Kihwal Lee Committed: Fri Sep 30 08:44:18 2016 -0500 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hdfs/DFSClient.java | 4 +- .../apache/hadoop/hdfs/client/HdfsAdmin.java | 7 +-- .../server/namenode/FSDirEncryptionZoneOp.java | 4 -- .../apache/hadoop/hdfs/TestEncryptionZones.java | 59 +++++++------------- 4 files changed, 24 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/0670149c/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index 4c2a967..93c0ff0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -2599,8 +2599,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); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/0670149c/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsAdmin.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsAdmin.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsAdmin.java index 946b79d..bac2809 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsAdmin.java @@ -328,14 +328,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); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/0670149c/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java index 7501fc3..5457f08 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java @@ -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); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/0670149c/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java index 9168ca6..18a0800 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java @@ -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) --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org