HDDS-207. ozone listVolume command accepts random values as argument. Contributed by Lokesh Jain.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/129269f9 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/129269f9 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/129269f9 Branch: refs/heads/HADOOP-15461 Commit: 129269f98926775ccb5046d9dd41b58f1013211d Parents: d5d4447 Author: Xiaoyu Yao <x...@apache.org> Authored: Wed Jul 18 11:05:42 2018 -0700 Committer: Xiaoyu Yao <x...@apache.org> Committed: Wed Jul 18 11:05:42 2018 -0700 ---------------------------------------------------------------------- .../src/test/acceptance/basic/ozone-shell.robot | 8 +++++--- .../apache/hadoop/ozone/ozShell/TestOzoneShell.java | 12 ++++++++++-- .../org/apache/hadoop/ozone/web/ozShell/Shell.java | 1 + .../ozone/web/ozShell/volume/ListVolumeHandler.java | 13 ++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/129269f9/hadoop-ozone/acceptance-test/src/test/acceptance/basic/ozone-shell.robot ---------------------------------------------------------------------- diff --git a/hadoop-ozone/acceptance-test/src/test/acceptance/basic/ozone-shell.robot b/hadoop-ozone/acceptance-test/src/test/acceptance/basic/ozone-shell.robot index f4be3e0..cc4b035 100644 --- a/hadoop-ozone/acceptance-test/src/test/acceptance/basic/ozone-shell.robot +++ b/hadoop-ozone/acceptance-test/src/test/acceptance/basic/ozone-shell.robot @@ -52,7 +52,9 @@ Test ozone shell ${result} = Execute on datanode ozone oz -createVolume ${protocol}${server}/${volume} -user bilbo -quota 100TB -root Should not contain ${result} Failed Should contain ${result} Creating Volume: ${volume} - ${result} = Execute on datanode ozone oz -listVolume o3://ozoneManager -user bilbo | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.volumeName=="${volume}")' + ${result} = Execute on datanode ozone oz -listVolume ${protocol}${server}/ -user bilbo | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.volumeName=="${volume}")' + Should contain ${result} createdOn + ${result} = Execute on datanode ozone oz -listVolume -user bilbo | grep -Ev 'Removed|DEBUG|ERROR|INFO|TRACE|WARN' | jq -r '.[] | select(.volumeName=="${volume}")' Should contain ${result} createdOn Execute on datanode ozone oz -updateVolume ${protocol}${server}/${volume} -user bill -quota 10TB ${result} = Execute on datanode ozone oz -infoVolume ${protocol}${server}/${volume} | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.volumeName=="${volume}") | .owner | .name' @@ -66,7 +68,7 @@ Test ozone shell Should Be Equal ${result} GROUP ${result} = Execute on datanode ozone oz -updateBucket ${protocol}${server}/${volume}/bb1 -removeAcl group:samwise:r | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.bucketName=="bb1") | .acls | .[] | select(.name=="frodo") | .type' Should Be Equal ${result} USER - ${result} = Execute on datanode ozone oz -listBucket o3://ozoneManager/${volume}/ | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.bucketName=="bb1") | .volumeName' + ${result} = Execute on datanode ozone oz -listBucket ${protocol}${server}/${volume}/ | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.bucketName=="bb1") | .volumeName' Should Be Equal ${result} ${volume} Run Keyword and Return If ${withkeytest} Test key handling ${protocol} ${server} ${volume} Execute on datanode ozone oz -deleteBucket ${protocol}${server}/${volume}/bb1 @@ -80,6 +82,6 @@ Test key handling Execute on datanode ls -l NOTICE.txt.1 ${result} = Execute on datanode ozone oz -infoKey ${protocol}${server}/${volume}/bb1/key1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.keyName=="key1")' Should contain ${result} createdOn - ${result} = Execute on datanode ozone oz -listKey o3://ozoneManager/${volume}/bb1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.keyName=="key1") | .keyName' + ${result} = Execute on datanode ozone oz -listKey ${protocol}${server}/${volume}/bb1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.keyName=="key1") | .keyName' Should Be Equal ${result} key1 Execute on datanode ozone oz -deleteKey ${protocol}${server}/${volume}/bb1/key1 -v http://git-wip-us.apache.org/repos/asf/hadoop/blob/129269f9/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java ---------------------------------------------------------------------- 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 000d530..8f53049 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 @@ -71,6 +71,7 @@ import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.ToolRunner; import org.junit.After; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -332,7 +333,7 @@ public class TestOzoneShell { public void testListVolume() throws Exception { LOG.info("Running testListVolume"); String protocol = clientProtocol.getName().toLowerCase(); - String commandOutput; + String commandOutput, commandError; List<VolumeInfo> volumes; final int volCount = 20; final String user1 = "test-user-a-" + protocol; @@ -361,8 +362,15 @@ public class TestOzoneShell { assertNotNull(vol); } + String[] args = new String[] {"-listVolume", url + "/abcde", "-user", + user1, "-length", "100"}; + assertEquals(1, ToolRunner.run(shell, args)); + commandError = err.toString(); + Assert.assertTrue(commandError.contains("Invalid URI:")); + + err.reset(); // test -length option - String[] args = new String[] {"-listVolume", url + "/", "-user", + args = new String[] {"-listVolume", url + "/", "-user", user1, "-length", "100"}; assertEquals(0, ToolRunner.run(shell, args)); commandOutput = out.toString(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/129269f9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java index 2aec0fc..726f4ca 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java @@ -207,6 +207,7 @@ public class Shell extends Configured implements Tool { "For example : ozone oz -listVolume <ozoneURI>" + "-user <username> -root or ozone oz " + "-listVolume"); + listVolume.setOptionalArg(true); options.addOption(listVolume); Option updateVolume = http://git-wip-us.apache.org/repos/asf/hadoop/blob/129269f9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/ListVolumeHandler.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/ListVolumeHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/ListVolumeHandler.java index 3749df4..85b7b2b 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/ListVolumeHandler.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/ListVolumeHandler.java @@ -18,6 +18,7 @@ package org.apache.hadoop.ozone.web.ozShell.volume; +import com.google.common.base.Strings; import org.apache.commons.cli.CommandLine; import org.apache.hadoop.ozone.client.OzoneClientUtils; import org.apache.hadoop.ozone.client.OzoneVolume; @@ -30,6 +31,7 @@ import org.apache.hadoop.ozone.web.utils.JsonUtils; import org.apache.hadoop.ozone.web.utils.OzoneUtils; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Iterator; @@ -77,7 +79,16 @@ public class ListVolumeHandler extends Handler { } String ozoneURIString = cmd.getOptionValue(Shell.LIST_VOLUME); - verifyURI(ozoneURIString); + if (Strings.isNullOrEmpty(ozoneURIString)) { + ozoneURIString = "/"; + } + URI ozoneURI = verifyURI(ozoneURIString); + if (!Strings.isNullOrEmpty(ozoneURI.getPath()) && !ozoneURI.getPath() + .equals("/")) { + throw new OzoneClientException( + "Invalid URI: " + ozoneURI + " . Specified path not used." + ozoneURI + .getPath()); + } if (cmd.hasOption(Shell.USER)) { userName = cmd.getOptionValue(Shell.USER); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org