You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2021/08/26 06:45:09 UTC
[GitHub] [hadoop] snvijaya opened a new pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
snvijaya opened a new pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335
This commit aims to facilitate upcoming work as part of adding an alternate connection to store backend - [HADOOP-17853](https://issues.apache.org/jira/browse/HADOOP-17853)
The scope of the change is to make AbfsHttpOperation an abstract class and create a child class AbfsHttpConnection. Future connection types will be added as child of AbfsHttpOperation. Retaining the abstract class name to reduce any backport pain.
ABFS driver tests were run with HNS and non-HNS storage accounts over combinations of authentication types - OAuth and SharedKey. Tests results will be updated in conversation tab with each PR iteration.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#issuecomment-906142303
:::: AGGREGATED TEST RESULT ::::
HNS-OAuth
========================
[INFO] Results:
[INFO]
[WARNING] Tests run: 106, Failures: 0, Errors: 0, Skipped: 1
[INFO] Results:
[INFO]
[WARNING] Tests run: 558, Failures: 0, Errors: 0, Skipped: 98
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] ITestAbfsReadWriteAndSeek.testReadAndWriteWithDifferentBufferSizesAndSeek:66->testReadWriteAndSeek:81 » TestTimedOut
[INFO]
[ERROR] Tests run: 259, Failures: 0, Errors: 1, Skipped: 52
HNS-SharedKey
========================
[INFO] Results:
[INFO]
[WARNING] Tests run: 106, Failures: 0, Errors: 0, Skipped: 2
[INFO] Results:
[INFO]
[WARNING] Tests run: 558, Failures: 0, Errors: 0, Skipped: 67
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] ITestAbfsReadWriteAndSeek.testReadAndWriteWithDifferentBufferSizesAndSeek:66->testReadWriteAndSeek:81 » TestTimedOut
[INFO]
[ERROR] Tests run: 259, Failures: 0, Errors: 1, Skipped: 40
NonHNS-SharedKey
========================
[INFO] Results:
[INFO]
[WARNING] Tests run: 106, Failures: 0, Errors: 0, Skipped: 2
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] ITestAzureBlobFileSystemCheckAccess.testCheckAccessForAccountWithoutNS:181 Expecting org.apache.hadoop.security.AccessControlException with text "This request is not authorized to perform this operation using this permission.", 403 but got : "void"
[INFO]
[ERROR] Tests run: 558, Failures: 1, Errors: 0, Skipped: 276
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] ITestAbfsReadWriteAndSeek.testReadAndWriteWithDifferentBufferSizesAndSeek:66->testReadWriteAndSeek:81 » TestTimedOut
[INFO]
[ERROR] Tests run: 259, Failures: 0, Errors: 1, Skipped: 40
3 tests that failed with timeout is set for more than 100MB buffer size choking the dev VM network when tests are run in parallel over 8 processes. When run individually they pass.
Test failure observed in NonHNS-SharedKey: ITestAzureBlobFileSystemCheckAccess.testCheckAccessForAccountWithoutNS
is fixed as part of [HADOOP-17767](https://issues.apache.org/jira/browse/HADOOP-17767)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701920531
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
Review comment:
Have created a separate PR to address these comments to refactor the Http request handling [HADOOP-17890 PR](https://github.com/apache/hadoop/pull/3381) . The JSON parsing code is in a method parseListFilesResponse which takes input stream as a parameter to it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] hadoop-yetus commented on pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
hadoop-yetus commented on pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#issuecomment-906186547
:confetti_ball: **+1 overall**
| Vote | Subsystem | Runtime | Logfile | Comment |
|:----:|----------:|--------:|:--------:|:-------:|
| +0 :ok: | reexec | 0m 55s | | Docker mode activated. |
|||| _ Prechecks _ |
| +1 :green_heart: | dupname | 0m 1s | | No case conflicting files found. |
| +0 :ok: | codespell | 0m 0s | | codespell was not available. |
| +1 :green_heart: | @author | 0m 0s | | The patch does not contain any @author tags. |
| +1 :green_heart: | test4tests | 0m 0s | | The patch appears to include 3 new or modified test files. |
|||| _ trunk Compile Tests _ |
| +1 :green_heart: | mvninstall | 32m 22s | | trunk passed |
| +1 :green_heart: | compile | 0m 37s | | trunk passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | compile | 0m 31s | | trunk passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | checkstyle | 0m 25s | | trunk passed |
| +1 :green_heart: | mvnsite | 0m 38s | | trunk passed |
| +1 :green_heart: | javadoc | 0m 28s | | trunk passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javadoc | 0m 26s | | trunk passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | spotbugs | 1m 0s | | trunk passed |
| +1 :green_heart: | shadedclient | 16m 52s | | branch has no errors when building and testing our client artifacts. |
|||| _ Patch Compile Tests _ |
| +1 :green_heart: | mvninstall | 0m 32s | | the patch passed |
| +1 :green_heart: | compile | 0m 32s | | the patch passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javac | 0m 32s | | the patch passed |
| +1 :green_heart: | compile | 0m 26s | | the patch passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | javac | 0m 26s | | the patch passed |
| +1 :green_heart: | blanks | 0m 0s | | The patch has no blanks issues. |
| -0 :warning: | checkstyle | 0m 16s | [/results-checkstyle-hadoop-tools_hadoop-azure.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/1/artifact/out/results-checkstyle-hadoop-tools_hadoop-azure.txt) | hadoop-tools/hadoop-azure: The patch generated 1 new + 4 unchanged - 0 fixed = 5 total (was 4) |
| +1 :green_heart: | mvnsite | 0m 30s | | the patch passed |
| +1 :green_heart: | javadoc | 0m 21s | | the patch passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javadoc | 0m 19s | | the patch passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | spotbugs | 1m 3s | | the patch passed |
| +1 :green_heart: | shadedclient | 16m 39s | | patch has no errors when building and testing our client artifacts. |
|||| _ Other Tests _ |
| +1 :green_heart: | unit | 1m 50s | | hadoop-azure in the patch passed. |
| +1 :green_heart: | asflicense | 0m 29s | | The patch does not generate ASF License warnings. |
| | | 78m 18s | | |
| Subsystem | Report/Notes |
|----------:|:-------------|
| Docker | ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/1/artifact/out/Dockerfile |
| GITHUB PR | https://github.com/apache/hadoop/pull/3335 |
| Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell |
| uname | Linux 6970b2fddfcf 4.15.0-147-generic #151-Ubuntu SMP Fri Jun 18 19:21:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux |
| Build tool | maven |
| Personality | dev-support/bin/hadoop.sh |
| git revision | trunk / 81cceeb9dc1e84998fc03f87f1415b2b6eb6a062 |
| Default Java | Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| Multi-JDK versions | /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/1/testReport/ |
| Max. process+thread count | 577 (vs. ulimit of 5500) |
| modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
| Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/1/console |
| versions | git=2.25.1 maven=3.6.3 spotbugs=4.2.2 |
| Powered by | Apache Yetus 0.14.0-SNAPSHOT https://yetus.apache.org |
This message was automatically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701916259
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701917138
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
+ // read and discard
+ int bytesRead = 0;
+ byte[] b = new byte[getCleanUpBufferSize()];
+ while ((bytesRead = stream.read(b)) >= 0) {
+ totalBytesRead += bytesRead;
+ }
+ }
+ }
+ } catch (IOException ex) {
+ LOG.warn("IO/Network error: {} {}: {}",
+ getMethod(), getMaskedUrl(), ex.getMessage());
+ LOG.debug("IO Error: ", ex);
+ throw ex;
+ } finally {
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+
+ setBytesReceived(totalBytesRead);
+ }
+ }
+ }
+
+ /**
+ * Open the HTTP connection.
+ *
+ * @throws IOException if an error occurs.
+ */
+ private HttpURLConnection openConnection() throws IOException {
+ if (!isTraceEnabled()) {
+ return (HttpURLConnection) getUrl().openConnection();
+ }
+ long start = System.nanoTime();
+ try {
+ return (HttpURLConnection) getUrl().openConnection();
+ } finally {
+ setConnectionTimeMs(elapsedTimeMs(start));
+ }
+ }
+
+ /**
+ * When the request fails, this function is used to parse the response
+ * and extract the storageErrorCode and storageErrorMessage. Any errors
+ * encountered while attempting to process the error response are logged,
+ * but otherwise ignored.
+ *
+ * For storage errors, the response body *usually* has the following format:
+ *
+ * {
+ * "error":
+ * {
+ * "code": "string",
+ * "message": "string"
+ * }
+ * }
+ *
+ */
+ private void processStorageErrorResponse() {
+ try (InputStream stream = connection.getErrorStream()) {
+ if (stream == null) {
+ return;
+ }
+ JsonFactory jf = new JsonFactory();
+ try (JsonParser jp = jf.createJsonParser(stream)) {
+ String fieldName, fieldValue;
+ jp.nextToken(); // START_OBJECT - {
+ jp.nextToken(); // FIELD_NAME - "error":
+ jp.nextToken(); // START_OBJECT - {
+ jp.nextToken();
+ while (jp.hasCurrentToken()) {
+ if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
+ fieldName = jp.getCurrentName();
+ jp.nextToken();
+ fieldValue = jp.getText();
+ switch (fieldName) {
+ case "code":
+ setStorageErrorCode(fieldValue);
+ break;
+ case "message":
+ setStorageErrorMessage(fieldValue);
+ break;
+ case "ExpectedAppendPos":
+ setExpectedAppendPos(fieldValue);
+ break;
+ default:
+ break;
+ }
+ }
+ jp.nextToken();
+ }
+ }
+ } catch (IOException ex) {
Review comment:
It returns either an IOException or JsonParseException (which is a child exception type of IOException).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] hadoop-yetus commented on pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
hadoop-yetus commented on pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#issuecomment-912616274
:confetti_ball: **+1 overall**
| Vote | Subsystem | Runtime | Logfile | Comment |
|:----:|----------:|--------:|:--------:|:-------:|
| +0 :ok: | reexec | 1m 5s | | Docker mode activated. |
|||| _ Prechecks _ |
| +1 :green_heart: | dupname | 0m 0s | | No case conflicting files found. |
| +0 :ok: | codespell | 0m 0s | | codespell was not available. |
| +1 :green_heart: | @author | 0m 0s | | The patch does not contain any @author tags. |
| +1 :green_heart: | test4tests | 0m 0s | | The patch appears to include 3 new or modified test files. |
|||| _ trunk Compile Tests _ |
| +1 :green_heart: | mvninstall | 33m 15s | | trunk passed |
| +1 :green_heart: | compile | 0m 40s | | trunk passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | compile | 0m 36s | | trunk passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | checkstyle | 0m 30s | | trunk passed |
| +1 :green_heart: | mvnsite | 0m 42s | | trunk passed |
| +1 :green_heart: | javadoc | 0m 34s | | trunk passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javadoc | 0m 32s | | trunk passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | spotbugs | 1m 2s | | trunk passed |
| +1 :green_heart: | shadedclient | 15m 8s | | branch has no errors when building and testing our client artifacts. |
|||| _ Patch Compile Tests _ |
| +1 :green_heart: | mvninstall | 0m 31s | | the patch passed |
| +1 :green_heart: | compile | 0m 31s | | the patch passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javac | 0m 31s | | the patch passed |
| +1 :green_heart: | compile | 0m 26s | | the patch passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | javac | 0m 26s | | the patch passed |
| +1 :green_heart: | blanks | 0m 0s | | The patch has no blanks issues. |
| -0 :warning: | checkstyle | 0m 16s | [/results-checkstyle-hadoop-tools_hadoop-azure.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/2/artifact/out/results-checkstyle-hadoop-tools_hadoop-azure.txt) | hadoop-tools/hadoop-azure: The patch generated 1 new + 4 unchanged - 0 fixed = 5 total (was 4) |
| +1 :green_heart: | mvnsite | 0m 31s | | the patch passed |
| +1 :green_heart: | javadoc | 0m 23s | | the patch passed with JDK Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 |
| +1 :green_heart: | javadoc | 0m 22s | | the patch passed with JDK Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| +1 :green_heart: | spotbugs | 1m 4s | | the patch passed |
| +1 :green_heart: | shadedclient | 14m 21s | | patch has no errors when building and testing our client artifacts. |
|||| _ Other Tests _ |
| +1 :green_heart: | unit | 2m 5s | | hadoop-azure in the patch passed. |
| +1 :green_heart: | asflicense | 0m 36s | | The patch does not generate ASF License warnings. |
| | | 76m 33s | | |
| Subsystem | Report/Notes |
|----------:|:-------------|
| Docker | ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/2/artifact/out/Dockerfile |
| GITHUB PR | https://github.com/apache/hadoop/pull/3335 |
| Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell |
| uname | Linux 1ab14ef8e3f4 4.15.0-65-generic #74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux |
| Build tool | maven |
| Personality | dev-support/bin/hadoop.sh |
| git revision | trunk / cedc9f6f145234a0563233b09c6b653dfed3ed08 |
| Default Java | Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| Multi-JDK versions | /usr/lib/jvm/java-11-openjdk-amd64:Ubuntu-11.0.11+9-Ubuntu-0ubuntu2.20.04 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_292-8u292-b10-0ubuntu1~20.04-b10 |
| Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/2/testReport/ |
| Max. process+thread count | 696 (vs. ulimit of 5500) |
| modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
| Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-3335/2/console |
| versions | git=2.25.1 maven=3.6.3 spotbugs=4.2.2 |
| Powered by | Apache Yetus 0.14.0-SNAPSHOT https://yetus.apache.org |
This message was automatically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701921089
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
+ // read and discard
+ int bytesRead = 0;
+ byte[] b = new byte[getCleanUpBufferSize()];
+ while ((bytesRead = stream.read(b)) >= 0) {
+ totalBytesRead += bytesRead;
+ }
+ }
+ }
+ } catch (IOException ex) {
+ LOG.warn("IO/Network error: {} {}: {}",
+ getMethod(), getMaskedUrl(), ex.getMessage());
+ LOG.debug("IO Error: ", ex);
+ throw ex;
+ } finally {
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+
+ setBytesReceived(totalBytesRead);
+ }
+ }
+ }
+
+ /**
+ * Open the HTTP connection.
+ *
+ * @throws IOException if an error occurs.
+ */
+ private HttpURLConnection openConnection() throws IOException {
+ if (!isTraceEnabled()) {
+ return (HttpURLConnection) getUrl().openConnection();
+ }
+ long start = System.nanoTime();
+ try {
+ return (HttpURLConnection) getUrl().openConnection();
+ } finally {
+ setConnectionTimeMs(elapsedTimeMs(start));
+ }
+ }
+
+ /**
+ * When the request fails, this function is used to parse the response
+ * and extract the storageErrorCode and storageErrorMessage. Any errors
+ * encountered while attempting to process the error response are logged,
+ * but otherwise ignored.
+ *
+ * For storage errors, the response body *usually* has the following format:
+ *
+ * {
+ * "error":
+ * {
+ * "code": "string",
+ * "message": "string"
+ * }
+ * }
+ *
+ */
+ private void processStorageErrorResponse() {
+ try (InputStream stream = connection.getErrorStream()) {
+ if (stream == null) {
+ return;
+ }
+ JsonFactory jf = new JsonFactory();
Review comment:
Have addressed these in a separate PR [HADOOP-17890 PR](https://github.com/apache/hadoop/pull/3381) that refactors the Http handling code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701923387
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
Review comment:
I couldnt find the cause from the commit history, however I noticed many forums that suggest issues with data still being stream even though the stream was closed at client side. Hence believe this is to avoid any issues for that issues.
Have addressed the comment to add a new metric into IOStatistic to track bytes that are being discarded in [HADOOP-17890 PR](https://github.com/apache/hadoop/pull/3381).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] snvijaya commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
snvijaya commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r701913006
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
Review comment:
ABFS Driver dependency on com.fasterxml.jackson.core was replaced with org.codehaus.jackson in [HADOOP-15659](https://issues.apache.org/jira/browse/HADOOP-15659). @DadanielZ , Could you please help with the reason for this ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
[GitHub] [hadoop] steveloughran commented on a change in pull request #3335: HADOOP-17864. ABFS: Make provision for adding additional connections type
Posted by GitBox <gi...@apache.org>.
steveloughran commented on a change in pull request #3335:
URL: https://github.com/apache/hadoop/pull/3335#discussion_r696534279
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
Review comment:
move to jackson 2 and com.fasterxml.jackson.core;
(ideally abfs should cut all use of jackson1)
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
+ // read and discard
+ int bytesRead = 0;
+ byte[] b = new byte[getCleanUpBufferSize()];
+ while ((bytesRead = stream.read(b)) >= 0) {
+ totalBytesRead += bytesRead;
+ }
+ }
+ }
+ } catch (IOException ex) {
+ LOG.warn("IO/Network error: {} {}: {}",
+ getMethod(), getMaskedUrl(), ex.getMessage());
+ LOG.debug("IO Error: ", ex);
+ throw ex;
+ } finally {
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+
+ setBytesReceived(totalBytesRead);
+ }
+ }
+ }
+
+ /**
+ * Open the HTTP connection.
+ *
+ * @throws IOException if an error occurs.
+ */
+ private HttpURLConnection openConnection() throws IOException {
+ if (!isTraceEnabled()) {
+ return (HttpURLConnection) getUrl().openConnection();
+ }
+ long start = System.nanoTime();
+ try {
+ return (HttpURLConnection) getUrl().openConnection();
+ } finally {
+ setConnectionTimeMs(elapsedTimeMs(start));
+ }
+ }
+
+ /**
+ * When the request fails, this function is used to parse the response
+ * and extract the storageErrorCode and storageErrorMessage. Any errors
+ * encountered while attempting to process the error response are logged,
+ * but otherwise ignored.
+ *
+ * For storage errors, the response body *usually* has the following format:
+ *
+ * {
+ * "error":
+ * {
+ * "code": "string",
+ * "message": "string"
+ * }
+ * }
+ *
+ */
+ private void processStorageErrorResponse() {
+ try (InputStream stream = connection.getErrorStream()) {
+ if (stream == null) {
+ return;
+ }
+ JsonFactory jf = new JsonFactory();
+ try (JsonParser jp = jf.createJsonParser(stream)) {
+ String fieldName, fieldValue;
+ jp.nextToken(); // START_OBJECT - {
+ jp.nextToken(); // FIELD_NAME - "error":
+ jp.nextToken(); // START_OBJECT - {
+ jp.nextToken();
+ while (jp.hasCurrentToken()) {
+ if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
+ fieldName = jp.getCurrentName();
+ jp.nextToken();
+ fieldValue = jp.getText();
+ switch (fieldName) {
+ case "code":
+ setStorageErrorCode(fieldValue);
+ break;
+ case "message":
+ setStorageErrorMessage(fieldValue);
+ break;
+ case "ExpectedAppendPos":
+ setExpectedAppendPos(fieldValue);
+ break;
+ default:
+ break;
+ }
+ }
+ jp.nextToken();
+ }
+ }
+ } catch (IOException ex) {
Review comment:
what do JSON parse errors report as?
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
Review comment:
nit: remove all the `this.`;
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
Review comment:
1. why this?
2. if bytes are read and discarded: increment an IOStatistic on this because its a sign of waste
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
Review comment:
this is really complex code with a lot of branches. Is there any way it could be cleaned up/refactored for easier reading and testing? For example, if the JSON parsing was independent & took an input stream, you could add a unit test which passed in invalid or incomplete JSON to see what happens.
##########
File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpConnection.java
##########
@@ -0,0 +1,367 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
+import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
+
+public class AbfsHttpConnection extends AbfsHttpOperation {
+ private static final Logger LOG = LoggerFactory.getLogger(AbfsHttpOperation.class);
+ private HttpURLConnection connection;
+ private ListResultSchema listResultSchema = null;
+
+ public AbfsHttpConnection(final URL url,
+ final String method,
+ List<AbfsHttpHeader> requestHeaders) throws IOException {
+ super(url, method);
+ init(method, requestHeaders);
+ }
+
+ /**
+ * Initializes a new HTTP request and opens the connection.
+ *
+ * @param method The HTTP method (PUT, PATCH, POST, GET, HEAD, or DELETE).
+ * @param requestHeaders The HTTP request headers.READ_TIMEOUT
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void init(final String method, List<AbfsHttpHeader> requestHeaders)
+ throws IOException {
+ this.connection = openConnection();
+ if (this.connection instanceof HttpsURLConnection) {
+ HttpsURLConnection secureConn = (HttpsURLConnection) this.connection;
+ SSLSocketFactory sslSocketFactory = DelegatingSSLSocketFactory.getDefaultFactory();
+ if (sslSocketFactory != null) {
+ secureConn.setSSLSocketFactory(sslSocketFactory);
+ }
+ }
+
+ this.connection.setConnectTimeout(getConnectTimeout());
+ this.connection.setReadTimeout(getReadTimeout());
+
+ this.connection.setRequestMethod(method);
+
+ for (AbfsHttpHeader header : requestHeaders) {
+ this.connection.setRequestProperty(header.getName(), header.getValue());
+ }
+ }
+
+ public HttpURLConnection getConnection() {
+ return connection;
+ }
+
+ public ListResultSchema getListResultSchema() {
+ return listResultSchema;
+ }
+
+ public String getResponseHeader(String httpHeader) {
+ return connection.getHeaderField(httpHeader);
+ }
+
+ public void setHeader(String header, String value) {
+ this.getConnection().setRequestProperty(header, value);
+ }
+
+ public Map<String, List<String>> getRequestHeaders() {
+ return getConnection().getRequestProperties();
+ }
+
+ public String getRequestHeader(String header) {
+ return getConnection().getRequestProperty(header);
+ }
+
+ public String getClientRequestId() {
+ return this.connection
+ .getRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID);
+ }
+ /**
+ * Sends the HTTP request. Note that HttpUrlConnection requires that an
+ * empty buffer be sent in order to set the "Content-Length: 0" header, which
+ * is required by our endpoint.
+ *
+ * @param buffer the request entity body.
+ * @param offset an offset into the buffer where the data beings.
+ * @param length the length of the data in the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void sendRequest(byte[] buffer, int offset, int length) throws IOException {
+ this.connection.setDoOutput(true);
+ this.connection.setFixedLengthStreamingMode(length);
+ if (buffer == null) {
+ // An empty buffer is sent to set the "Content-Length: 0" header, which
+ // is required by our endpoint.
+ buffer = new byte[]{};
+ offset = 0;
+ length = 0;
+ }
+
+ // send the request body
+
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+ try (OutputStream outputStream = this.connection.getOutputStream()) {
+ // update bytes sent before they are sent so we may observe
+ // attempted sends as well as successful sends via the
+ // accompanying statusCode
+ setBytesSent(length);
+ outputStream.write(buffer, offset, length);
+ } finally {
+ if (isTraceEnabled()) {
+ setSendRequestTimeMs(elapsedTimeMs(startTime));
+ }
+ }
+ }
+
+ /**
+ * Gets and processes the HTTP response.
+ *
+ * @param buffer a buffer to hold the response entity body
+ * @param offset an offset in the buffer where the data will being.
+ * @param length the number of bytes to be written to the buffer.
+ *
+ * @throws IOException if an error occurs.
+ */
+ public void processResponse(byte[] buffer, final int offset,
+ final int length) throws IOException {
+ // get the response
+ long startTime = 0;
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ setStatusCode(this.connection.getResponseCode());
+
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(elapsedTimeMs(startTime));
+ }
+
+ setStatusDescription(this.connection.getResponseMessage());
+
+ setRequestId(this.connection.getHeaderField(
+ HttpHeaderConfigurations.X_MS_REQUEST_ID));
+ if (getRequestId() == null) {
+ setRequestId(AbfsHttpConstants.EMPTY_STRING);
+ }
+ // dump the headers
+ AbfsIoUtils.dumpHeadersToDebugLog("Response Headers",
+ connection.getHeaderFields());
+
+ if (AbfsHttpConstants.HTTP_METHOD_HEAD.equals(getMethod())) {
+ // If it is HEAD, and it is ERROR
+ return;
+ }
+
+ if (isTraceEnabled()) {
+ startTime = System.nanoTime();
+ }
+
+ if (getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ processStorageErrorResponse();
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+ setBytesReceived(this.connection.getHeaderFieldLong(
+ HttpHeaderConfigurations.CONTENT_LENGTH, 0));
+ } else {
+ // consume the input stream to release resources
+ int totalBytesRead = 0;
+
+ try (InputStream stream = this.connection.getInputStream()) {
+ if (isNullInputStream(stream)) {
+ return;
+ }
+ boolean endOfStream = false;
+
+ // this is a list operation and need to retrieve the data
+ // need a better solution
+ if (AbfsHttpConstants.HTTP_METHOD_GET.equals(getMethod())
+ && buffer == null) {
+ parseListFilesResponse(stream);
+ } else if (AbfsHttpConstants.HTTP_METHOD_POST.equals(getMethod())) {
+ int contentLen = this.connection.getContentLength();
+ if (contentLen != 0) {
+ try (DataInputStream dis = new DataInputStream(stream)) {
+ byte[] contentBuffer = new byte[contentLen];
+ dis.readFully(contentBuffer);
+ setResponseContentBuffer(contentBuffer);
+ totalBytesRead += contentLen;
+ }
+ }
+ } else {
+ if (buffer != null) {
+ while (totalBytesRead < length) {
+ int bytesRead = stream.read(buffer, offset + totalBytesRead,
+ length - totalBytesRead);
+ if (bytesRead == -1) {
+ endOfStream = true;
+ break;
+ }
+ totalBytesRead += bytesRead;
+ }
+ }
+ if (!endOfStream && stream.read() != -1) {
+ // read and discard
+ int bytesRead = 0;
+ byte[] b = new byte[getCleanUpBufferSize()];
+ while ((bytesRead = stream.read(b)) >= 0) {
+ totalBytesRead += bytesRead;
+ }
+ }
+ }
+ } catch (IOException ex) {
+ LOG.warn("IO/Network error: {} {}: {}",
+ getMethod(), getMaskedUrl(), ex.getMessage());
+ LOG.debug("IO Error: ", ex);
+ throw ex;
+ } finally {
+ if (isTraceEnabled()) {
+ setRecvResponseTimeMs(getRecvResponseTimeMs() + elapsedTimeMs(startTime));
+ }
+
+ setBytesReceived(totalBytesRead);
+ }
+ }
+ }
+
+ /**
+ * Open the HTTP connection.
+ *
+ * @throws IOException if an error occurs.
+ */
+ private HttpURLConnection openConnection() throws IOException {
+ if (!isTraceEnabled()) {
+ return (HttpURLConnection) getUrl().openConnection();
+ }
+ long start = System.nanoTime();
+ try {
+ return (HttpURLConnection) getUrl().openConnection();
+ } finally {
+ setConnectionTimeMs(elapsedTimeMs(start));
+ }
+ }
+
+ /**
+ * When the request fails, this function is used to parse the response
+ * and extract the storageErrorCode and storageErrorMessage. Any errors
+ * encountered while attempting to process the error response are logged,
+ * but otherwise ignored.
+ *
+ * For storage errors, the response body *usually* has the following format:
+ *
+ * {
+ * "error":
+ * {
+ * "code": "string",
+ * "message": "string"
+ * }
+ * }
+ *
+ */
+ private void processStorageErrorResponse() {
+ try (InputStream stream = connection.getErrorStream()) {
+ if (stream == null) {
+ return;
+ }
+ JsonFactory jf = new JsonFactory();
Review comment:
check content type before trying to parse
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org