This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new f9ec90c400 HDDS-8887. Support --all in ListOptions. (#4931)
f9ec90c400 is described below
commit f9ec90c4002ddb68d3cb89e88c0d7c48d99979e3
Author: ashishkumar50 <[email protected]>
AuthorDate: Tue Jun 20 13:29:38 2023 +0530
HDDS-8887. Support --all in ListOptions. (#4931)
---
.../hadoop/ozone/shell/TestOzoneShellHA.java | 43 ++++++++++++++++++++++
.../org/apache/hadoop/ozone/shell/ListOptions.java | 31 ++++++++++++----
.../ozone/shell/volume/ListVolumeHandler.java | 6 +--
3 files changed, 68 insertions(+), 12 deletions(-)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
index 783e6d2c2e..82882210ae 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
@@ -1404,6 +1404,49 @@ public class TestOzoneShellHA {
}
}
+ @Test
+ public void testListAllKeys()
+ throws Exception {
+ String volumeName = "vollst";
+ // Create volume vollst
+ String[] args = new String[] {
+ "volume", "create", "o3://" + omServiceId +
+ OZONE_URI_DELIMITER + volumeName};
+ execute(ozoneShell, args);
+ out.reset();
+
+ // Create bucket bucket1
+ args = new String[]{"bucket", "create", "o3://" + omServiceId +
+ OZONE_URI_DELIMITER + volumeName + "/bucket1"};
+ execute(ozoneShell, args);
+ out.reset();
+
+ // Insert 120 keys into bucket1
+ String keyName = OZONE_URI_DELIMITER + volumeName + "/bucket1" +
+ OZONE_URI_DELIMITER + "key";
+ for (int i = 0; i < 120; i++) {
+ args = new String[]{
+ "key", "put", "o3://" + omServiceId + keyName + i,
+ testFile.getPath()};
+ execute(ozoneShell, args);
+ }
+
+ out.reset();
+ // Number of keys should return less than 120(100 by default)
+ args =
+ new String[]{"key", "list", volumeName};
+ execute(ozoneShell, args);
+ Assert.assertTrue(getNumOfKeys() < 120);
+
+ out.reset();
+ // Use --all option to get all the keys
+ args =
+ new String[]{"key", "list", "--all", volumeName};
+ execute(ozoneShell, args);
+ // Number of keys returned should be 120
+ Assert.assertEquals(120, getNumOfKeys());
+ }
+
@Test
public void testVolumeListKeys()
throws Exception {
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/ListOptions.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/ListOptions.java
index 4baf4f5abd..eb12d15ebc 100644
---
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/ListOptions.java
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/ListOptions.java
@@ -24,11 +24,21 @@ import picocli.CommandLine;
*/
public class ListOptions {
- @CommandLine.Option(names = {"--length", "-l"},
- description = "Maximum number of items to list",
- defaultValue = "100",
- showDefaultValue = CommandLine.Help.Visibility.ALWAYS)
- private int limit;
+ @CommandLine.ArgGroup(exclusive = true)
+ private ExclusiveLimit exclusiveLimit = new ExclusiveLimit();
+
+ static class ExclusiveLimit {
+ @CommandLine.Option(names = {"--length", "-l"},
+ description = "Maximum number of items to list",
+ defaultValue = "100",
+ showDefaultValue = CommandLine.Help.Visibility.ALWAYS)
+ private int limit;
+
+ @CommandLine.Option(names = {"--all", "-a"},
+ description = "List all results",
+ defaultValue = "false")
+ private boolean all;
+ }
@CommandLine.Option(names = {"--start", "-s"},
description = "The item to start the listing from.\n" +
@@ -40,12 +50,19 @@ public class ListOptions {
private String prefix;
public int getLimit() {
- if (limit < 1) {
+ if (exclusiveLimit.all) {
+ return Integer.MAX_VALUE;
+ }
+ if (exclusiveLimit.limit < 1) {
throw new IllegalArgumentException(
"List length should be a positive number");
}
- return limit;
+ return exclusiveLimit.limit;
+ }
+
+ public boolean isAll() {
+ return exclusiveLimit.all;
}
public String getStartItem() {
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ListVolumeHandler.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ListVolumeHandler.java
index 433376916d..233e926b38 100644
---
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ListVolumeHandler.java
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ListVolumeHandler.java
@@ -56,10 +56,6 @@ public class ListVolumeHandler extends Handler {
+ " if list all volumes option is specified.")
private String userName;
- @Option(names = {"--all", "-a"},
- description = "List all volumes.")
- private boolean listAllVolumes;
-
@Override
protected OzoneAddress getAddress() throws OzoneClientException {
OzoneAddress address = new OzoneAddress(uri);
@@ -76,7 +72,7 @@ public class ListVolumeHandler extends Handler {
}
Iterator<? extends OzoneVolume> volumeIterator;
- if (userName != null && !listAllVolumes) {
+ if (userName != null && !listOptions.isAll()) {
volumeIterator = client.getObjectStore().listVolumesByUser(userName,
listOptions.getPrefix(), listOptions.getStartItem());
} else {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]