Skip to content

Commit

Permalink
Add support for --force-lock for deploy and destroy (#1206)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->

## Tests
<!-- How is this tested? -->
  • Loading branch information
kartikgupta-db authored Apr 30, 2024
1 parent ac79ea0 commit 1047e97
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
20 changes: 20 additions & 0 deletions packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
"category": "Databricks",
"icon": "$(trash)"
},
{
"command": "databricks.bundle.forceDeploy",
"title": "Force deploy bundle",
"category": "Databricks",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle"
},
{
"command": "databricks.bundle.forceDestroy",
"title": "Force destroy bundle",
"category": "Databricks",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -429,6 +441,14 @@
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
"group": "navigation@1"
},
{
"command": "databricks.bundle.forceDeploy",
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle"
},
{
"command": "databricks.bundle.forceDestroy",
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle"
},
{
"command": "databricks.bundle.variable.openFile",
"when": "view == dabsVariableView && databricks.context.bundle.deploymentState == idle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
}

@Mutex.synchronise("mutex")
public async deploy() {
public async deploy(force = false) {
if (this.target === undefined) {
throw new Error("Target is undefined");
}
Expand All @@ -72,12 +72,13 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
this.authProvider,
this.workspaceFolder,
this.workspaceConfigs.databrickscfgLocation,
this.logger
this.logger,
force
);
}

@Mutex.synchronise("mutex")
public async destroy() {
public async destroy(force = false) {
if (this.target === undefined) {
throw new Error("Target is undefined");
}
Expand All @@ -90,7 +91,8 @@ export class BundleRemoteStateModel extends BaseModelWithStateCache<BundleRemote
this.authProvider,
this.workspaceFolder,
this.workspaceConfigs.databrickscfgLocation,
this.logger
this.logger,
force
);
}

Expand Down
23 changes: 19 additions & 4 deletions packages/databricks-vscode/src/cli/CliWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,20 @@ export class CliWrapper {
authProvider: AuthProvider,
workspaceFolder: Uri,
configfilePath?: string,
logger?: logging.NamedLogger
logger?: logging.NamedLogger,
force = false
) {
await commands.executeCommand("databricks.bundle.showLogs");
return await runBundleCommand(
"deploy",
this.cliPath,
["bundle", "deploy", "--target", target],
[
"bundle",
"deploy",
"--target",
target,
...(force ? ["--force-lock"] : []),
],
workspaceFolder,
{
start: [`Deploying the bundle for target ${target}...`].concat(
Expand All @@ -511,13 +518,21 @@ export class CliWrapper {
authProvider: AuthProvider,
workspaceFolder: Uri,
configfilePath?: string,
logger?: logging.NamedLogger
logger?: logging.NamedLogger,
force = false
) {
await commands.executeCommand("databricks.bundle.showLogs");
return await runBundleCommand(
"destroy",
this.cliPath,
["bundle", "destroy", "--target", target, "--auto-approve"],
[
"bundle",
"destroy",
"--target",
target,
"--auto-approve",
...(force ? ["--force-lock"] : []),
],
workspaceFolder,
{
start: `Destroying the bundle for target ${target}...`,
Expand Down
10 changes: 10 additions & 0 deletions packages/databricks-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,16 @@ export async function activate(
bundleCommands.deployCommand,
bundleCommands
),
telemetry.registerCommand(
"databricks.bundle.forceDeploy",
bundleCommands.forceDeployCommand,
bundleCommands
),
telemetry.registerCommand(
"databricks.bundle.forceDestroy",
bundleCommands.forceDestroyCommand,
bundleCommands
),
telemetry.registerCommand(
"databricks.bundle.deployAndRun",
bundleCommands.deployAndRun,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ export class BundleCommands implements Disposable {
private deployMutex = new Mutex();

@Mutex.synchronise("deployMutex")
async deploy() {
async deploy(force = false) {
try {
this.whenContext.setDeploymentState("deploying");
await window.withProgress(
{location: ProgressLocation.Notification, cancellable: false},
async () => {
await this.bundleRemoteStateModel.deploy();
await this.bundleRemoteStateModel.deploy(force);
}
);

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

@onError({log: true, popup: false})
public async forceDeployCommand() {
await this.deploy(true);
}

@onError({popup: {prefix: "Error running resource."}})
async deployAndRun(treeNode: BundleResourceExplorerTreeNode) {
if (!isRunnable(treeNode)) {
Expand Down Expand Up @@ -147,8 +152,7 @@ export class BundleCommands implements Disposable {
this.bundleRunStatusManager.cancel(treeNode.resourceKey);
}

@onError({log: true, popup: false})
async destroy() {
async destroy(force = false) {
if ((await this.configModel.get("mode")) !== "development") {
const confirm = await window.showErrorMessage(
"Are you sure you want to destroy this bundle and all resources associated with it?",
Expand All @@ -167,7 +171,7 @@ export class BundleCommands implements Disposable {
await window.withProgress(
{location: ProgressLocation.Notification, cancellable: false},
async () => {
await this.bundleRemoteStateModel.destroy();
await this.bundleRemoteStateModel.destroy(force);
}
);

Expand All @@ -185,6 +189,16 @@ export class BundleCommands implements Disposable {
}
}

@onError({log: true, popup: false})
public async destroyCommand() {
await this.destroy();
}

@onError({log: true, popup: false})
public async forceDestroyCommand() {
await this.destroy(true);
}

dispose() {
this.disposables.forEach((i) => i.dispose());
}
Expand Down

0 comments on commit 1047e97

Please sign in to comment.