From c7403a448d42ce75fd936d6f8ebfc3bfc419ba07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Wed, 5 Sep 2018 12:40:44 +0200 Subject: [PATCH] HDDS-315. ozoneShell infoKey does not work for directories created as key and throws 'KEY_NOT_FOUND' error. Contributed by Dinesh Chitlangia. --- .../hadoop/ozone/ozShell/TestOzoneShell.java | 35 +++++++++++++++++++ .../web/ozShell/keys/InfoKeyHandler.java | 7 +++- 2 files changed, 41 insertions(+), 1 deletion(-) 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 b4740b47dc..386b1d23ca 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 @@ -815,6 +815,41 @@ public void testInfoKeyDetails() throws Exception { "Lookup key failed, error:KEY_NOT_FOUND")); } + @Test + public void testInfoDirKey() throws Exception { + LOG.info("Running testInfoKey for Dir Key"); + String dirKeyName = "test/"; + String keyNameOnly = "test"; + OzoneBucket bucket = creatBucket(); + String volumeName = bucket.getVolumeName(); + String bucketName = bucket.getName(); + String dataStr = "test-data"; + OzoneOutputStream keyOutputStream = + bucket.createKey(dirKeyName, dataStr.length()); + keyOutputStream.write(dataStr.getBytes()); + keyOutputStream.close(); + String[] args = new String[] {"-infoKey", + url + "/" + volumeName + "/" + bucketName + "/" + dirKeyName}; + // verify the response output + int a = ToolRunner.run(shell, args); + String output = out.toString(); + assertEquals(0, a); + assertTrue(output.contains(dirKeyName)); + assertTrue(output.contains("createdOn") && + output.contains("modifiedOn") && + output.contains(OzoneConsts.OZONE_TIME_ZONE)); + args = new String[] {"-infoKey", + url + "/" + volumeName + "/" + bucketName + "/" + keyNameOnly}; + a = ToolRunner.run(shell, args); + output = out.toString(); + assertEquals(1, a); + assertTrue(err.toString().contains( + "Lookup key failed, error:KEY_NOT_FOUND")); + // reset stream + out.reset(); + err.reset(); + } + @Test public void testListKey() throws Exception { LOG.info("Running testListKey"); diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java index fe8775611a..53a3264db9 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java @@ -25,6 +25,7 @@ import java.nio.file.Paths; import org.apache.commons.cli.CommandLine; +import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.client.*; import org.apache.hadoop.ozone.client.rest.OzoneException; import org.apache.hadoop.ozone.web.ozShell.Handler; @@ -64,8 +65,12 @@ protected void execute(CommandLine cmd) volumeName = path.getName(0).toString(); bucketName = path.getName(1).toString(); - keyName = path.getName(2).toString(); + String searchString = volumeName + OzoneConsts.OZONE_URI_DELIMITER + + bucketName + OzoneConsts.OZONE_URI_DELIMITER; + + keyName = ozoneURIString.substring(ozoneURIString.indexOf(searchString) + + searchString.length()); if (cmd.hasOption(Shell.VERBOSE)) { System.out.printf("Volume Name : %s%n", volumeName);