Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,25 @@ public DatabricksEnvironment getDatabricksEnvironment() {
return DatabricksEnvironment.getEnvironmentFromHostname(this.host);
}

private DatabricksConfig clone(Set<String> fieldsToSkip) {
DatabricksConfig newConfig = new DatabricksConfig();
for (Field f : DatabricksConfig.class.getDeclaredFields()) {
if (fieldsToSkip.contains(f.getName())) {
continue;
}
try {
f.set(newConfig, f.get(this));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return newConfig;
}

public DatabricksConfig clone() {
return clone(new HashSet<>());
}

public DatabricksConfig newWithWorkspaceHost(String host) {
Set<String> fieldsToSkip =
new HashSet<>(
Expand All @@ -645,18 +664,6 @@ public DatabricksConfig newWithWorkspaceHost(String host) {
// don't cache the
// header factory.
"headerFactory"));
DatabricksConfig newConfig = new DatabricksConfig();
for (Field f : DatabricksConfig.class.getDeclaredFields()) {
if (fieldsToSkip.contains(f.getName())) {
continue;
}
try {
f.set(newConfig, f.get(this));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
newConfig.setHost(host);
return newConfig;
return clone(fieldsToSkip).setHost(host);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,22 @@ public void testNewWithWorkspaceHost() {
assert newWorkspaceConfig.getClientId().equals("my-client-id");
assert newWorkspaceConfig.getClientSecret().equals("my-client-secret");
}

@Test
public void testClone() {
DatabricksConfig config =
new DatabricksConfig()
.setAuthType("oauth-m2m")
.setClientId("my-client-id")
.setClientSecret("my-client-secret")
.setAccountId("account-id")
.setHost("https://account.cloud.databricks.com");

DatabricksConfig newWorkspaceConfig = config.clone();

assert newWorkspaceConfig.getHost().equals("https://account.cloud.databricks.com");
assert newWorkspaceConfig.getAuthType().equals("oauth-m2m");
assert newWorkspaceConfig.getClientId().equals("my-client-id");
assert newWorkspaceConfig.getClientSecret().equals("my-client-secret");
}
}
Loading