Skip to content

Commit 1047e97

Browse files
Add support for --force-lock for deploy and destroy (#1206)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent ac79ea0 commit 1047e97

File tree

5 files changed

+74
-13
lines changed

5 files changed

+74
-13
lines changed

packages/databricks-vscode/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,18 @@
310310
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
311311
"category": "Databricks",
312312
"icon": "$(trash)"
313+
},
314+
{
315+
"command": "databricks.bundle.forceDeploy",
316+
"title": "Force deploy bundle",
317+
"category": "Databricks",
318+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle"
319+
},
320+
{
321+
"command": "databricks.bundle.forceDestroy",
322+
"title": "Force destroy bundle",
323+
"category": "Databricks",
324+
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle"
313325
}
314326
],
315327
"viewsContainers": {
@@ -429,6 +441,14 @@
429441
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
430442
"group": "navigation@1"
431443
},
444+
{
445+
"command": "databricks.bundle.forceDeploy",
446+
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle"
447+
},
448+
{
449+
"command": "databricks.bundle.forceDestroy",
450+
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle"
451+
},
432452
{
433453
"command": "databricks.bundle.variable.openFile",
434454
"when": "view == dabsVariableView && databricks.context.bundle.deploymentState == idle",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
5959
}
6060

6161
@Mutex.synchronise("mutex")
62-
public async deploy() {
62+
public async deploy(force = false) {
6363
if (this.target === undefined) {
6464
throw new Error("Target is undefined");
6565
}
@@ -72,12 +72,13 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
7272
this.authProvider,
7373
this.workspaceFolder,
7474
this.workspaceConfigs.databrickscfgLocation,
75-
this.logger
75+
this.logger,
76+
force
7677
);
7778
}
7879

7980
@Mutex.synchronise("mutex")
80-
public async destroy() {
81+
public async destroy(force = false) {
8182
if (this.target === undefined) {
8283
throw new Error("Target is undefined");
8384
}
@@ -90,7 +91,8 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
9091
this.authProvider,
9192
this.workspaceFolder,
9293
this.workspaceConfigs.databrickscfgLocation,
93-
this.logger
94+
this.logger,
95+
force
9496
);
9597
}
9698

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,20 @@ export class CliWrapper {
484484
authProvider: AuthProvider,
485485
workspaceFolder: Uri,
486486
configfilePath?: string,
487-
logger?: logging.NamedLogger
487+
logger?: logging.NamedLogger,
488+
force = false
488489
) {
489490
await commands.executeCommand("databricks.bundle.showLogs");
490491
return await runBundleCommand(
491492
"deploy",
492493
this.cliPath,
493-
["bundle", "deploy", "--target", target],
494+
[
495+
"bundle",
496+
"deploy",
497+
"--target",
498+
target,
499+
...(force ? ["--force-lock"] : []),
500+
],
494501
workspaceFolder,
495502
{
496503
start: [`Deploying the bundle for target ${target}...`].concat(
@@ -511,13 +518,21 @@ export class CliWrapper {
511518
authProvider: AuthProvider,
512519
workspaceFolder: Uri,
513520
configfilePath?: string,
514-
logger?: logging.NamedLogger
521+
logger?: logging.NamedLogger,
522+
force = false
515523
) {
516524
await commands.executeCommand("databricks.bundle.showLogs");
517525
return await runBundleCommand(
518526
"destroy",
519527
this.cliPath,
520-
["bundle", "destroy", "--target", target, "--auto-approve"],
528+
[
529+
"bundle",
530+
"destroy",
531+
"--target",
532+
target,
533+
"--auto-approve",
534+
...(force ? ["--force-lock"] : []),
535+
],
521536
workspaceFolder,
522537
{
523538
start: `Destroying the bundle for target ${target}...`,

packages/databricks-vscode/src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,16 @@ export async function activate(
634634
bundleCommands.deployCommand,
635635
bundleCommands
636636
),
637+
telemetry.registerCommand(
638+
"databricks.bundle.forceDeploy",
639+
bundleCommands.forceDeployCommand,
640+
bundleCommands
641+
),
642+
telemetry.registerCommand(
643+
"databricks.bundle.forceDestroy",
644+
bundleCommands.forceDestroyCommand,
645+
bundleCommands
646+
),
637647
telemetry.registerCommand(
638648
"databricks.bundle.deployAndRun",
639649
bundleCommands.deployAndRun,

packages/databricks-vscode/src/ui/bundle-resource-explorer/BundleCommands.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ export class BundleCommands implements Disposable {
8585
private deployMutex = new Mutex();
8686

8787
@Mutex.synchronise("deployMutex")
88-
async deploy() {
88+
async deploy(force = false) {
8989
try {
9090
this.whenContext.setDeploymentState("deploying");
9191
await window.withProgress(
9292
{location: ProgressLocation.Notification, cancellable: false},
9393
async () => {
94-
await this.bundleRemoteStateModel.deploy();
94+
await this.bundleRemoteStateModel.deploy(force);
9595
}
9696
);
9797

@@ -114,6 +114,11 @@ export class BundleCommands implements Disposable {
114114
await this.deploy();
115115
}
116116

117+
@onError({log: true, popup: false})
118+
public async forceDeployCommand() {
119+
await this.deploy(true);
120+
}
121+
117122
@onError({popup: {prefix: "Error running resource."}})
118123
async deployAndRun(treeNode: BundleResourceExplorerTreeNode) {
119124
if (!isRunnable(treeNode)) {
@@ -147,8 +152,7 @@ export class BundleCommands implements Disposable {
147152
this.bundleRunStatusManager.cancel(treeNode.resourceKey);
148153
}
149154

150-
@onError({log: true, popup: false})
151-
async destroy() {
155+
async destroy(force = false) {
152156
if ((await this.configModel.get("mode")) !== "development") {
153157
const confirm = await window.showErrorMessage(
154158
"Are you sure you want to destroy this bundle and all resources associated with it?",
@@ -167,7 +171,7 @@ export class BundleCommands implements Disposable {
167171
await window.withProgress(
168172
{location: ProgressLocation.Notification, cancellable: false},
169173
async () => {
170-
await this.bundleRemoteStateModel.destroy();
174+
await this.bundleRemoteStateModel.destroy(force);
171175
}
172176
);
173177

@@ -185,6 +189,16 @@ export class BundleCommands implements Disposable {
185189
}
186190
}
187191

192+
@onError({log: true, popup: false})
193+
public async destroyCommand() {
194+
await this.destroy();
195+
}
196+
197+
@onError({log: true, popup: false})
198+
public async forceDestroyCommand() {
199+
await this.destroy(true);
200+
}
201+
188202
dispose() {
189203
this.disposables.forEach((i) => i.dispose());
190204
}

0 commit comments

Comments
 (0)