You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ar...@apache.org on 2015/06/22 19:22:47 UTC
hadoop git commit: HDFS-8637. OzoneHandler : Add Error Table.
(Contributed by Anu Engineer)
Repository: hadoop
Updated Branches:
refs/heads/HDFS-7240 e2f20ce92 -> 1e7514249
HDFS-8637. OzoneHandler : Add Error Table. (Contributed by Anu Engineer)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/1e751424
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/1e751424
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/1e751424
Branch: refs/heads/HDFS-7240
Commit: 1e7514249a559cb7f65b43044a18ab74c0e149c7
Parents: e2f20ce
Author: Arpit Agarwal <ar...@apache.org>
Authored: Mon Jun 22 10:22:29 2015 -0700
Committer: Arpit Agarwal <ar...@apache.org>
Committed: Mon Jun 22 10:22:29 2015 -0700
----------------------------------------------------------------------
.../hadoop-hdfs/CHANGES-HDFS-7240.txt | 3 +
.../hadoop/ozone/web/exceptions/ErrorTable.java | 204 +++++++++++++++++++
.../ozone/web/exceptions/OzoneException.java | 19 +-
3 files changed, 224 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/1e751424/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-7240.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-7240.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-7240.txt
index e0fea38..c7b2e19 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-7240.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-7240.txt
@@ -14,3 +14,6 @@
functionality into parent interface. (Arpit Agarwal)
HDFS-8448. Create REST Interface for Volumes. (Anu Engineer via cnauroth)
+
+ HDFS-8637. OzoneHandler : Add Error Table. (Anu Engineer via Arpit Agarwal)
+
http://git-wip-us.apache.org/repos/asf/hadoop/blob/1e751424/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/ErrorTable.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/ErrorTable.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/ErrorTable.java
new file mode 100644
index 0000000..be49d04
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/ErrorTable.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.web.exceptions;
+
+import org.apache.hadoop.ozone.web.handlers.UserArgs;
+
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
+import static java.net.HttpURLConnection.HTTP_CONFLICT;
+import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
+import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+/**
+ * Error Table represents the Errors from Ozone Rest API layer.
+ *
+ * Please note : The errors in this table are sorted by the HTTP_ERROR codes
+ * if you add new error codes to this table please follow the same convention.
+ */
+public final class ErrorTable {
+
+ /* Error 400 */
+ public static final OzoneException MISSING_VERSION =
+ new OzoneException(HTTP_BAD_REQUEST, "missingVersion",
+ "x-ozone-version header is required.");
+
+ public static final OzoneException MISSING_DATE =
+ new OzoneException(HTTP_BAD_REQUEST, "missingDate",
+ "Date header is required.");
+
+ public static final OzoneException BAD_DATE =
+ new OzoneException(HTTP_BAD_REQUEST, "badDate",
+ "Unable to parse date format.");
+
+ public static final OzoneException MALFORMED_QUOTA =
+ new OzoneException(HTTP_BAD_REQUEST, "malformedQuota",
+ "Invalid quota specified.");
+
+ public static final OzoneException MALFORMED_ACL =
+ new OzoneException(HTTP_BAD_REQUEST, "malformedACL",
+ "Invalid ACL specified.");
+
+ public static final OzoneException INVALID_VOLUME_NAME =
+ new OzoneException(HTTP_BAD_REQUEST, "invalidVolumeName",
+ "Invalid volume name.");
+
+ public static final OzoneException INVALID_QUERY_PARAM =
+ new OzoneException(HTTP_BAD_REQUEST, "invalidQueryParam",
+ "Invalid query parameter.");
+
+ public static final OzoneException INVALID_BUCKET_NAME =
+ new OzoneException(HTTP_BAD_REQUEST, "invalidBucketName",
+ "Invalid bucket name.");
+
+ public static final OzoneException INVALID_KEY =
+ new OzoneException(HTTP_BAD_REQUEST, "invalidKey", "Invalid key.");
+
+ public static final OzoneException INVALID_REQUEST =
+ new OzoneException(HTTP_BAD_REQUEST, "invalidRequest",
+ "Error in request.");
+
+ public static final OzoneException MALFORMED_BUCKET_VERSION =
+ new OzoneException(HTTP_BAD_REQUEST, "malformedBucketVersion",
+ "Malformed bucket version or version not unique.");
+
+ public static final OzoneException MALFORMED_STORAGE_CLASS =
+ new OzoneException(HTTP_BAD_REQUEST, "malformedStorageClass",
+ "Invalid storage class specified.");
+
+ public static final OzoneException BAD_DIGEST =
+ new OzoneException(HTTP_BAD_REQUEST, "badDigest",
+ "Content MD5 does not match.");
+
+ public static final OzoneException INCOMPLETE_BODY =
+ new OzoneException(HTTP_BAD_REQUEST, "incompleteBody",
+ "Content length does not match stream size.");
+
+ public static final OzoneException BAD_AUTHORIZATION =
+ new OzoneException(HTTP_BAD_REQUEST, "badAuthorization",
+ "Missing authorization or authorization has to be " +
+ "unique.");
+
+ /* Error 401 */
+ public static final OzoneException UNAUTHORIZED =
+ new OzoneException(HTTP_UNAUTHORIZED, "Unauthorized",
+ "Access token is missing or invalid token.");
+
+ /* Error 403 */
+ public static final OzoneException ACCESS_DENIED =
+ new OzoneException(HTTP_FORBIDDEN, "accessDenied", "Access denied.");
+
+ /* Error 404 */
+ public static final OzoneException USER_NOT_FOUND =
+ new OzoneException(HTTP_NOT_FOUND, "userNotFound", "Invalid user name.");
+
+ public static final OzoneException VOLUME_NOT_FOUND =
+ new OzoneException(HTTP_NOT_FOUND, "volumeNotFound", "No such volume.");
+
+ /* Error 409 */
+ public static final OzoneException VOLUME_ALREADY_EXISTS =
+ new OzoneException(HTTP_CONFLICT, "volumeAlreadyExists",
+ "Duplicate volume name.");
+
+ public static final OzoneException BUCKET_ALREADY_EXISTS =
+ new OzoneException(HTTP_CONFLICT, "bucketAlreadyExists",
+ "Duplicate bucket name.");
+
+ public static final OzoneException VOLUME_NOT_EMPTY =
+ new OzoneException(HTTP_CONFLICT, "volumeNotEmpty",
+ "Volume must not have any buckets.");
+
+ public static final OzoneException BUCKET_NOT_EMPTY =
+ new OzoneException(HTTP_CONFLICT, "bucketNotEmpty",
+ "Bucket must not have any keys.");
+
+ public static final OzoneException KEY_OPERATION_CONFLICT =
+ new OzoneException(HTTP_CONFLICT, "keyOperationConflict",
+ "Conflicting operation on the specified key is going" +
+ " on.");
+
+ /* Error 500 */
+ public static final OzoneException SERVER_ERROR =
+ new OzoneException(HTTP_INTERNAL_ERROR, "internalServerError",
+ "Internal server error.");
+
+ /**
+ * Create a new instance of Error.
+ *
+ * @param e Error Template
+ * @param requestID Request ID
+ * @param resource Resource Name
+ * @param hostID hostID
+ *
+ * @return creates a new instance of error based on the template
+ */
+ public static OzoneException newError(OzoneException e, long requestID,
+ String resource, String hostID) {
+ OzoneException err =
+ new OzoneException(e.getHttpCode(), e.getShortMessage(),
+ e.getMessage());
+ err.setRequestId(Long.toString(requestID));
+ err.setResource(resource);
+ err.setHostID(hostID);
+ return err;
+ }
+
+ /**
+ * Create new instance of Error.
+ *
+ * @param e - Error Template
+ * @param args - Args
+ *
+ * @return Ozone Exception
+ */
+ public static OzoneException newError(OzoneException e, UserArgs args) {
+ OzoneException err =
+ new OzoneException(e.getHttpCode(), e.getShortMessage(),
+ e.getMessage());
+ err.setRequestId(Long.toString(args.getRequestID()));
+ err.setResource(args.getResourceName());
+ err.setHostID(args.getHostName());
+ return err;
+ }
+
+ /**
+ * Create new instance of Error.
+ *
+ * @param e - Error Template
+ * @param args - Args
+ * @param ex Exception
+ *
+ * @return Ozone Exception
+ */
+ public static OzoneException newError(OzoneException e, UserArgs args,
+ Exception ex) {
+ OzoneException err =
+ new OzoneException(e.getHttpCode(), e.getShortMessage(), ex);
+ err.setRequestId(Long.toString(args.getRequestID()));
+ err.setResource(args.getResourceName());
+ err.setHostID(args.getHostName());
+ err.setMessage(ex.getMessage());
+ return err;
+ }
+
+ private ErrorTable() {
+ // Never constructed.
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/1e751424/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/OzoneException.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/OzoneException.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/OzoneException.java
index 04458c1..e4a2b2f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/OzoneException.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/exceptions/OzoneException.java
@@ -46,6 +46,21 @@ public class OzoneException extends Exception {
/**
+ * Constructor that allows a shortMessage and exception.
+ *
+ * @param httpCode Error Code
+ * @param shortMessage Short Message
+ * @param ex Exception
+ */
+ public OzoneException(long httpCode, String shortMessage, Exception ex) {
+ super(ex);
+ this.message = ex.getMessage();
+ this.shortMessage = shortMessage;
+ this.httpCode = httpCode;
+ }
+
+
+ /**
* Constructor that allows a shortMessage.
*
* @param httpCode Error Code
@@ -68,7 +83,7 @@ public class OzoneException extends Exception {
this.resource = message;
this.httpCode = httpCode;
}
-
+
/**
* Returns the Resource that was involved in the exception.
*
@@ -99,7 +114,7 @@ public class OzoneException extends Exception {
/**
* Sets the error message.
*
- * @param longMessage - Long message
+ * @param longMessage - Long message
*/
public void setMessage(String longMessage) {
this.message = longMessage;