From 103f2eeb57dbadd9abbbc25a05bb7c79b48fdc17 Mon Sep 17 00:00:00 2001 From: Xiaoyu Yao Date: Fri, 13 Jul 2018 11:44:24 -0700 Subject: [PATCH] HDDS-210. Make "-file" argument optional for ozone getKey command. Contributed by Lokesh Jain. --- .../apache/hadoop/ozone/ozShell/TestOzoneShell.java | 12 ++++++++++++ .../hadoop/ozone/web/ozShell/keys/GetKeyHandler.java | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) 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 a4b30f00c7..000d53039b 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 void testGetKey() throws Exception { 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 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 34620b4934..2d059e0c8c 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 @@ protected void execute(CommandLine cmd) 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);