Skip to content

Commit ad7024c

Browse files
committed
Remove unified flag usage, rely on host metadata
Port of Go SDK #1547. Removes HostType.UNIFIED and all runtime checks of experimentalIsUnifiedHost. Host type is now determined solely from URL pattern (accounts.* = ACCOUNTS, else WORKSPACE). Host metadata resolution from /.well-known/databricks-config (added in PR 4) handles populating accountId, workspaceId, and discoveryUrl automatically. Key changes: - getHostType(): no longer returns UNIFIED - isAccountClient(): no longer throws for unified hosts - getClientType(): simplified, no UNIFIED case - fetchDefaultOidcEndpoints(): removed unified OIDC branch - DatabricksCliCredentialsProvider: removed --experimental-is-unified-host - AccountClient.getWorkspaceClient(): uses DNS zone matching (like Go SDK) to decide whether to reuse host or build deployment URL Co-authored-by: Isaac
1 parent 153a890 commit ad7024c

File tree

8 files changed

+86
-375
lines changed

8 files changed

+86
-375
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/AccountClient.java

Lines changed: 36 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,7 @@ public String authType() {
3030
List<String> buildHostArgs(String cliPath, DatabricksConfig config) {
3131
List<String> cmd =
3232
new ArrayList<>(Arrays.asList(cliPath, "auth", "token", "--host", config.getHost()));
33-
if (config.getExperimentalIsUnifiedHost() != null && config.getExperimentalIsUnifiedHost()) {
34-
// For unified hosts, pass account_id, workspace_id, and experimental flag
35-
cmd.add("--experimental-is-unified-host");
36-
if (config.getAccountId() != null) {
37-
cmd.add("--account-id");
38-
cmd.add(config.getAccountId());
39-
}
40-
if (config.getWorkspaceId() != null) {
41-
cmd.add("--workspace-id");
42-
cmd.add(config.getWorkspaceId());
43-
}
44-
} else if (config.getClientType() == ClientType.ACCOUNT) {
33+
if (config.getClientType() == ClientType.ACCOUNT) {
4534
cmd.add("--account-id");
4635
cmd.add(config.getAccountId());
4736
}

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ public synchronized Map<String, String> authenticate() throws DatabricksExceptio
270270
}
271271
Map<String, String> headers = new HashMap<>(headerFactory.headers());
272272

273-
// For unified hosts with workspace operations, add the X-Databricks-Org-Id header
274-
if (getHostType() == HostType.UNIFIED && workspaceId != null && !workspaceId.isEmpty()) {
275-
headers.put("X-Databricks-Org-Id", workspaceId);
276-
}
277-
278273
return headers;
279274
} catch (DatabricksException e) {
280275
String msg = String.format("%s auth: %s", credentialsProvider.authType(), e.getMessage());
@@ -732,23 +727,14 @@ public boolean isAws() {
732727
}
733728

734729
public boolean isAccountClient() {
735-
if (getHostType() == HostType.UNIFIED) {
736-
throw new DatabricksException(
737-
"Cannot determine account client status for unified hosts. "
738-
+ "Use getHostType() or getClientType() instead. "
739-
+ "For unified hosts, client type depends on whether workspaceId is set.");
740-
}
741730
if (host == null) {
742731
return false;
743732
}
744733
return host.startsWith("https://accounts.") || host.startsWith("https://accounts-dod.");
745734
}
746735

747-
/** Returns the host type based on configuration settings and host URL. */
736+
/** Returns the host type based on the host URL pattern. */
748737
public HostType getHostType() {
749-
if (experimentalIsUnifiedHost != null && experimentalIsUnifiedHost) {
750-
return HostType.UNIFIED;
751-
}
752738
if (host == null) {
753739
return HostType.WORKSPACE;
754740
}
@@ -758,15 +744,10 @@ public HostType getHostType() {
758744
return HostType.WORKSPACE;
759745
}
760746

761-
/** Returns the client type based on host type and workspace ID configuration. */
747+
/** Returns the client type based on host type. */
762748
public ClientType getClientType() {
763749
HostType hostType = getHostType();
764750
switch (hostType) {
765-
case UNIFIED:
766-
// For unified hosts, client type depends on whether workspaceId is set
767-
return (workspaceId != null && !workspaceId.isEmpty())
768-
? ClientType.WORKSPACE
769-
: ClientType.ACCOUNT;
770751
case ACCOUNTS:
771752
return ClientType.ACCOUNT;
772753
case WORKSPACE:
@@ -903,24 +884,11 @@ private OpenIDConnectEndpoints fetchOidcEndpointsFromDiscovery() {
903884
return null;
904885
}
905886

906-
private OpenIDConnectEndpoints getUnifiedOidcEndpoints(String accountId) throws IOException {
907-
if (accountId == null || accountId.isEmpty()) {
908-
throw new DatabricksException(
909-
"account_id is required for unified host OIDC endpoint discovery");
910-
}
911-
String prefix = getHost() + "/oidc/accounts/" + accountId;
912-
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
913-
}
914-
915887
private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
916888
if (getHost() == null) {
917889
return null;
918890
}
919891

920-
// For unified hosts, use account-based OIDC endpoints
921-
if (getHostType() == HostType.UNIFIED) {
922-
return getUnifiedOidcEndpoints(getAccountId());
923-
}
924892
if (isAccountClient() && getAccountId() != null) {
925893
String prefix = getHost() + "/oidc/accounts/" + getAccountId();
926894
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ public enum HostType {
99
WORKSPACE,
1010

1111
/** Traditional accounts host. */
12-
ACCOUNTS,
13-
14-
/** Unified host supporting both workspace and account operations. */
15-
UNIFIED
12+
ACCOUNTS
1613
}

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.*;
44

5-
import com.databricks.sdk.core.ClientType;
65
import com.databricks.sdk.core.DatabricksConfig;
76
import com.databricks.sdk.core.HostType;
87
import com.databricks.sdk.service.provisioning.Workspace;
@@ -49,28 +48,14 @@ public void testGetWorkspaceClientForUnifiedHost() {
4948

5049
WorkspaceClient workspaceClient = accountClient.getWorkspaceClient(workspace);
5150

52-
// Should have the same host
51+
// Should have the same host (unified hosts reuse the same host)
5352
assertEquals(unifiedHost, workspaceClient.config().getHost());
5453

5554
// Should have workspace ID set
5655
assertEquals("123456", workspaceClient.config().getWorkspaceId());
5756

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());
63-
}
64-
65-
@Test
66-
public void testGetWorkspaceClientForUnifiedHostType() {
67-
// Verify unified host type is correctly detected
68-
DatabricksConfig config =
69-
new DatabricksConfig()
70-
.setHost("https://unified.databricks.com")
71-
.setExperimentalIsUnifiedHost(true);
72-
73-
assertEquals(HostType.UNIFIED, config.getHostType());
57+
// Host type is WORKSPACE (determined from URL pattern, not unified flag)
58+
assertEquals(HostType.WORKSPACE, workspaceClient.config().getHostType());
7459
}
7560

7661
@Test

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

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ class DatabricksCliCredentialsProviderTest {
1111
private static final String CLI_PATH = "/usr/local/bin/databricks";
1212
private static final String HOST = "https://my-workspace.cloud.databricks.com";
1313
private static final String ACCOUNT_HOST = "https://accounts.cloud.databricks.com";
14-
private static final String UNIFIED_HOST = "https://unified.databricks.com";
1514
private static final String ACCOUNT_ID = "test-account-123";
16-
private static final String WORKSPACE_ID = "987654321";
1715

1816
private final DatabricksCliCredentialsProvider provider = new DatabricksCliCredentialsProvider();
1917

@@ -39,104 +37,12 @@ void testBuildHostArgs_AccountHost() {
3937
}
4038

4139
@Test
42-
void testBuildHostArgs_UnifiedHost_WithAccountIdAndWorkspaceId() {
43-
DatabricksConfig config =
44-
new DatabricksConfig()
45-
.setHost(UNIFIED_HOST)
46-
.setExperimentalIsUnifiedHost(true)
47-
.setAccountId(ACCOUNT_ID)
48-
.setWorkspaceId(WORKSPACE_ID);
40+
void testBuildHostArgs_NonAccountsHostWithAccountId() {
41+
// Non-accounts hosts should not pass --account-id even if accountId is set
42+
DatabricksConfig config = new DatabricksConfig().setHost(HOST).setAccountId(ACCOUNT_ID);
4943

5044
List<String> cmd = provider.buildHostArgs(CLI_PATH, config);
5145

52-
assertEquals(
53-
Arrays.asList(
54-
CLI_PATH,
55-
"auth",
56-
"token",
57-
"--host",
58-
UNIFIED_HOST,
59-
"--experimental-is-unified-host",
60-
"--account-id",
61-
ACCOUNT_ID,
62-
"--workspace-id",
63-
WORKSPACE_ID),
64-
cmd);
65-
}
66-
67-
@Test
68-
void testBuildHostArgs_UnifiedHost_WithAccountIdOnly() {
69-
DatabricksConfig config =
70-
new DatabricksConfig()
71-
.setHost(UNIFIED_HOST)
72-
.setExperimentalIsUnifiedHost(true)
73-
.setAccountId(ACCOUNT_ID);
74-
75-
List<String> cmd = provider.buildHostArgs(CLI_PATH, config);
76-
77-
assertEquals(
78-
Arrays.asList(
79-
CLI_PATH,
80-
"auth",
81-
"token",
82-
"--host",
83-
UNIFIED_HOST,
84-
"--experimental-is-unified-host",
85-
"--account-id",
86-
ACCOUNT_ID),
87-
cmd);
88-
}
89-
90-
@Test
91-
void testBuildHostArgs_UnifiedHost_WithWorkspaceIdOnly() {
92-
DatabricksConfig config =
93-
new DatabricksConfig()
94-
.setHost(UNIFIED_HOST)
95-
.setExperimentalIsUnifiedHost(true)
96-
.setWorkspaceId(WORKSPACE_ID);
97-
98-
List<String> cmd = provider.buildHostArgs(CLI_PATH, config);
99-
100-
assertEquals(
101-
Arrays.asList(
102-
CLI_PATH,
103-
"auth",
104-
"token",
105-
"--host",
106-
UNIFIED_HOST,
107-
"--experimental-is-unified-host",
108-
"--workspace-id",
109-
WORKSPACE_ID),
110-
cmd);
111-
}
112-
113-
@Test
114-
void testBuildHostArgs_UnifiedHost_WithNoAccountIdOrWorkspaceId() {
115-
DatabricksConfig config =
116-
new DatabricksConfig().setHost(UNIFIED_HOST).setExperimentalIsUnifiedHost(true);
117-
118-
List<String> cmd = provider.buildHostArgs(CLI_PATH, config);
119-
120-
assertEquals(
121-
Arrays.asList(
122-
CLI_PATH, "auth", "token", "--host", UNIFIED_HOST, "--experimental-is-unified-host"),
123-
cmd);
124-
}
125-
126-
@Test
127-
void testBuildHostArgs_UnifiedHostFalse_WithAccountHost() {
128-
// When experimentalIsUnifiedHost is explicitly false, should fall back to account-id logic
129-
DatabricksConfig config =
130-
new DatabricksConfig()
131-
.setHost(ACCOUNT_HOST)
132-
.setExperimentalIsUnifiedHost(false)
133-
.setAccountId(ACCOUNT_ID);
134-
135-
List<String> cmd = provider.buildHostArgs(CLI_PATH, config);
136-
137-
assertEquals(
138-
Arrays.asList(
139-
CLI_PATH, "auth", "token", "--host", ACCOUNT_HOST, "--account-id", ACCOUNT_ID),
140-
cmd);
46+
assertEquals(Arrays.asList(CLI_PATH, "auth", "token", "--host", HOST), cmd);
14147
}
14248
}

0 commit comments

Comments
 (0)