Skip to content

Commit ea3ed45

Browse files
Remove bundle source (#1005)
## Changes * Remove config source tag. It was being used only for clusterId any and we can figure that out by diffing with the `validatedConfig`. * Expose `validateConfig` and `preValidateConfig` from the config model. * Hide configModel submodels. ## Tests <!-- How is this tested? -->
1 parent b853df6 commit ea3ed45

File tree

7 files changed

+54
-120
lines changed

7 files changed

+54
-120
lines changed

packages/databricks-vscode/src/configuration/ConnectionCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class ConnectionCommands implements Disposable {
200200
}
201201

202202
async selectTarget() {
203-
const targets = await this.configModel.bundlePreValidateModel.targets;
203+
const targets = await this.configModel.targets;
204204
const currentTarget = this.configModel.target;
205205
if (targets === undefined) {
206206
return;

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ export class ConnectionManager implements Disposable {
171171
}
172172

173173
// Try to load a profile user had previously selected for this target
174-
const savedProfile = (
175-
await this.configModel.overrideableConfigModel.load()
176-
).authProfile;
174+
const savedProfile = (await this.configModel.get("overrides"))
175+
?.authProfile;
177176
if (savedProfile !== undefined) {
178177
const authProvider = new ProfileAuthProvider(host, savedProfile);
179178
if (await authProvider.check()) {
@@ -183,8 +182,8 @@ export class ConnectionManager implements Disposable {
183182

184183
// Try to load any parameters that are hard coded in the bundle
185184
const bundleAuthParams =
186-
await this.configModel.bundlePreValidateModel.load();
187-
if (bundleAuthParams.authParams !== undefined) {
185+
await this.configModel.get("preValidateConfig");
186+
if (bundleAuthParams?.authParams !== undefined) {
188187
throw new Error("Bundle auth params not implemented");
189188
}
190189

packages/databricks-vscode/src/configuration/models/ConfigModel.ts

Lines changed: 44 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,37 @@ const defaults: ConfigState = {
2323
mode: "development",
2424
};
2525

26-
const SELECTED_BUNDLE_VALIDATE_CONFIG_KEYS = [
27-
"clusterId",
28-
"remoteRootPath",
29-
] as const;
26+
const TOP_LEVEL_VALIDATE_CONFIG_KEYS = ["clusterId", "remoteRootPath"] as const;
3027

31-
const SELECTED_BUNDLE_PRE_VALIDATE_CONFIG_KEYS = [
28+
const TOP_LEVEL_PRE_VALIDATE_CONFIG_KEYS = [
3229
"host",
3330
"mode",
3431
"authParams",
3532
] as const;
3633

3734
type ConfigState = Pick<
3835
BundleValidateState,
39-
(typeof SELECTED_BUNDLE_VALIDATE_CONFIG_KEYS)[number]
36+
(typeof TOP_LEVEL_VALIDATE_CONFIG_KEYS)[number]
4037
> &
4138
Pick<
4239
BundlePreValidateState,
43-
(typeof SELECTED_BUNDLE_PRE_VALIDATE_CONFIG_KEYS)[number]
40+
(typeof TOP_LEVEL_PRE_VALIDATE_CONFIG_KEYS)[number]
4441
> &
45-
OverrideableConfigState;
46-
47-
export type ConfigSource = "bundle" | "override" | "default";
48-
49-
type ConfigSourceMap = {
50-
[K in keyof ConfigState]: {
51-
config: ConfigState[K];
52-
source: ConfigSource;
42+
OverrideableConfigState & {
43+
preValidateConfig?: BundlePreValidateState;
44+
validateConfig?: BundleValidateState;
45+
overrides?: OverrideableConfigState;
5346
};
54-
};
5547

48+
function selectTopLevelKeys(
49+
obj: any,
50+
keys: readonly string[]
51+
): Record<string, any> {
52+
return keys.reduce((prev: any, key) => {
53+
prev[key] = obj[key];
54+
return prev;
55+
}, {});
56+
}
5657
/**
5758
* In memory view of the databricks configs loaded from overrides and bundle.
5859
*/
@@ -64,43 +65,36 @@ export class ConfigModel implements Disposable {
6465
* after configsMutex to avoid deadlocks.
6566
*/
6667
private readonly readStateMutex = new Mutex();
67-
private readonly configCache = new CachedValue<ConfigSourceMap>(
68+
private readonly configCache = new CachedValue<ConfigState>(
6869
this.readState.bind(this)
6970
);
7071

7172
@Mutex.synchronise("readStateMutex")
7273
async readState() {
7374
if (this.target === undefined) {
74-
return {config: {}, source: {}};
75+
return {};
7576
}
76-
const bundleValidateConfig = await this.bundleValidateModel.load([
77-
...SELECTED_BUNDLE_VALIDATE_CONFIG_KEYS,
78-
]);
77+
const bundleValidateConfig = await this.bundleValidateModel.load();
7978
const overrides = await this.overrideableConfigModel.load();
80-
const bundleConfigs = await this.bundlePreValidateModel.load([
81-
...SELECTED_BUNDLE_PRE_VALIDATE_CONFIG_KEYS,
82-
]);
83-
const newConfigs = {
84-
...bundleConfigs,
85-
...bundleValidateConfig,
79+
const bundlePreValidateConfig =
80+
await this.bundlePreValidateModel.load();
81+
82+
return {
83+
...selectTopLevelKeys(
84+
bundlePreValidateConfig,
85+
TOP_LEVEL_PRE_VALIDATE_CONFIG_KEYS
86+
),
87+
...selectTopLevelKeys(
88+
bundleValidateConfig,
89+
TOP_LEVEL_VALIDATE_CONFIG_KEYS
90+
),
8691
...overrides,
92+
preValidateConfig: bundlePreValidateConfig,
93+
validateConfig: bundleValidateConfig,
94+
overrides,
8795
};
88-
89-
const newValue: any = {};
90-
(Object.keys(newConfigs) as (keyof typeof newConfigs)[]).forEach(
91-
(key) => {
92-
newValue[key] = {
93-
config: newConfigs[key],
94-
source:
95-
overrides !== undefined && key in overrides
96-
? "override"
97-
: "bundle",
98-
};
99-
}
100-
);
101-
102-
return newValue;
10396
}
97+
10498
public onDidChange = this.configCache.onDidChange.bind(this.configCache);
10599
public onDidChangeKey = this.configCache.onDidChangeKey.bind(
106100
this.configCache
@@ -117,9 +111,9 @@ export class ConfigModel implements Disposable {
117111
private _authProvider: AuthProvider | undefined;
118112

119113
constructor(
120-
public readonly bundleValidateModel: BundleValidateModel,
121-
public readonly overrideableConfigModel: OverrideableConfigModel,
122-
public readonly bundlePreValidateModel: BundlePreValidateModel,
114+
private readonly bundleValidateModel: BundleValidateModel,
115+
private readonly overrideableConfigModel: OverrideableConfigModel,
116+
private readonly bundlePreValidateModel: BundlePreValidateModel,
123117
private readonly vscodeWhenContext: CustomWhenContext,
124118
private readonly stateStorage: StateStorage
125119
) {
@@ -133,7 +127,7 @@ export class ConfigModel implements Disposable {
133127
//refresh cache to trigger onDidChange event
134128
await this.configCache.refresh();
135129
}),
136-
...SELECTED_BUNDLE_VALIDATE_CONFIG_KEYS.map((key) =>
130+
...TOP_LEVEL_VALIDATE_CONFIG_KEYS.map((key) =>
137131
this.bundleValidateModel.onDidChangeKey(key)(async () => {
138132
//refresh cache to trigger onDidChange event
139133
this.configCache.refresh();
@@ -147,6 +141,9 @@ export class ConfigModel implements Disposable {
147141
await this.readTarget();
148142
}
149143

144+
get targets() {
145+
return this.bundlePreValidateModel.targets;
146+
}
150147
/**
151148
* Try to read target from bundle config.
152149
* If not found, try to read from state storage.
@@ -226,24 +223,7 @@ export class ConfigModel implements Disposable {
226223
public async get<T extends keyof ConfigState>(
227224
key: T
228225
): Promise<ConfigState[T] | undefined> {
229-
return (await this.configCache.value)[key]?.config ?? defaults[key];
230-
}
231-
232-
/**
233-
* Return config value along with source of the config.
234-
* Refer to {@link DatabricksConfigSource} for possible values.
235-
*/
236-
@Mutex.synchronise("configsMutex")
237-
public async getS<T extends keyof ConfigState>(
238-
key: T
239-
): Promise<ConfigSourceMap[T] | undefined> {
240-
const config = (await this.configCache.value)[key];
241-
return config
242-
? ({
243-
config: config.config ?? defaults[key],
244-
source: config.source ?? "default",
245-
} as ConfigSourceMap[T])
246-
: undefined;
226+
return (await this.configCache.value)[key] ?? defaults[key];
247227
}
248228

249229
@Mutex.synchronise("configsMutex")

packages/databricks-vscode/src/configuration/ui/AuthTypeComponent.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class AuthTypeComponent extends BaseComponent {
5555
}
5656

5757
const config =
58-
(await this.configModel.getS("authProfile")) ??
59-
(await this.configModel.getS("authParams"));
58+
(await this.configModel.get("authProfile")) ??
59+
(await this.configModel.get("authParams"));
6060
if (config === undefined) {
6161
// This case can never happen. This is just to make ts happy.
6262
return [];
@@ -72,7 +72,6 @@ export class AuthTypeComponent extends BaseComponent {
7272
description: authProvider.describe(),
7373
contextValue: getContextValue(authProvider.authType),
7474
id: TREE_ICON_ID,
75-
source: config.source,
7675
},
7776
];
7877
}

packages/databricks-vscode/src/configuration/ui/ClusterComponent.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export class ClusterComponent extends BaseComponent {
8585

8686
@onError({popup: true})
8787
private async getRoot(): Promise<ConfigurationTreeItem[]> {
88-
const config = await this.configModel.getS("clusterId");
88+
const config = await this.configModel.get("clusterId");
8989

90-
if (config?.config === undefined) {
90+
if (config === undefined) {
9191
// Cluster is not set in bundle and override
9292
// We are logged in -> Select cluster prompt
9393
const label = "Select a cluster";
@@ -124,7 +124,6 @@ export class ClusterComponent extends BaseComponent {
124124
collapsibleState: TreeItemCollapsibleState.Expanded,
125125
contextValue: contextValue,
126126
iconPath: icon,
127-
source: config.source,
128127
id: TREE_ICON_ID,
129128
},
130129
];

packages/databricks-vscode/src/configuration/ui/ConfigurationDataProvider.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
EventEmitter,
55
TreeDataProvider,
66
TreeItem,
7-
ThemeIcon,
8-
ThemeColor,
97
} from "vscode";
108

119
import {ConnectionManager} from "../ConnectionManager";
@@ -79,47 +77,8 @@ export class ConfigurationDataProvider
7977
break;
8078
}
8179

82-
const configSourceTooltip = {
83-
bundle: "This configuration is loaded from a Databricks Asset Bundle.",
84-
override: "This configuration is a workspace only override.",
85-
};
86-
8780
return (
8881
await Promise.all(this.components.map((c) => c.getChildren(parent)))
89-
)
90-
.map((items) => {
91-
// Add config source item to expanded view, if the parent config is not a default
92-
if (
93-
parent?.source === undefined ||
94-
parent.source === "default" ||
95-
items.length === 0
96-
) {
97-
return items;
98-
}
99-
100-
const tooltip = configSourceTooltip[parent.source];
101-
return [
102-
{
103-
label: "Source",
104-
description: parent.source,
105-
iconPath: new ThemeIcon("info", new ThemeColor("info")),
106-
tooltip,
107-
},
108-
...items,
109-
];
110-
})
111-
.flat()
112-
.map((item) => {
113-
// Add config source tooltip to the config root item, if the config is not a default
114-
// and parent is undefined.
115-
if (item.source === undefined || item.source === "default") {
116-
return item;
117-
}
118-
const tooltip = configSourceTooltip[item.source];
119-
return {
120-
...item,
121-
tooltip,
122-
};
123-
});
82+
).flat();
12483
}
12584
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {TreeItem} from "vscode";
2-
import {ConfigSource} from "../models/ConfigModel";
32

43
export interface ConfigurationTreeItem extends TreeItem {
5-
source?: ConfigSource;
64
url?: string;
75
}

0 commit comments

Comments
 (0)