hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x...@apache.org
Subject [30/50] [abbrv] hadoop git commit: HDDS-289. Volume and Bucket name should not contain a delimiter ('/'). Contributed by chencan.
Date Mon, 01 Oct 2018 18:18:19 GMT
HDDS-289. Volume and Bucket name should not contain a delimiter ('/'). Contributed by chencan.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/72891fc9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/72891fc9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/72891fc9

Branch: refs/heads/HDDS-4
Commit: 72891fc9be142ada485f06e63cd7108c54241d4b
Parents: 3c798c1
Author: Hanisha Koneru <hanishakoneru@apache.org>
Authored: Fri Sep 28 11:24:42 2018 -0700
Committer: Hanisha Koneru <hanishakoneru@apache.org>
Committed: Fri Sep 28 11:24:42 2018 -0700

----------------------------------------------------------------------
 .../hadoop/ozone/ozShell/TestOzoneShell.java    | 55 +++++++++++++++-----
 .../web/ozShell/bucket/CreateBucketHandler.java | 13 +++--
 .../web/ozShell/bucket/InfoBucketHandler.java   | 14 +++--
 .../web/ozShell/bucket/ListBucketHandler.java   | 12 ++++-
 .../ozone/web/ozShell/keys/ListKeyHandler.java  | 13 +++--
 .../web/ozShell/volume/CreateVolumeHandler.java | 21 +++++---
 .../web/ozShell/volume/InfoVolumeHandler.java   | 16 ++++--
 7 files changed, 108 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/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 fbb3eae..6e73b8c 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
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.ozone.ozShell;
 
+import com.google.common.base.Strings;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -31,7 +32,7 @@ import java.util.List;
 import java.util.Random;
 import java.util.UUID;
 import java.util.stream.Collectors;
-
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdds.cli.MissingSubcommandException;
 import org.apache.hadoop.hdds.client.ReplicationFactor;
@@ -60,17 +61,9 @@ import org.apache.hadoop.ozone.web.response.KeyInfo;
 import org.apache.hadoop.ozone.web.response.VolumeInfo;
 import org.apache.hadoop.ozone.web.utils.JsonUtils;
 import org.apache.hadoop.test.GenericTestUtils;
-
-import com.google.common.base.Strings;
-import org.apache.commons.lang3.RandomStringUtils;
-import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -87,6 +80,12 @@ import picocli.CommandLine.ParameterException;
 import picocli.CommandLine.ParseResult;
 import picocli.CommandLine.RunLast;
 
+import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 /**
  * This test class specified for testing Ozone shell command.
  */
@@ -211,8 +210,7 @@ public class TestOzoneShell {
     testCreateVolume("/////", "Volume name is required " +
         "to create a volume");
     testCreateVolume("/////vol/123",
-        "Bucket or Volume name has " +
-            "an unsupported character : /");
+        "Invalid volume name. Delimiters (/) not allowed in volume name");
   }
 
   private void testCreateVolume(String volumeName, String errorMsg)
@@ -305,6 +303,12 @@ public class TestOzoneShell {
     assertTrue(output.contains("createdOn")
         && output.contains(OzoneConsts.OZONE_TIME_ZONE));
 
+    // test infoVolume with invalid volume name
+    args = new String[] {"volume", "info",
+        url + "/" + volumeName + "/invalid-name"};
+    executeWithError(shell, args, "Invalid volume name. " +
+        "Delimiters (/) not allowed in volume name");
+
     // get info for non-exist volume
     args = new String[] {"volume", "info", url + "/invalid-volume"};
     executeWithError(shell, args, "VOLUME_NOT_FOUND");
@@ -563,8 +567,13 @@ public class TestOzoneShell {
     // test create a bucket in a non-exist volume
     args = new String[] {"bucket", "create",
         url + "/invalid-volume/" + bucketName};
-
     executeWithError(shell, args, "Info Volume failed, error:VOLUME_NOT_FOUND");
+
+    // test createBucket with invalid bucket name
+    args = new String[] {"bucket", "create",
+        url + "/" + vol.getName() + "/" + bucketName + "/invalid-name"};
+    executeWithError(shell, args,
+        "Invalid bucket name. Delimiters (/) not allowed in bucket name");
   }
 
   @Test
@@ -618,6 +627,12 @@ public class TestOzoneShell {
     assertTrue(output.contains("createdOn")
         && output.contains(OzoneConsts.OZONE_TIME_ZONE));
 
+    // test infoBucket with invalid bucket name
+    args = new String[] {"bucket", "info",
+        url + "/" + vol.getName() + "/" + bucketName + "/invalid-name"};
+    executeWithError(shell, args,
+        "Invalid bucket name. Delimiters (/) not allowed in bucket name");
+
     // test get info from a non-exist bucket
     args = new String[] {"bucket", "info",
         url + "/" + vol.getName() + "/invalid-bucket" + bucketName};
@@ -688,8 +703,14 @@ public class TestOzoneShell {
       assertNotNull(bucket);
     }
 
-    // test -length option
+    // test listBucket with invalid volume name
     String[] args = new String[] {"bucket", "list",
+        url + "/" + vol.getName() + "/invalid-name"};
+    executeWithError(shell, args, "Invalid volume name. " +
+        "Delimiters (/) not allowed in volume name");
+
+    // test -length option
+    args = new String[] {"bucket", "list",
         url + "/" + vol.getName(), "--length", "100"};
     execute(shell, args);
     commandOutput = out.toString();
@@ -954,8 +975,14 @@ public class TestOzoneShell {
       keyOutputStream.close();
     }
 
-    // test -length option
+    // test listKey with invalid bucket name
     String[] args = new String[] {"key", "list",
+        url + "/" + volumeName + "/" + bucketName + "/invalid-name"};
+    executeWithError(shell, args, "Invalid bucket name. " +
+        "Delimiters (/) not allowed in bucket name");
+
+    // test -length option
+    args = new String[] {"key", "list",
         url + "/" + volumeName + "/" + bucketName, "--length", "100"};
     execute(shell, args);
     commandOutput = out.toString();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/CreateBucketHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/CreateBucketHandler.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/CreateBucketHandler.java
index bd8db60..49bbc18 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/CreateBucketHandler.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/CreateBucketHandler.java
@@ -50,9 +50,16 @@ public class CreateBucketHandler extends Handler {
 
     URI ozoneURI = verifyURI(uri);
     Path path = Paths.get(ozoneURI.getPath());
-    if (path.getNameCount() < 2) {
-      throw new OzoneClientException(
-          "volume and bucket name required in createBucket");
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 2) {
+      String errorMessage;
+      if (pathNameCount < 2) {
+        errorMessage = "volume and bucket name required in createBucket";
+      } else {
+        errorMessage = "Invalid bucket name. Delimiters (/) not allowed in " +
+            "bucket name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
     String volumeName = path.getName(0).toString();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
index 4122b72..18f8a0b 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
@@ -50,10 +50,16 @@ public class InfoBucketHandler extends Handler {
     String volumeName, bucketName;
     URI ozoneURI = verifyURI(uri);
     Path path = Paths.get(ozoneURI.getPath());
-
-    if (path.getNameCount() < 2) {
-      throw new OzoneClientException(
-          "volume and bucket name required in info Bucket");
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 2) {
+      String errorMessage;
+      if (pathNameCount < 2) {
+        errorMessage = "volume and bucket name required in infoBucket";
+      } else {
+        errorMessage = "Invalid bucket name. Delimiters (/) not allowed in " +
+            "bucket name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
     volumeName = path.getName(0).toString();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/ListBucketHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/ListBucketHandler.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/ListBucketHandler.java
index d8c824b..7c3029a 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/ListBucketHandler.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/ListBucketHandler.java
@@ -71,8 +71,16 @@ public class ListBucketHandler extends Handler {
 
     URI ozoneURI = verifyURI(uri);
     Path path = Paths.get(ozoneURI.getPath());
-    if (path.getNameCount() < 1) {
-      throw new OzoneClientException("volume is required in listBucket");
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 1) {
+      String errorMessage;
+      if (pathNameCount < 1) {
+        errorMessage = "volume is required in listBucket";
+      } else {
+        errorMessage = "Invalid volume name. Delimiters (/) not allowed in " +
+            "volume name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
     if (maxBuckets < 1) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java
----------------------------------------------------------------------
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 3c019a6..c539d60 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
@@ -71,9 +71,16 @@ public class ListKeyHandler extends Handler {
 
     URI ozoneURI = verifyURI(uri);
     Path path = Paths.get(ozoneURI.getPath());
-    if (path.getNameCount() < 2) {
-      throw new OzoneClientException(
-          "volume/bucket is required in listKey");
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 2) {
+      String errorMessage;
+      if (pathNameCount < 2) {
+        errorMessage = "volume/bucket is required in listKey";
+      } else {
+        errorMessage = "Invalid bucket name. Delimiters (/) not allowed in " +
+            "bucket name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
     if (maxKeys < 1) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/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 2697639..de0fbaa 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
@@ -19,6 +19,8 @@
 package org.apache.hadoop.ozone.web.ozShell.volume;
 
 import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import org.apache.hadoop.ozone.client.OzoneClientException;
 import org.apache.hadoop.ozone.client.OzoneClientUtils;
@@ -64,15 +66,20 @@ public class CreateVolumeHandler extends Handler {
   public Void call() throws Exception {
 
     URI ozoneURI = verifyURI(uri);
-
-    // we need to skip the slash in the URI path
-    // getPath returns /volumeName needs to remove the initial slash.
-    String volumeName = ozoneURI.getPath().replaceAll("^/+", "");
-    if (volumeName.isEmpty()) {
-      throw new OzoneClientException(
-          "Volume name is required to create a volume");
+    Path path = Paths.get(ozoneURI.getPath());
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 1) {
+      String errorMessage;
+      if (pathNameCount < 1) {
+        errorMessage = "Volume name is required to create a volume";
+      } else {
+        errorMessage = "Invalid volume name. Delimiters (/) not allowed in " +
+            "volume name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
+    String volumeName = ozoneURI.getPath().replaceAll("^/+", "");
     if (isVerbose()) {
       System.out.printf("Volume name : %s%n", volumeName);
     }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/72891fc9/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/InfoVolumeHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/InfoVolumeHandler.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/InfoVolumeHandler.java
index 60a8c6d..16c0342 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/InfoVolumeHandler.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/volume/InfoVolumeHandler.java
@@ -19,6 +19,8 @@
 package org.apache.hadoop.ozone.web.ozShell.volume;
 
 import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import org.apache.hadoop.ozone.client.OzoneClientException;
 import org.apache.hadoop.ozone.client.OzoneClientUtils;
@@ -47,9 +49,17 @@ public class InfoVolumeHandler extends Handler{
   public Void call() throws Exception {
 
     URI ozoneURI = verifyURI(uri);
-    if (ozoneURI.getPath().isEmpty()) {
-      throw new OzoneClientException(
-          "Volume name is required to get info of a volume");
+    Path path = Paths.get(ozoneURI.getPath());
+    int pathNameCount = path.getNameCount();
+    if (pathNameCount != 1) {
+      String errorMessage;
+      if (pathNameCount < 1) {
+        errorMessage = "Volume name is required to get info of a volume";
+      } else {
+        errorMessage = "Invalid volume name. Delimiters (/) not allowed in " +
+            "volume name";
+      }
+      throw new OzoneClientException(errorMessage);
     }
 
     // we need to skip the slash in the URI path


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


Mime
View raw message