hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [39/50] [abbrv] hadoop git commit: HADOOP-15809. ABFS: better exception handling when making getAccessToken call. Contributed by Da Zhou
Date Mon, 08 Oct 2018 08:48:02 GMT
HADOOP-15809. ABFS: better exception handling when making getAccessToken call.
Contributed by Da Zhou


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

Branch: refs/heads/HEAD
Commit: 273cc2d4e972dc7cc371761a4ab2d1bc20dd5ca0
Parents: 94d82f4
Author: Steve Loughran <stevel@apache.org>
Authored: Fri Oct 5 11:29:03 2018 +0100
Committer: Steve Loughran <stevel@apache.org>
Committed: Fri Oct 5 11:29:03 2018 +0100

----------------------------------------------------------------------
 .../exceptions/AbfsRestOperationException.java  |  9 +++++
 .../azurebfs/oauth2/AzureADAuthenticator.java   | 35 +++++++++++---------
 .../fs/azurebfs/services/AbfsRestOperation.java |  9 +++++
 3 files changed, 38 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/273cc2d4/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/AbfsRestOperationException.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/AbfsRestOperationException.java
b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/AbfsRestOperationException.java
index f0b69ef..149f916 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/AbfsRestOperationException.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/AbfsRestOperationException.java
@@ -22,6 +22,7 @@ package org.apache.hadoop.fs.azurebfs.contracts.exceptions;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
+import org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.HttpException;
 import org.apache.hadoop.fs.azurebfs.services.AbfsHttpOperation;
 
 /**
@@ -59,6 +60,14 @@ public class AbfsRestOperationException extends AzureBlobFileSystemException
{
     this.errorMessage = errorMessage;
   }
 
+  public AbfsRestOperationException(final HttpException innerException) {
+    super(innerException.getMessage());
+
+    this.statusCode = innerException.getHttpErrorCode();
+    this.errorCode = AzureServiceErrorCode.UNKNOWN;
+    this.errorMessage = innerException.getMessage();
+  }
+
   public int getStatusCode() {
     return this.statusCode;
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/273cc2d4/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/AzureADAuthenticator.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/AzureADAuthenticator.java
b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/AzureADAuthenticator.java
index e82dc95..97415ce 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/AzureADAuthenticator.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/AzureADAuthenticator.java
@@ -161,14 +161,28 @@ public final class AzureADAuthenticator {
     return getTokenCall(authEndpoint, qp.serialize(), null, null);
   }
 
-  private static class HttpException extends IOException {
+
+  /**
+   * This exception class contains the http error code,
+   * requestId and error message, it is thrown when AzureADAuthenticator
+   * failed to get the Azure Active Directory token.
+   */
+  public static class HttpException extends IOException {
     private int httpErrorCode;
     private String requestId;
 
+    /**
+     * Gets Http error status code.
+     * @return  http error code.
+     */
     public int getHttpErrorCode() {
       return this.httpErrorCode;
     }
 
+    /**
+     * Gets http request id .
+     * @return  http request id.
+     */
     public String getRequestId() {
       return this.requestId;
     }
@@ -188,21 +202,17 @@ public final class AzureADAuthenticator {
             = new ExponentialRetryPolicy(3, 0, 1000, 2);
 
     int httperror = 0;
-    String requestId;
-    String httpExceptionMessage = null;
     IOException ex = null;
     boolean succeeded = false;
     int retryCount = 0;
     do {
       httperror = 0;
-      requestId = "";
       ex = null;
       try {
         token = getTokenSingleCall(authEndpoint, body, headers, httpMethod);
       } catch (HttpException e) {
         httperror = e.httpErrorCode;
-        requestId = e.requestId;
-        httpExceptionMessage = e.getMessage();
+        ex = e;
       } catch (IOException e) {
         ex = e;
       }
@@ -210,12 +220,7 @@ public final class AzureADAuthenticator {
       retryCount++;
     } while (!succeeded && retryPolicy.shouldRetry(retryCount, httperror));
     if (!succeeded) {
-      if (ex != null) {
-        throw ex;
-      }
-      if (httperror != 0) {
-        throw new IOException(httpExceptionMessage);
-      }
+      throw ex;
     }
     return token;
   }
@@ -263,7 +268,7 @@ public final class AzureADAuthenticator {
         InputStream httpResponseStream = conn.getInputStream();
         token = parseTokenFromStream(httpResponseStream);
       } else {
-        String responseBody = consumeInputStream(conn.getInputStream(), 1024);
+        String responseBody = consumeInputStream(conn.getErrorStream(), 1024);
         String proxies = "none";
         String httpProxy = System.getProperty("http.proxy");
         String httpsProxy = System.getProperty("https.proxy");
@@ -273,11 +278,11 @@ public final class AzureADAuthenticator {
         String logMessage =
                 "AADToken: HTTP connection failed for getting token from AzureAD. Http response:
"
                         + httpResponseCode + " " + conn.getResponseMessage()
-                        + " Content-Type: " + responseContentType
+                        + "\nContent-Type: " + responseContentType
                         + " Content-Length: " + responseContentLength
                         + " Request ID: " + requestId.toString()
                         + " Proxies: " + proxies
-                        + " First 1K of Body: " + responseBody;
+                        + "\nFirst 1K of Body: " + responseBody;
         LOG.debug(logMessage);
         throw new HttpException(httpResponseCode, requestId, logMessage);
       }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/273cc2d4/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
index 3f5717e..9c60f7c 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationExcep
 import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
 import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidAbfsRestOperationException;
 import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.HttpException;
 
 /**
  * The AbfsRestOperation for Rest AbfsClient.
@@ -175,6 +176,14 @@ public class AbfsRestOperation {
       if (!client.getRetryPolicy().shouldRetry(retryCount, -1)) {
         throw new InvalidAbfsRestOperationException(ex);
       }
+
+      // once HttpException is thrown by AzureADAuthenticator,
+      // it indicates the policy in AzureADAuthenticator determined
+      // retry is not needed
+      if (ex instanceof HttpException) {
+        throw new AbfsRestOperationException((HttpException) ex);
+      }
+
       return false;
     } finally {
       AbfsClientThrottlingIntercept.updateMetrics(operationType, httpOperation);


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