Skip to content

Commit a342738

Browse files
Add support for bundle destroy command (#1205)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent 6806a38 commit a342738

File tree

8 files changed

+524
-188
lines changed

8 files changed

+524
-188
lines changed

packages/databricks-vscode/package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,28 +227,28 @@
227227
"command": "databricks.bundle.refreshRemoteState",
228228
"icon": "$(refresh)",
229229
"title": "Refresh remote state",
230-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
230+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
231231
"category": "Databricks"
232232
},
233233
{
234234
"command": "databricks.bundle.deploy",
235235
"icon": "$(cloud-upload)",
236236
"title": "Deploy bundle",
237-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
237+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
238238
"category": "Databricks"
239239
},
240240
{
241241
"command": "databricks.bundle.deployAndRun",
242242
"icon": "$(debug-start)",
243243
"title": "Deploy the bundle and run the resource",
244-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
244+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
245245
"category": "Databricks"
246246
},
247247
{
248248
"command": "databricks.bundle.cancelRun",
249249
"title": "Cancel run",
250250
"icon": "$(debug-stop)",
251-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
251+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
252252
"category": "Databricks"
253253
},
254254
{
@@ -314,16 +314,23 @@
314314
{
315315
"command": "databricks.bundle.variable.openFile",
316316
"title": "Override bundle variables",
317-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
317+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
318318
"category": "Databricks",
319319
"icon": "$(gear)"
320320
},
321321
{
322322
"command": "databricks.bundle.variable.reset",
323323
"title": "Reset to default values",
324-
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
324+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
325325
"category": "Databricks",
326326
"icon": "$(discard)"
327+
},
328+
{
329+
"command": "databricks.bundle.destroy",
330+
"title": "Destroy bundle",
331+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
332+
"category": "Databricks",
333+
"icon": "$(trash)"
327334
}
328335
],
329336
"viewsContainers": {
@@ -438,6 +445,11 @@
438445
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
439446
"group": "navigation@1"
440447
},
448+
{
449+
"command": "databricks.bundle.destroy",
450+
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
451+
"group": "navigation@1"
452+
},
441453
{
442454
"command": "databricks.bundle.variable.openFile",
443455
"when": "view == dabsVariableView && databricks.context.bundle.deploymentState == idle",

packages/databricks-vscode/src/bundle/models/BundleRemoteStateModel.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import lodash from "lodash";
99
import {WorkspaceConfigs} from "../../vscode-objs/WorkspaceConfigs";
1010
import {logging} from "@databricks/databricks-sdk";
1111
import {Loggers} from "../../logger";
12-
import {MsPythonExtensionWrapper} from "../../language/MsPythonExtensionWrapper";
1312

1413
/* eslint-disable @typescript-eslint/naming-convention */
1514
export type BundleResourceModifiedStatus = "created" | "deleted" | "updated";
@@ -49,7 +48,6 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
4948
constructor(
5049
private readonly cli: CliWrapper,
5150
private readonly workspaceFolder: Uri,
52-
private readonly pythonExtension: MsPythonExtensionWrapper,
5351
private readonly workspaceConfigs: WorkspaceConfigs
5452
) {
5553
super();
@@ -73,7 +71,24 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
7371
this.target,
7472
this.authProvider,
7573
this.workspaceFolder,
76-
this.pythonExtension,
74+
this.workspaceConfigs.databrickscfgLocation,
75+
this.logger
76+
);
77+
}
78+
79+
@Mutex.synchronise("mutex")
80+
public async destroy() {
81+
if (this.target === undefined) {
82+
throw new Error("Target is undefined");
83+
}
84+
if (this.authProvider === undefined) {
85+
throw new Error("No authentication method is set");
86+
}
87+
88+
await this.cli.bundleDestroy(
89+
this.target,
90+
this.authProvider,
91+
this.workspaceFolder,
7792
this.workspaceConfigs.databrickscfgLocation,
7893
this.logger
7994
);
@@ -118,18 +133,18 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
118133
return {};
119134
}
120135

121-
const output = await this.cli.bundleSummarise(
136+
const {stdout} = await this.cli.bundleSummarise(
122137
this.target,
123138
this.authProvider,
124139
this.workspaceFolder,
125140
this.workspaceConfigs.databrickscfgLocation,
126141
this.logger
127142
);
128143

129-
if (output === "" || output === undefined) {
144+
if (stdout === "" || stdout === undefined) {
130145
return {};
131146
}
132-
return JSON.parse(output);
147+
return JSON.parse(stdout);
133148
}
134149

135150
/**

packages/databricks-vscode/src/bundle/models/BundleValidateModel.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ export class BundleValidateModel extends BaseModelWithStateCache<BundleValidateS
6767
}
6868

6969
const validateOutput = JSON.parse(
70-
await this.cli.bundleValidate(
71-
this.target,
72-
this.authProvider,
73-
this.workspaceFolder,
74-
workspaceConfigs.databrickscfgLocation,
75-
this.logger
76-
)
70+
(
71+
await this.cli.bundleValidate(
72+
this.target,
73+
this.authProvider,
74+
this.workspaceFolder,
75+
workspaceConfigs.databrickscfgLocation,
76+
this.logger
77+
)
78+
).stdout
7779
) as BundleTarget;
7880

7981
return {

0 commit comments

Comments
 (0)