HDDS-210. Make "-file" argument optional for ozone getKey command. Contributed by Lokesh Jain.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/103f2eeb Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/103f2eeb Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/103f2eeb Branch: refs/heads/HDFS-12943 Commit: 103f2eeb57dbadd9abbbc25a05bb7c79b48fdc17 Parents: 88625f5 Author: Xiaoyu Yao <x...@apache.org> Authored: Fri Jul 13 11:44:24 2018 -0700 Committer: Xiaoyu Yao <x...@apache.org> Committed: Fri Jul 13 11:45:02 2018 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/ozone/ozShell/TestOzoneShell.java | 12 ++++++++++++ .../hadoop/ozone/web/ozShell/keys/GetKeyHandler.java | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/103f2eeb/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java index a4b30f0..000d530 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java @@ -705,6 +705,18 @@ public class TestOzoneShell { randFile.read(dataBytes); } assertEquals(dataStr, DFSUtil.bytes2String(dataBytes)); + + tmpPath = baseDir.getAbsolutePath() + File.separatorChar + keyName; + args = new String[] {"-getKey", + url + "/" + volumeName + "/" + bucketName + "/" + keyName, "-file", + baseDir.getAbsolutePath()}; + assertEquals(0, ToolRunner.run(shell, args)); + + dataBytes = new byte[dataStr.length()]; + try (FileInputStream randFile = new FileInputStream(new File(tmpPath))) { + randFile.read(dataBytes); + } + assertEquals(dataStr, DFSUtil.bytes2String(dataBytes)); } @Test http://git-wip-us.apache.org/repos/asf/hadoop/blob/103f2eeb/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java index 34620b4..2d059e0 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java @@ -98,11 +98,14 @@ public class GetKeyHandler extends Handler { Path dataFilePath = Paths.get(fileName); File dataFile = new File(fileName); + if (dataFile.exists() && dataFile.isDirectory()) { + dataFile = new File(fileName, keyName); + } if (dataFile.exists()) { - throw new OzoneClientException(fileName + - "exists. Download will overwrite an " + - "existing file. Aborting."); + throw new OzoneClientException( + fileName + "exists. Download will overwrite an " + + "existing file. Aborting."); } OzoneVolume vol = client.getObjectStore().getVolume(volumeName); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org