From c0e19a20d1c091fa30f9c0efee3f6d60e2dcfa71 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 20 Jun 2025 09:15:51 +0000 Subject: [PATCH 1/2] Add AutoValue + small example --- databricks-sdk-java/pom.xml | 13 ++++ .../sdk/core/oauth/DataPlaneTokenSource.java | 64 ++++++------------- pom.xml | 7 ++ 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/databricks-sdk-java/pom.xml b/databricks-sdk-java/pom.xml index c5a2e8c32..120370887 100644 --- a/databricks-sdk-java/pom.xml +++ b/databricks-sdk-java/pom.xml @@ -103,5 +103,18 @@ jackson-datatype-jsr310 ${jackson.version} + + + com.google.auto.value + auto-value + 1.10.4 + provided + + + com.google.auto.value + auto-value-annotations + 1.10.4 + provided + diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java index 8d48c2dff..83b3d99be 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java @@ -1,60 +1,38 @@ package com.databricks.sdk.core.oauth; import com.databricks.sdk.core.http.HttpClient; +import com.google.auto.value.AutoValue; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** - * Manages and provides Databricks data plane tokens. This class is responsible for acquiring and - * caching OAuth tokens that are specific to a particular Databricks data plane service endpoint and - * a set of authorization details. It utilizes a {@link DatabricksOAuthTokenSource} for obtaining - * control plane tokens, which may then be exchanged or used to authorize requests for data plane - * tokens. Cached {@link EndpointTokenSource} instances are used to efficiently reuse tokens for - * repeated requests to the same endpoint with the same authorization context. + * Manages and provides Databricks data plane tokens. This class is responsible + * for acquiring and caching OAuth tokens that are specific to a particular + * Databricks data plane service endpoint and a set of authorization details. + * It utilizes a {@link DatabricksOAuthTokenSource} for obtaining control plane + * tokens, which may then be exchanged or used to authorize requests for data + * plane tokens. Cached {@link EndpointTokenSource} instances are used to + * efficiently reuse tokens for repeated requests to the same endpoint with the + * same authorization context. */ public class DataPlaneTokenSource { private final HttpClient httpClient; private final TokenSource cpTokenSource; private final String host; private final ConcurrentHashMap sourcesCache; + /** - * Caching key for {@link EndpointTokenSource}, based on endpoint and authorization details. This - * is a value object that uniquely identifies a token source configuration. + * Caching key for {@link EndpointTokenSource}, based on endpoint and + * authorization details. This is a value object that uniquely identifies + * a token source configuration. */ - private static final class TokenSourceKey { - /** The target service endpoint URL. */ - private final String endpoint; - - /** Specific authorization details for the endpoint. */ - private final String authDetails; - - /** - * Constructs a TokenSourceKey. - * - * @param endpoint The target service endpoint URL. - * @param authDetails Specific authorization details. - */ - public TokenSourceKey(String endpoint, String authDetails) { - this.endpoint = endpoint; - this.authDetails = authDetails; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TokenSourceKey that = (TokenSourceKey) o; - return Objects.equals(endpoint, that.endpoint) - && Objects.equals(authDetails, that.authDetails); - } + @AutoValue + static abstract class TokenSourceKey { + abstract String endpoint(); + abstract String authDetails(); - @Override - public int hashCode() { - return Objects.hash(endpoint, authDetails); + static TokenSourceKey create(String endpoint, String authDetails) { + return new AutoValue_DataPlaneTokenSource_TokenSourceKey(endpoint, authDetails); } } @@ -101,14 +79,14 @@ public Token getToken(String endpoint, String authDetails) { throw new IllegalArgumentException("Authorization details cannot be empty"); } - TokenSourceKey key = new TokenSourceKey(endpoint, authDetails); + TokenSourceKey key = TokenSourceKey.create(endpoint, authDetails); EndpointTokenSource specificSource = sourcesCache.computeIfAbsent( key, k -> new EndpointTokenSource( - this.cpTokenSource, k.authDetails, this.httpClient, this.host)); + this.cpTokenSource, k.authDetails(), this.httpClient, this.host)); return specificSource.getToken(); } diff --git a/pom.xml b/pom.xml index afba640fb..d8f65b585 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,13 @@ 8 8 + + + com.google.auto.value + auto-value + 1.10.4 + + From 8392767bf507acb622f1633ab9fd1debafd38236 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 20 Jun 2025 09:42:44 +0000 Subject: [PATCH 2/2] make fmt --- .../sdk/core/oauth/DataPlaneTokenSource.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java index 83b3d99be..01bd05d2c 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java @@ -6,14 +6,12 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Manages and provides Databricks data plane tokens. This class is responsible - * for acquiring and caching OAuth tokens that are specific to a particular - * Databricks data plane service endpoint and a set of authorization details. - * It utilizes a {@link DatabricksOAuthTokenSource} for obtaining control plane - * tokens, which may then be exchanged or used to authorize requests for data - * plane tokens. Cached {@link EndpointTokenSource} instances are used to - * efficiently reuse tokens for repeated requests to the same endpoint with the - * same authorization context. + * Manages and provides Databricks data plane tokens. This class is responsible for acquiring and + * caching OAuth tokens that are specific to a particular Databricks data plane service endpoint and + * a set of authorization details. It utilizes a {@link DatabricksOAuthTokenSource} for obtaining + * control plane tokens, which may then be exchanged or used to authorize requests for data plane + * tokens. Cached {@link EndpointTokenSource} instances are used to efficiently reuse tokens for + * repeated requests to the same endpoint with the same authorization context. */ public class DataPlaneTokenSource { private final HttpClient httpClient; @@ -22,13 +20,13 @@ public class DataPlaneTokenSource { private final ConcurrentHashMap sourcesCache; /** - * Caching key for {@link EndpointTokenSource}, based on endpoint and - * authorization details. This is a value object that uniquely identifies - * a token source configuration. + * Caching key for {@link EndpointTokenSource}, based on endpoint and authorization details. This + * is a value object that uniquely identifies a token source configuration. */ @AutoValue - static abstract class TokenSourceKey { + abstract static class TokenSourceKey { abstract String endpoint(); + abstract String authDetails(); static TokenSourceKey create(String endpoint, String authDetails) {