Skip to content

Commit 4d195ac

Browse files
Remove unified flag usage, rely on host metadata (#720)
## 🥞 Stacked PR Use this [link](https://github.com/databricks/databricks-sdk-java/pull/720/files) to review incremental changes. - [**hectorcast-db/stack/port-8-remove-unified-flag**](#720) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/720/files)] --------- ## Summary Port of Go SDK [#1547](databricks/databricks-sdk-go#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 earlier PRs in this stack) handles populating config fields automatically. **Key changes:** - `getHostType()`: no longer returns `UNIFIED`; determined solely by URL pattern - `isAccountClient()`: no longer throws for unified hosts - `getClientType()`: simplified, no `UNIFIED` case - `fetchDefaultOidcEndpoints()`: removed unified OIDC branch, removed `getUnifiedOidcEndpoints()` - `DatabricksCliCredentialsProvider.buildHostArgs()`: removed `--experimental-is-unified-host`, `--account-id`, `--workspace-id` flags for unified case - `AccountClient.getWorkspaceClient()`: uses DNS zone matching (like Go SDK) to decide whether to reuse host or build deployment URL - `HostType` enum: removed `UNIFIED` value - `authenticate()`: removed `X-Databricks-Org-Id` header injection (handled by generated `*Impl.java` files) **Note:** `AccountClient.java` is a generated file. The template needs to be updated. `NO_CHANGELOG=true` ## Test plan - [x] All 1086 tests pass - [x] `UnifiedHostTest`, `DatabricksConfigTest`, `AccountClientTest`, `DatabricksCliCredentialsProviderTest` updated
1 parent f28430b commit 4d195ac

File tree

13 files changed

+152
-414
lines changed

13 files changed

+152
-414
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
@@ -51,18 +51,7 @@ public String authType() {
5151
List<String> buildHostArgs(String cliPath, DatabricksConfig config) {
5252
List<String> cmd =
5353
new ArrayList<>(Arrays.asList(cliPath, "auth", "token", "--host", config.getHost()));
54-
if (config.getExperimentalIsUnifiedHost() != null && config.getExperimentalIsUnifiedHost()) {
55-
// For unified hosts, pass account_id, workspace_id, and experimental flag
56-
cmd.add("--experimental-is-unified-host");
57-
if (config.getAccountId() != null) {
58-
cmd.add("--account-id");
59-
cmd.add(config.getAccountId());
60-
}
61-
if (config.getWorkspaceId() != null) {
62-
cmd.add("--workspace-id");
63-
cmd.add(config.getWorkspaceId());
64-
}
65-
} else if (config.getClientType() == ClientType.ACCOUNT) {
54+
if (config.getClientType() == ClientType.ACCOUNT) {
6655
cmd.add("--account-id");
6756
cmd.add(config.getAccountId());
6857
}

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

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,13 @@ private synchronized DatabricksConfig innerResolve() {
232232
}
233233

234234
/**
235-
* Attempts to resolve host metadata from the well-known endpoint. Only called for unified hosts.
236-
* Logs a warning and continues if metadata resolution fails, since not all hosts support the
237-
* discovery endpoint.
235+
* Attempts to resolve host metadata from the well-known endpoint. Logs a warning and continues if
236+
* metadata resolution fails, since not all hosts support the discovery endpoint.
238237
*/
239238
private void tryResolveHostMetadata() {
240239
if (host == null) {
241240
return;
242241
}
243-
if (experimentalIsUnifiedHost == null || !experimentalIsUnifiedHost) {
244-
return;
245-
}
246242
try {
247243
resolveHostMetadata();
248244
} catch (Exception e) {
@@ -275,11 +271,6 @@ public synchronized Map<String, String> authenticate() throws DatabricksExceptio
275271
}
276272
Map<String, String> headers = new HashMap<>(headerFactory.headers());
277273

278-
// For unified hosts with workspace operations, add the X-Databricks-Org-Id header
279-
if (getHostType() == HostType.UNIFIED && workspaceId != null && !workspaceId.isEmpty()) {
280-
headers.put("X-Databricks-Org-Id", workspaceId);
281-
}
282-
283274
return headers;
284275
} catch (DatabricksException e) {
285276
String msg = String.format("%s auth: %s", credentialsProvider.authType(), e.getMessage());
@@ -746,23 +737,14 @@ public boolean isAws() {
746737
}
747738

748739
public boolean isAccountClient() {
749-
if (getHostType() == HostType.UNIFIED) {
750-
throw new DatabricksException(
751-
"Cannot determine account client status for unified hosts. "
752-
+ "Use getHostType() or getClientType() instead. "
753-
+ "For unified hosts, client type depends on whether workspaceId is set.");
754-
}
755740
if (host == null) {
756741
return false;
757742
}
758743
return host.startsWith("https://accounts.") || host.startsWith("https://accounts-dod.");
759744
}
760745

761-
/** Returns the host type based on configuration settings and host URL. */
746+
/** Returns the host type based on the host URL pattern. */
762747
public HostType getHostType() {
763-
if (experimentalIsUnifiedHost != null && experimentalIsUnifiedHost) {
764-
return HostType.UNIFIED;
765-
}
766748
if (host == null) {
767749
return HostType.WORKSPACE;
768750
}
@@ -772,15 +754,10 @@ public HostType getHostType() {
772754
return HostType.WORKSPACE;
773755
}
774756

775-
/** Returns the client type based on host type and workspace ID configuration. */
757+
/** Returns the client type based on host type. */
776758
public ClientType getClientType() {
777759
HostType hostType = getHostType();
778760
switch (hostType) {
779-
case UNIFIED:
780-
// For unified hosts, client type depends on whether workspaceId is set
781-
return (workspaceId != null && !workspaceId.isEmpty())
782-
? ClientType.WORKSPACE
783-
: ClientType.ACCOUNT;
784761
case ACCOUNTS:
785762
return ClientType.ACCOUNT;
786763
case WORKSPACE:
@@ -926,24 +903,11 @@ private OpenIDConnectEndpoints fetchOidcEndpointsFromDiscovery() {
926903
return null;
927904
}
928905

929-
private OpenIDConnectEndpoints getUnifiedOidcEndpoints(String accountId) throws IOException {
930-
if (accountId == null || accountId.isEmpty()) {
931-
throw new DatabricksException(
932-
"account_id is required for unified host OIDC endpoint discovery");
933-
}
934-
String prefix = getHost() + "/oidc/accounts/" + accountId;
935-
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
936-
}
937-
938906
private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
939907
if (getHost() == null) {
940908
return null;
941909
}
942910

943-
// For unified hosts, use account-based OIDC endpoints
944-
if (getHostType() == HostType.UNIFIED) {
945-
return getUnifiedOidcEndpoints(getAccountId());
946-
}
947911
if (isAccountClient() && getAccountId() != null) {
948912
String prefix = getHost() + "/oidc/accounts/" + getAccountId();
949913
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 & 20 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;
@@ -37,7 +36,6 @@ public void testGetWorkspaceClientForUnifiedHost() {
3736
DatabricksConfig accountConfig =
3837
new DatabricksConfig()
3938
.setHost(unifiedHost)
40-
.setExperimentalIsUnifiedHost(true)
4139
.setAccountId("test-account")
4240
.setToken("test-token");
4341

@@ -49,28 +47,14 @@ public void testGetWorkspaceClientForUnifiedHost() {
4947

5048
WorkspaceClient workspaceClient = accountClient.getWorkspaceClient(workspace);
5149

52-
// Should have the same host
50+
// Should have the same host (unified hosts reuse the same host)
5351
assertEquals(unifiedHost, workspaceClient.config().getHost());
5452

5553
// Should have workspace ID set
5654
assertEquals("123456", workspaceClient.config().getWorkspaceId());
5755

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());
56+
// Host type is WORKSPACE (determined from URL pattern, not unified flag)
57+
assertEquals(HostType.WORKSPACE, workspaceClient.config().getHostType());
7458
}
7559

7660
@Test
@@ -79,7 +63,6 @@ public void testGetWorkspaceClientForSpogHostDoesNotMutateAccountConfig() {
7963
DatabricksConfig accountConfig =
8064
new DatabricksConfig()
8165
.setHost(spogHost)
82-
.setExperimentalIsUnifiedHost(true)
8366
.setAccountId("test-account")
8467
.setToken("test-token");
8568

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)