From d56fbd9d56de184988aa5c6b72ecb10ea0bb691a Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 3 Aug 2022 19:37:29 +0800 Subject: [PATCH 1/5] Repalce okhttp by apache http client --- LICENSE-binary | 1 - NOTICE-binary | 11 --- hadoop-client-modules/hadoop-client/pom.xml | 12 ---- .../dev-support/findbugsExcludeFile.xml | 13 ---- .../hadoop-hdfs-client/pom.xml | 12 ---- ...fRefreshTokenBasedAccessTokenProvider.java | 59 +++++++++------- .../CredentialBasedAccessTokenProvider.java | 69 ++++++++++--------- .../hdfs/web/oauth2/OAuth2Constants.java | 4 -- hadoop-project/pom.xml | 35 ---------- 9 files changed, 73 insertions(+), 143 deletions(-) diff --git a/LICENSE-binary b/LICENSE-binary index 4e6f688fcb896..6c8b66c78d89d 100644 --- a/LICENSE-binary +++ b/LICENSE-binary @@ -241,7 +241,6 @@ com.google.guava:guava:27.0-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.microsoft.azure:azure-storage:7.0.0 com.nimbusds:nimbus-jose-jwt:9.8.1 -com.squareup.okhttp3:okhttp:4.9.3 com.squareup.okio:okio:1.6.0 com.zaxxer:HikariCP:4.0.3 commons-beanutils:commons-beanutils:1.9.3 diff --git a/NOTICE-binary b/NOTICE-binary index b96e052658876..5d0e45f16d591 100644 --- a/NOTICE-binary +++ b/NOTICE-binary @@ -336,17 +336,6 @@ limitations under the License. ----------------------------------------------------------------------- -This product contains a modified portion of 'OkHttp', an open source -HTTP & SPDY client for Android and Java applications, which can be obtained -at: - - * LICENSE: - * okhttp/third_party/okhttp/LICENSE (Apache License 2.0) - * HOMEPAGE: - * https://github.com/square/okhttp - * LOCATION_IN_GRPC: - * okhttp/third_party/okhttp - This product contains a modified portion of 'Netty', an open source networking library, which can be obtained at: diff --git a/hadoop-client-modules/hadoop-client/pom.xml b/hadoop-client-modules/hadoop-client/pom.xml index 5299c9e8713df..b48a221bdf179 100644 --- a/hadoop-client-modules/hadoop-client/pom.xml +++ b/hadoop-client-modules/hadoop-client/pom.xml @@ -114,18 +114,6 @@ org.eclipse.jetty jetty-server - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-stdlib-common - - - com.squareup.okhttp3 - okhttp - com.sun.jersey jersey-core diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml b/hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml index 508388aa4812e..c96b3a99bd1c4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml @@ -94,17 +94,4 @@ - - - - - - - - - - - - - diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml index 9bb0932d32867..5f07f8cbfc564 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml @@ -34,18 +34,6 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd"> - - com.squareup.okhttp3 - okhttp - - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-stdlib-common - org.apache.hadoop hadoop-common diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java index e944e8c1c8d77..22f2c9f88b2ab 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java @@ -19,20 +19,17 @@ package org.apache.hadoop.hdfs.web.oauth2; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map; -import java.util.concurrent.TimeUnit; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; +import org.apache.commons.io.IOUtils; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.web.URLConnectionFactory; import org.apache.hadoop.util.JsonSerialization; import org.apache.hadoop.util.Timer; +import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; @@ -42,9 +39,18 @@ import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.REFRESH_TOKEN; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.URLENCODED; import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.EntityBuilder; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.methods.RequestBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; + /** * Supply a access token obtained via a refresh token (provided through the * Configuration using the second half of the @@ -103,30 +109,35 @@ public synchronized String getAccessToken() throws IOException { } void refresh() throws IOException { - OkHttpClient client = - new OkHttpClient.Builder().connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, - TimeUnit.MILLISECONDS) - .readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS) + HttpEntity reqEntity = EntityBuilder.create() + .setContentType(ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8)) + .setParameters( + new BasicNameValuePair(GRANT_TYPE, REFRESH_TOKEN), + new BasicNameValuePair(REFRESH_TOKEN, refreshToken), + new BasicNameValuePair(CLIENT_ID, clientId)) .build(); - String bodyString = - Utils.postBody(GRANT_TYPE, REFRESH_TOKEN, REFRESH_TOKEN, refreshToken, CLIENT_ID, clientId); + HttpUriRequest request = RequestBuilder + .post(refreshURL) + .setEntity(reqEntity) + .build(); - RequestBody body = RequestBody.create(bodyString, URLENCODED); + RequestConfig reqConf = RequestConfig.custom() + .setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT) + .setSocketTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT) + .build(); - Request request = new Request.Builder().url(refreshURL).post(body).build(); - try (Response response = client.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } - if (response.code() != HttpStatus.SC_OK) { + HttpClientBuilder clientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(reqConf); + try (CloseableHttpClient client = clientBuilder.build(); + CloseableHttpResponse response = client.execute(request)) { + int statusCode = response.getStatusLine().getStatusCode(); + String respText = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + if (statusCode != HttpStatus.SC_OK) { throw new IllegalArgumentException( - "Received invalid http response: " + response.code() + ", text = " - + response.toString()); + "Received invalid http response: " + statusCode + ", text = " + respText); } - Map responseBody = JsonSerialization.mapReader().readValue(response.body().string()); - + Map responseBody = JsonSerialization.mapReader().readValue(respText); String newExpiresIn = responseBody.get(EXPIRES_IN).toString(); accessTokenTimer.setExpiresIn(newExpiresIn); diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java index 25ceb8846092b..0404ec67bc982 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java @@ -19,21 +19,16 @@ package org.apache.hadoop.hdfs.web.oauth2; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map; -import java.util.concurrent.TimeUnit; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; +import org.apache.commons.io.IOUtils; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.web.URLConnectionFactory; import org.apache.hadoop.util.JsonSerialization; import org.apache.hadoop.util.Timer; -import org.apache.http.HttpStatus; import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY; @@ -43,9 +38,20 @@ import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_SECRET; import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.URLENCODED; import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.EntityBuilder; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.methods.RequestBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; + /** * Obtain an access token via the credential-based OAuth2 workflow. This * abstract class requires only that implementations provide the credential, @@ -97,40 +103,41 @@ public synchronized String getAccessToken() throws IOException { } void refresh() throws IOException { - OkHttpClient client = new OkHttpClient.Builder() - .connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS) - .readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS) + HttpEntity reqEntity = EntityBuilder.create() + .setContentType(ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8)) + .setParameters( + new BasicNameValuePair(CLIENT_SECRET, getCredential()), + new BasicNameValuePair(GRANT_TYPE, CLIENT_CREDENTIALS), + new BasicNameValuePair(CLIENT_ID, clientId)) .build(); - String bodyString = Utils.postBody(CLIENT_SECRET, getCredential(), - GRANT_TYPE, CLIENT_CREDENTIALS, - CLIENT_ID, clientId); - - RequestBody body = RequestBody.create(bodyString, URLENCODED); + HttpUriRequest request = RequestBuilder + .post(refreshURL) + .setEntity(reqEntity) + .build(); - Request request = new Request.Builder() - .url(refreshURL) - .post(body) - .build(); - try (Response response = client.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } + RequestConfig reqConf = RequestConfig.custom() + .setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT) + .setSocketTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT) + .build(); - if (response.code() != HttpStatus.SC_OK) { - throw new IllegalArgumentException("Received invalid http response: " - + response.code() + ", text = " + response.toString()); + HttpClientBuilder clientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(reqConf); + try (CloseableHttpClient client = clientBuilder.build(); + CloseableHttpResponse response = client.execute(request)) { + int statusCode = response.getStatusLine().getStatusCode(); + String respText = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + if (statusCode != HttpStatus.SC_OK) { + throw new IllegalArgumentException( + "Received invalid http response: " + statusCode + ", text = " + respText); } - Map responseBody = JsonSerialization.mapReader().readValue( - response.body().string()); - + Map responseBody = JsonSerialization.mapReader().readValue(respText); String newExpiresIn = responseBody.get(EXPIRES_IN).toString(); timer.setExpiresIn(newExpiresIn); accessToken = responseBody.get(ACCESS_TOKEN).toString(); } catch (Exception e) { - throw new IOException("Unable to obtain access token from credential", e); + throw new IOException("Exception while refreshing access token", e); } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/OAuth2Constants.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/OAuth2Constants.java index 2f28b65e40e92..4ac02e19b9cc2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/OAuth2Constants.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/OAuth2Constants.java @@ -18,7 +18,6 @@ */ package org.apache.hadoop.hdfs.web.oauth2; -import okhttp3.MediaType; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -30,9 +29,6 @@ public final class OAuth2Constants { private OAuth2Constants() { /** Private constructor. **/ } - public static final MediaType URLENCODED - = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8"); - /* Constants for OAuth protocol */ public static final String ACCESS_TOKEN = "access_token"; public static final String BEARER = "bearer"; diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index 2caad449b5cbf..d62a80a6f378b 100644 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -131,10 +131,6 @@ 3.3.1 4.0.3 6.2.1.jre7 - 2.7.5 - 4.9.3 - 1.4.10 - 1.4.10 2.0.6.1 5.2.0 2.2.21 @@ -221,37 +217,6 @@ - - com.squareup.okhttp3 - okhttp - ${okhttp3.version} - - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-stdlib-common - - - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin-stdlib.verion} - - - org.jetbrains - annotations - - - - - org.jetbrains.kotlin - kotlin-stdlib-common - ${kotlin-stdlib-common.version} - com.squareup.okhttp3 mockwebserver From 7d67c6036bcb3a311b3dda1ffa9f0191c4e9b292 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 3 Aug 2022 19:42:44 +0800 Subject: [PATCH 2/5] nit --- NOTICE-binary | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NOTICE-binary b/NOTICE-binary index 5d0e45f16d591..b96e052658876 100644 --- a/NOTICE-binary +++ b/NOTICE-binary @@ -336,6 +336,17 @@ limitations under the License. ----------------------------------------------------------------------- +This product contains a modified portion of 'OkHttp', an open source +HTTP & SPDY client for Android and Java applications, which can be obtained +at: + + * LICENSE: + * okhttp/third_party/okhttp/LICENSE (Apache License 2.0) + * HOMEPAGE: + * https://github.com/square/okhttp + * LOCATION_IN_GRPC: + * okhttp/third_party/okhttp + This product contains a modified portion of 'Netty', an open source networking library, which can be obtained at: From 1c3e894e9b7311bfa7404ba8431896b3e27fe3df Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 3 Aug 2022 19:43:40 +0800 Subject: [PATCH 3/5] nit --- .../CredentialBasedAccessTokenProvider.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java index 0404ec67bc982..bce37347e2443 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java @@ -30,16 +30,6 @@ import org.apache.hadoop.util.JsonSerialization; import org.apache.hadoop.util.Timer; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_CREDENTIALS; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_ID; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_SECRET; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; -import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; - import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; @@ -52,6 +42,16 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; +import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; +import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_CREDENTIALS; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_ID; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_SECRET; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; +import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; + /** * Obtain an access token via the credential-based OAuth2 workflow. This * abstract class requires only that implementations provide the credential, From b5e1ed5620b1ba4e5004936b34620c52101a4109 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 3 Aug 2022 19:44:42 +0800 Subject: [PATCH 4/5] nit --- ...fRefreshTokenBasedAccessTokenProvider.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java index 22f2c9f88b2ab..26b4084850784 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java @@ -29,18 +29,9 @@ import org.apache.hadoop.hdfs.web.URLConnectionFactory; import org.apache.hadoop.util.JsonSerialization; import org.apache.hadoop.util.Timer; + import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; - -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_ID; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; -import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.REFRESH_TOKEN; -import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; - import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.EntityBuilder; import org.apache.http.client.methods.CloseableHttpResponse; @@ -51,6 +42,15 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; +import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY; +import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.CLIENT_ID; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.EXPIRES_IN; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.GRANT_TYPE; +import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.REFRESH_TOKEN; +import static org.apache.hadoop.hdfs.web.oauth2.Utils.notNull; + /** * Supply a access token obtained via a refresh token (provided through the * Configuration using the second half of the From 0056f0df3cbb4ca93bbe4af62e3de559b035f145 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 3 Aug 2022 20:08:31 +0800 Subject: [PATCH 5/5] nit --- .../hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java index bce37347e2443..41fc2fd983c77 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java @@ -137,7 +137,7 @@ void refresh() throws IOException { accessToken = responseBody.get(ACCESS_TOKEN).toString(); } catch (Exception e) { - throw new IOException("Exception while refreshing access token", e); + throw new IOException("Unable to obtain access token from credential", e); } } }