Skip to content

Commit 1294486

Browse files
committed
-
1 parent 278f969 commit 1294486

File tree

9 files changed

+29
-41
lines changed

9 files changed

+29
-41
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/ClientType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
/** Represents the type of Databricks client being used for API operations. */
66
@InternalApi
77
public enum ClientType {
8-
/** Traditional workspace client. */
8+
/** Workspace client (traditional or unified host with workspaceId). */
99
WORKSPACE,
1010

11-
/** Traditional account client. */
12-
ACCOUNT,
13-
14-
/** Workspace-scoped client on unified host. */
15-
WORKSPACE_ON_UNIFIED,
16-
17-
/** Account-scoped client on unified host. */
18-
ACCOUNT_ON_UNIFIED
11+
/** Account client (traditional or unified host without workspaceId). */
12+
ACCOUNT
1913
}

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksCliCredentialsProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ private CliTokenSource getDatabricksCliTokenSource(DatabricksConfig config) {
3131
}
3232
List<String> cmd =
3333
new ArrayList<>(Arrays.asList(cliPath, "auth", "token", "--host", config.getHost()));
34-
if (config.getClientType() == ClientType.ACCOUNT
35-
|| config.getClientType() == ClientType.ACCOUNT_ON_UNIFIED) {
34+
if (config.getClientType() == ClientType.ACCOUNT) {
3635
cmd.add("--account-id");
3736
cmd.add(config.getAccountId());
3837
}

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@ public class DatabricksConfig {
2828
private String accountId;
2929

3030
/**
31-
* Workspace ID for unified host operations.
32-
*
33-
* <p><b>Note:</b> This API is experimental and may change or be removed in future releases
34-
* without notice.
31+
* Workspace ID for unified host operations. Note: This API is experimental and may change or be
32+
* removed in future releases without notice.
3533
*/
3634
@ConfigAttribute(env = "DATABRICKS_WORKSPACE_ID")
3735
private String workspaceId;
3836

3937
/**
40-
* Flag to explicitly mark a host as a unified host.
41-
*
42-
* <p><b>Note:</b> This API is experimental and may change or be removed in future releases
43-
* without notice.
38+
* Flag to explicitly mark a host as a unified host. Note: This API is experimental and may change
39+
* or be removed in future releases without notice.
4440
*/
4541
@ConfigAttribute(env = "DATABRICKS_EXPERIMENTAL_IS_UNIFIED_HOST")
4642
private Boolean experimentalIsUnifiedHost;
@@ -61,10 +57,8 @@ public class DatabricksConfig {
6157
private String redirectUrl;
6258

6359
/**
64-
* The OpenID Connect discovery URL used to retrieve OIDC configuration and endpoints.
65-
*
66-
* <p><b>Note:</b> This API is experimental and may change or be removed in future releases
67-
* without notice.
60+
* The OpenID Connect discovery URL used to retrieve OIDC configuration and endpoints. Note: This
61+
* API is experimental and may change or be removed in future releases without notice.
6862
*/
6963
@ConfigAttribute(env = "DATABRICKS_DISCOVERY_URL")
7064
private String discoveryUrl;
@@ -256,7 +250,7 @@ public synchronized Map<String, String> authenticate() throws DatabricksExceptio
256250

257251
// For unified hosts with workspace operations, wrap the header factory
258252
// to inject the X-Databricks-Org-Id header
259-
if (getClientType() == ClientType.WORKSPACE_ON_UNIFIED) {
253+
if (getHostType() == HostType.UNIFIED && workspaceId != null && !workspaceId.isEmpty()) {
260254
headerFactory = new UnifiedHostHeaderFactory(rawHeaderFactory, workspaceId);
261255
} else {
262256
headerFactory = rawHeaderFactory;
@@ -754,9 +748,10 @@ public ClientType getClientType() {
754748
HostType hostType = getHostType();
755749
switch (hostType) {
756750
case UNIFIED:
751+
// For unified hosts, client type depends on whether workspaceId is set
757752
return (workspaceId != null && !workspaceId.isEmpty())
758-
? ClientType.WORKSPACE_ON_UNIFIED
759-
: ClientType.ACCOUNT_ON_UNIFIED;
753+
? ClientType.WORKSPACE
754+
: ClientType.ACCOUNT;
760755
case ACCOUNTS:
761756
return ClientType.ACCOUNT;
762757
case WORKSPACE:

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DefaultCredentialsProvider.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ private void addOIDCCredentialsProviders(DatabricksConfig config) {
151151
config.getHttpClient())
152152
.audience(config.getTokenAudience())
153153
.accountId(
154-
(config.getClientType() == ClientType.ACCOUNT
155-
|| config.getClientType() == ClientType.ACCOUNT_ON_UNIFIED)
156-
? config.getAccountId()
157-
: null)
154+
config.getClientType() == ClientType.ACCOUNT ? config.getAccountId() : null)
158155
.scopes(config.getScopes())
159156
.build();
160157

databricks-sdk-java/src/main/java/com/databricks/sdk/core/GoogleCredentialsCredentialsProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public HeaderFactory configure(DatabricksConfig config) {
6666
Map<String, String> headers = new HashMap<>();
6767
headers.put("Authorization", String.format("Bearer %s", idToken.getTokenValue()));
6868

69-
if (config.getClientType() == ClientType.ACCOUNT
70-
|| config.getClientType() == ClientType.ACCOUNT_ON_UNIFIED) {
69+
if (config.getClientType() == ClientType.ACCOUNT) {
7170
AccessToken token;
7271
try {
7372
token = finalServiceAccountCredentials.createScoped(GCP_SCOPES).refreshAccessToken();

databricks-sdk-java/src/main/java/com/databricks/sdk/core/GoogleIdCredentialsProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public HeaderFactory configure(DatabricksConfig config) {
6969
throw new DatabricksException(message, e);
7070
}
7171

72-
if (config.getClientType() == ClientType.ACCOUNT
73-
|| config.getClientType() == ClientType.ACCOUNT_ON_UNIFIED) {
72+
if (config.getClientType() == ClientType.ACCOUNT) {
7473
try {
7574
headers.put(
7675
SA_ACCESS_TOKEN_HEADER, gcpScopedCredentials.refreshAccessToken().getTokenValue());

databricks-sdk-java/src/test/java/com/databricks/sdk/AccountClientTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ public void testGetWorkspaceClientForUnifiedHost() {
5555
// Should have workspace ID set
5656
assertEquals("123456", workspaceClient.config().getWorkspaceId());
5757

58-
// Should be workspace-on-unified client type
59-
assertEquals(ClientType.WORKSPACE_ON_UNIFIED, workspaceClient.config().getClientType());
58+
// Should be workspace client type (on unified host)
59+
assertEquals(ClientType.WORKSPACE, workspaceClient.config().getClientType());
60+
61+
// Host type should still be unified
62+
assertEquals(HostType.UNIFIED, workspaceClient.config().getHostType());
6063
}
6164

6265
@Test

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ public void testGetClientTypeAccount() {
401401

402402
@Test
403403
public void testGetClientTypeWorkspaceOnUnified() {
404+
// For unified hosts with workspaceId, client type is WORKSPACE
404405
assertEquals(
405-
ClientType.WORKSPACE_ON_UNIFIED,
406+
ClientType.WORKSPACE,
406407
new DatabricksConfig()
407408
.setHost("https://unified.databricks.com")
408409
.setExperimentalIsUnifiedHost(true)
@@ -412,8 +413,9 @@ public void testGetClientTypeWorkspaceOnUnified() {
412413

413414
@Test
414415
public void testGetClientTypeAccountOnUnified() {
416+
// For unified hosts without workspaceId, client type is ACCOUNT
415417
assertEquals(
416-
ClientType.ACCOUNT_ON_UNIFIED,
418+
ClientType.ACCOUNT,
417419
new DatabricksConfig()
418420
.setHost("https://unified.databricks.com")
419421
.setExperimentalIsUnifiedHost(true)

databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ private static Stream<Arguments> provideClientTypeTestCases() {
8989
"https://unified.databricks.com",
9090
null,
9191
true,
92-
ClientType.ACCOUNT_ON_UNIFIED),
92+
ClientType.ACCOUNT),
9393
Arguments.of(
9494
"Unified with workspace ID",
9595
"https://unified.databricks.com",
9696
"123456",
9797
true,
98-
ClientType.WORKSPACE_ON_UNIFIED));
98+
ClientType.WORKSPACE));
9999
}
100100

101101
@ParameterizedTest(name = "{0}")
@@ -182,7 +182,7 @@ public void testUnifiedHostFromEnvironmentVariables() {
182182
assertEquals(HostType.UNIFIED, config.getHostType());
183183
assertEquals("987654321", config.getWorkspaceId());
184184
assertEquals("account-abc", config.getAccountId());
185-
assertEquals(ClientType.WORKSPACE_ON_UNIFIED, config.getClientType());
185+
assertEquals(ClientType.WORKSPACE, config.getClientType());
186186
}
187187

188188
// --- UnifiedHostHeaderFactory Tests ---

0 commit comments

Comments
 (0)