HDDS-208. ozone createVolume command ignores the first character of the volume 
name 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/4e59b927
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4e59b927
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4e59b927

Branch: refs/heads/YARN-7402
Commit: 4e59b9278463e4f8ccce7100d4582e896154beb8
Parents: 5d0f01e
Author: Xiaoyu Yao <x...@apache.org>
Authored: Tue Jul 10 14:07:23 2018 -0700
Committer: Xiaoyu Yao <x...@apache.org>
Committed: Tue Jul 10 14:07:23 2018 -0700

----------------------------------------------------------------------
 .../hadoop/ozone/ozShell/TestOzoneShell.java    | 26 +++++++++++++++++---
 .../web/ozShell/volume/CreateVolumeHandler.java | 10 ++++----
 2 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/4e59b927/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 5082870..a4b30f0 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
@@ -38,6 +38,7 @@ import java.util.Random;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
+import com.google.common.base.Strings;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdds.client.ReplicationFactor;
@@ -203,13 +204,32 @@ public class TestOzoneShell {
   public void testCreateVolume() throws Exception {
     LOG.info("Running testCreateVolume");
     String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
+    testCreateVolume(volumeName, "");
+    volumeName = "volume" + RandomStringUtils.randomNumeric(5);
+    testCreateVolume("/////" + volumeName, "");
+    testCreateVolume("/////", "Volume name is required to create a volume");
+    testCreateVolume("/////vol/123",
+        "Illegal argument: Bucket or Volume name has an unsupported character 
: /");
+  }
+
+  private void testCreateVolume(String volumeName, String errorMsg) throws 
Exception {
+    err.reset();
     String userName = "bilbo";
     String[] args = new String[] {"-createVolume", url + "/" + volumeName,
         "-user", userName, "-root"};
 
-    assertEquals(0, ToolRunner.run(shell, args));
-    OzoneVolume volumeInfo = client.getVolumeDetails(volumeName);
-    assertEquals(volumeName, volumeInfo.getName());
+    if (Strings.isNullOrEmpty(errorMsg)) {
+      assertEquals(0, ToolRunner.run(shell, args));
+    } else {
+      assertEquals(1, ToolRunner.run(shell, args));
+      assertTrue(err.toString().contains(errorMsg));
+      return;
+    }
+
+    String truncatedVolumeName =
+        volumeName.substring(volumeName.lastIndexOf('/') + 1);
+    OzoneVolume volumeInfo = client.getVolumeDetails(truncatedVolumeName);
+    assertEquals(truncatedVolumeName, volumeInfo.getName());
     assertEquals(userName, volumeInfo.getOwner());
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/4e59b927/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/CreateVolumeHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/CreateVolumeHandler.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/CreateVolumeHandler.java
index 74fdbb0..0057282 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/CreateVolumeHandler.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/CreateVolumeHandler.java
@@ -60,15 +60,15 @@ public class CreateVolumeHandler extends Handler {
 
     String ozoneURIString = cmd.getOptionValue(Shell.CREATE_VOLUME);
     URI ozoneURI = verifyURI(ozoneURIString);
-    if (ozoneURI.getPath().isEmpty()) {
+
+    // we need to skip the slash in the URI path
+    // getPath returns /volumeName needs to remove the initial slash.
+    volumeName = ozoneURI.getPath().replaceAll("^/+", "");
+    if (volumeName.isEmpty()) {
       throw new OzoneClientException(
           "Volume name is required to create a volume");
     }
 
-    // we need to skip the slash in the URI path
-    // getPath returns /volumeName needs to remove the first slash.
-    volumeName = ozoneURI.getPath().substring(1);
-
     if (cmd.hasOption(Shell.VERBOSE)) {
       System.out.printf("Volume name : %s%n", volumeName);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to