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 1b1013533cc..0b53f690db1 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 @@ -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) JsonUtils.toJsonList(commandOutput, KeyInfo.class); diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java index 5642bc7b810..111ce1607c1 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java +++ b/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 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);