hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aengin...@apache.org
Subject hadoop git commit: HDDS-705. OS3Exception resource name should be the actual resource name. Contributed by Bharat Viswanadham.
Date Mon, 22 Oct 2018 16:15:44 GMT
Repository: hadoop
Updated Branches:
  refs/heads/ozone-0.3 34650b18e -> ce6919734


HDDS-705. OS3Exception resource name should be the actual resource name.
Contributed by Bharat Viswanadham.

Recommitting after making sure that patch is clean.

(cherry picked from commit 97a41b3dbeb42653c82559cd07ec4b7d7d709377)


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

Branch: refs/heads/ozone-0.3
Commit: ce6919734d9757769fb49730fda2b8689e926f85
Parents: 34650b1
Author: Nanda kumar <nanda@apache.org>
Authored: Mon Oct 22 15:48:36 2018 +0530
Committer: Anu Engineer <aengineer@apache.org>
Committed: Mon Oct 22 08:56:54 2018 -0700

----------------------------------------------------------------------
 .../ozone/s3/endpoint/BucketEndpoint.java       |  4 +-
 .../hadoop/ozone/s3/endpoint/EndpointBase.java  |  7 ++--
 .../ozone/s3/endpoint/ObjectEndpoint.java       |  9 ++---
 .../hadoop/ozone/s3/exception/S3ErrorTable.java | 39 +++-----------------
 .../ozone/s3/header/AuthorizationHeaderV2.java  | 12 ++----
 .../ozone/s3/header/AuthorizationHeaderV4.java  | 12 ++----
 .../hadoop/ozone/s3/header/Credential.java      |  3 +-
 .../ozone/s3/exception/TestOS3Exception.java    |  2 +-
 8 files changed, 24 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
index 1c31dd4..453cecc 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
@@ -199,11 +199,11 @@ public class BucketEndpoint extends EndpointBase {
     } catch (IOException ex) {
       if (ex.getMessage().contains("BUCKET_NOT_EMPTY")) {
         OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
-            .BUCKET_NOT_EMPTY, S3ErrorTable.Resource.BUCKET);
+            .BUCKET_NOT_EMPTY, bucketName);
         throw os3Exception;
       } else if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
         OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
-            .NO_SUCH_BUCKET, S3ErrorTable.Resource.BUCKET);
+            .NO_SUCH_BUCKET, bucketName);
         throw os3Exception;
       } else {
         throw ex;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
index 61f066c..c6b4e66 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
@@ -28,7 +28,6 @@ import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneVolume;
 import org.apache.hadoop.ozone.s3.exception.OS3Exception;
 import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
-import org.apache.hadoop.ozone.s3.exception.S3ErrorTable.Resource;
 import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV2;
 import org.apache.hadoop.ozone.s3.header.AuthorizationHeaderV4;
 
@@ -61,7 +60,7 @@ public class EndpointBase {
       LOG.error("Error occurred is {}", ex);
       if (ex.getMessage().contains("NOT_FOUND")) {
         OS3Exception oex =
-            S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, Resource.BUCKET);
+            S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName);
         throw oex;
       } else {
         throw ex;
@@ -80,7 +79,7 @@ public class EndpointBase {
       LOG.error("Error occurred is {}", ex);
       if (ex.getMessage().contains("NOT_FOUND")) {
         OS3Exception oex =
-            S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, Resource.BUCKET);
+            S3ErrorTable.newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName);
         throw oex;
       } else {
         throw ex;
@@ -187,7 +186,7 @@ public class EndpointBase {
 
     if (auth == null) {
       throw S3ErrorTable
-          .newError(S3ErrorTable.MALFORMED_HEADER, Resource.HEADER);
+          .newError(S3ErrorTable.MALFORMED_HEADER, auth);
     }
 
     String userName;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
index 15ad2c4..3f88af9 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
@@ -150,7 +150,7 @@ public class ObjectEndpoint extends EndpointBase {
     } catch (IOException ex) {
       if (ex.getMessage().contains("NOT_FOUND")) {
         OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
-            .NO_SUCH_OBJECT, S3ErrorTable.Resource.OBJECT);
+            .NO_SUCH_KEY, keyPath);
         throw os3Exception;
       } else {
         throw ex;
@@ -176,9 +176,8 @@ public class ObjectEndpoint extends EndpointBase {
     } catch (IOException ex) {
       LOG.error("Exception occurred in HeadObject", ex);
       if (ex.getMessage().contains("KEY_NOT_FOUND")) {
-        OS3Exception os3Exception = S3ErrorTable.newError(S3ErrorTable
-            .NO_SUCH_OBJECT, S3ErrorTable.Resource.OBJECT);
-        throw os3Exception;
+        // Just return 404 with no content
+        return Response.status(Status.NOT_FOUND).build();
       } else {
         throw ex;
       }
@@ -215,7 +214,7 @@ public class ObjectEndpoint extends EndpointBase {
     } catch (IOException ex) {
       if (ex.getMessage().contains("BUCKET_NOT_FOUND")) {
         throw S3ErrorTable.newError(S3ErrorTable
-            .NO_SUCH_BUCKET, S3ErrorTable.Resource.BUCKET);
+            .NO_SUCH_BUCKET, bucketName);
       } else if (!ex.getMessage().contains("NOT_FOUND")) {
         throw ex;
       }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
index f5adb71..9d0f767 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
@@ -45,52 +45,23 @@ public final class S3ErrorTable {
       "BucketNotEmpty", "The bucket you tried to delete is not empty.",
       HTTP_CONFLICT);
 
-  public static final OS3Exception NO_SUCH_OBJECT = new OS3Exception(
-      "NoSuchObject", "The specified object does not exist", HTTP_NOT_FOUND);
-
-
   public static final OS3Exception MALFORMED_HEADER = new OS3Exception(
       "AuthorizationHeaderMalformed", "The authorization header you provided " +
       "is invalid.", HTTP_NOT_FOUND);
 
+  public static final OS3Exception NO_SUCH_KEY = new OS3Exception(
+      "NoSuchObject", "The specified key does not exist", HTTP_NOT_FOUND);
+
   /**
    * Create a new instance of Error.
    * @param e Error Template
    * @param resource Resource associated with this exception
    * @return creates a new instance of error based on the template
    */
-  public static OS3Exception newError(OS3Exception e, Resource resource) {
+  public static OS3Exception newError(OS3Exception e, String resource) {
     OS3Exception err =  new OS3Exception(e.getCode(), e.getErrorMessage(),
         e.getHttpCode());
-    err.setResource(resource.getResource());
+    err.setResource(resource);
     return err;
   }
-
-  /**
-   * Resources, which can be defined in OS3Exception.
-   */
-  public enum Resource {
-    BUCKET("Bucket"),
-    OBJECT("Object"),
-    HEADER("header"),
-    VOLUME("Volume");
-
-    private final String resource;
-
-    /**
-     * Constructs resource.
-     * @param value
-     */
-    Resource(String value) {
-      this.resource = value;
-    }
-
-    /**
-     * Get resource.
-     * @return string
-     */
-    public String getResource() {
-      return  this.resource;
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV2.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV2.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV2.java
index e08931b..8e745f2 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV2.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV2.java
@@ -52,28 +52,24 @@ public class AuthorizationHeaderV2 {
   public void parseHeader() throws OS3Exception {
     String[] split = authHeader.split(" ");
     if (split.length != 2) {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     identifier = split[0];
     if (!IDENTIFIER.equals(identifier)) {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     String[] remainingSplit = split[1].split(":");
 
     if (remainingSplit.length != 2) {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     accessKeyID = remainingSplit[0];
     signature = remainingSplit[1];
     if (isBlank(accessKeyID) || isBlank(signature)) {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV4.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV4.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV4.java
index b6e2bf1..88c64ca 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV4.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthorizationHeaderV4.java
@@ -64,8 +64,7 @@ public class AuthorizationHeaderV4 {
     String[] split = authHeader.split(" ");
 
     if (split.length != 4) {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     algorithm = split[0];
@@ -78,24 +77,21 @@ public class AuthorizationHeaderV4 {
       credential = credential.substring(CREDENTIAL.length(), credential
           .length() - 1);
     } else {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     if (signedHeaders.startsWith(SIGNEDHEADERS)) {
       signedHeaders = signedHeaders.substring(SIGNEDHEADERS.length(),
           signedHeaders.length() - 1);
     } else {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     if (signature.startsWith(SIGNATURE)) {
       signature = signature.substring(SIGNATURE.length(), signature
           .length());
     } else {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, authHeader);
     }
 
     // Parse credential. Other parts of header are not validated yet. When

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/Credential.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/Credential.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/Credential.java
index b8c519b..19699a0 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/Credential.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/Credential.java
@@ -63,8 +63,7 @@ public class Credential {
       awsService = split[3];
       awsRequest = split[4];
     } else {
-      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, S3ErrorTable
-          .Resource.HEADER);
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, credential);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce691973/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exception.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exception.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exception.java
index 3611123..fa6e2c7 100644
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exception.java
+++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exception.java
@@ -32,7 +32,7 @@ public class TestOS3Exception {
     OS3Exception ex = new OS3Exception("AccessDenied", "Access Denied",
         403);
     String requestId = OzoneUtils.getRequestID();
-    ex = S3ErrorTable.newError(ex, S3ErrorTable.Resource.BUCKET);
+    ex = S3ErrorTable.newError(ex, "bucket");
     ex.setRequestId(requestId);
     String val = ex.toXml();
     String formatString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +


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