Browse Source

HDDS-315. ozoneShell infoKey does not work for directories created as key and throws 'KEY_NOT_FOUND' error. Contributed by Dinesh Chitlangia.

Márton Elek 6 years ago
parent
commit
c7403a448d

+ 35 - 0
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java

@@ -815,6 +815,41 @@ public class TestOzoneShell {
         "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");

+ 6 - 1
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java

@@ -25,6 +25,7 @@ import java.nio.file.Path;
 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 @@ public class InfoKeyHandler extends Handler {
 
     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);