hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yq...@apache.org
Subject hadoop git commit: HDFS-8741. Proper error msg to be printed when invalid operation type is given to WebHDFS operations. Contributed by Surendra Singh Lilhore.
Date Mon, 06 Mar 2017 11:04:47 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk fad766e1d -> 3536ce031


HDFS-8741. Proper error msg to be printed when invalid operation type is given to WebHDFS
operations. Contributed by Surendra Singh Lilhore.


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

Branch: refs/heads/trunk
Commit: 3536ce031ca780d6de83cf67779f571a0142ccc8
Parents: fad766e
Author: Yiqun Lin <yqlin@apache.org>
Authored: Mon Mar 6 19:04:03 2017 +0800
Committer: Yiqun Lin <yqlin@apache.org>
Committed: Mon Mar 6 19:04:03 2017 +0800

----------------------------------------------------------------------
 .../hdfs/web/resources/DeleteOpParam.java       | 11 +++++-
 .../hadoop/hdfs/web/resources/GetOpParam.java   | 11 +++++-
 .../hadoop/hdfs/web/resources/PostOpParam.java  | 11 +++++-
 .../hadoop/hdfs/web/resources/PutOpParam.java   | 11 +++++-
 .../hadoop/hdfs/web/resources/TestParam.java    | 41 ++++++++++++++++++++
 5 files changed, 81 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/3536ce03/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/DeleteOpParam.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/DeleteOpParam.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/DeleteOpParam.java
index 25bed1c..e765498 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/DeleteOpParam.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/DeleteOpParam.java
@@ -72,7 +72,16 @@ public class DeleteOpParam extends HttpOpParam<DeleteOpParam.Op>
{
    * @param str a string representation of the parameter value.
    */
   public DeleteOpParam(final String str) {
-    super(DOMAIN, DOMAIN.parse(str));
+    super(DOMAIN, getOp(str));
+  }
+
+  private static Op getOp(String str) {
+    try {
+      return DOMAIN.parse(str);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException(str + " is not a valid " + Type.DELETE
+          + " operation.");
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/3536ce03/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/GetOpParam.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/GetOpParam.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/GetOpParam.java
index 1321bf6..d32af33 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/GetOpParam.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/GetOpParam.java
@@ -111,7 +111,16 @@ public class GetOpParam extends HttpOpParam<GetOpParam.Op> {
    * @param str a string representation of the parameter value.
    */
   public GetOpParam(final String str) {
-    super(DOMAIN, DOMAIN.parse(str));
+    super(DOMAIN, getOp(str));
+  }
+
+  private static Op getOp(String str) {
+    try {
+      return DOMAIN.parse(str);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException(str + " is not a valid " + Type.GET
+          + " operation.");
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/3536ce03/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PostOpParam.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PostOpParam.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PostOpParam.java
index 56a14c7..305db46 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PostOpParam.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PostOpParam.java
@@ -80,7 +80,16 @@ public class PostOpParam extends HttpOpParam<PostOpParam.Op> {
    * @param str a string representation of the parameter value.
    */
   public PostOpParam(final String str) {
-    super(DOMAIN, DOMAIN.parse(str));
+    super(DOMAIN, getOp(str));
+  }
+
+  private static Op getOp(String str) {
+    try {
+      return DOMAIN.parse(str);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException(str + " is not a valid " + Type.POST
+          + " operation.");
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/3536ce03/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java
index 4bb48a6..558bb53 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java
@@ -107,7 +107,16 @@ public class PutOpParam extends HttpOpParam<PutOpParam.Op> {
    * @param str a string representation of the parameter value.
    */
   public PutOpParam(final String str) {
-    super(DOMAIN, DOMAIN.parse(str));
+    super(DOMAIN, getOp(str));
+  }
+
+  private static Op getOp(String str) {
+    try {
+      return DOMAIN.parse(str);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException(str + " is not a valid " + Type.PUT
+          + " operation.");
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/3536ce03/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
index d444cb4..6c145a4 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/resources/TestParam.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.fs.XAttrSetFlag;
 import org.apache.hadoop.fs.permission.AclEntry;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.junit.Assert;
 import org.junit.Test;
@@ -503,4 +504,44 @@ public class TestParam {
     p = new StoragePolicyParam("COLD");
     Assert.assertEquals("COLD", p.getValue());
   }
+
+  @Test
+  public void testHttpOpParams() {
+    try {
+      new PostOpParam("TEST");
+      Assert
+          .fail("Construct the PostOpParam with param value 'TEST' should be"
+              + " failed.");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains(
+          "TEST is not a valid POST operation.", e);
+    }
+    try {
+      new PutOpParam("TEST");
+      Assert
+          .fail("Construct the PutOpParam with param value 'TEST' should be"
+              + " failed.");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains(
+          "TEST is not a valid PUT operation.", e);
+    }
+    try {
+      new DeleteOpParam("TEST");
+      Assert
+          .fail("Construct the DeleteOpParam with param value 'TEST' should be"
+              + " failed.");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains(
+          "TEST is not a valid DELETE operation.", e);
+    }
+    try {
+      new GetOpParam("TEST");
+      Assert
+          .fail("Construct the GetOpParam with param value 'TEST' should be"
+              + " failed.");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains(
+          "TEST is not a valid GET operation.", e);
+    }
+  }
 }


---------------------------------------------------------------------
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