Browse Source

HDDS-1432. Ozone client list command truncates response without any indication. Contributed by Siddharth Wagle.

Arpit Agarwal 6 years ago
parent
commit
f2ab2795db

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

@@ -1114,11 +1114,16 @@ public class TestOzoneShell {
     }
 
     out.reset();
+    String msgText = "Listing first 3 entries of the result. " +
+        "Use --length (-l) to override max returned keys.";
     args =
         new String[] {"key", "list", url + "/" + volumeName + "/" + bucketName,
             "--length", "3"};
     execute(shell, args);
     commandOutput = out.toString();
+    assertTrue("Expecting output to start with " + msgText,
+        commandOutput.contains(msgText));
+    commandOutput = commandOutput.replace(msgText, "");
     keys = (List<KeyInfo>) JsonUtils.toJsonList(commandOutput,
         KeyInfo.class);
 

+ 7 - 0
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java

@@ -90,12 +90,19 @@ public class ListKeyHandler extends Handler {
         startKey);
     List<KeyInfo> keyInfos = new ArrayList<>();
 
+    int maxKeyLimit = maxKeys;
     while (maxKeys > 0 && keyIterator.hasNext()) {
       KeyInfo key = OzoneClientUtils.asKeyInfo(keyIterator.next());
       keyInfos.add(key);
       maxKeys -= 1;
     }
 
+    // More keys were returned notify about max length
+    if (keyIterator.hasNext()) {
+      System.out.println("Listing first " + maxKeyLimit + " entries of the " +
+          "result. Use --length (-l) to override max returned keys.");
+    }
+
     if (isVerbose()) {
       System.out.printf("Found : %d keys for bucket %s in volume : %s ",
           keyInfos.size(), bucketName, volumeName);