Skip to content

Commit 5e44b1f

Browse files
Don't allow per file run modes in prod/staging target (#1032)
## Changes * We still keep showing the actual options to run, because this gives users a pathway to figure out why the modes are disabled. * We want to block this because we write wrappers into the remote sync desitnation, which is essentially editing the prod deployment. We don't want to do that. ## Tests <!-- How is this tested? -->
1 parent 4f8ece7 commit 5e44b1f

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

packages/databricks-vscode/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,14 @@ export async function activate(
584584
const runCommands = new RunCommands(connectionManager);
585585
const debugFactory = new DatabricksDebugAdapterFactory(
586586
connectionManager,
587+
configModel,
587588
bundleCommands,
588589
context,
589590
wsfsAccessVerifier
590591
);
591592
const debugWorkflowFactory = new DatabricksWorkflowDebugAdapterFactory(
592593
connectionManager,
594+
configModel,
593595
wsfsAccessVerifier,
594596
context,
595597
bundleCommands

packages/databricks-vscode/src/run/DatabricksDebugAdapter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {WorkspaceFsAccessVerifier} from "../workspace-fs";
2424
import {DatabricksRuntime} from "./DatabricksRuntime";
2525
import {Subject} from "./Subject";
2626
import {BundleCommands} from "../ui/bundle-resource-explorer/BundleCommands";
27+
import {ConfigModel} from "../configuration/models/ConfigModel";
2728

2829
/**
2930
* This interface describes the mock-debug specific launch attributes
@@ -47,6 +48,7 @@ export class DatabricksDebugAdapterFactory
4748
{
4849
constructor(
4950
private connection: ConnectionManager,
51+
private configModel: ConfigModel,
5052
private bundleCommands: BundleCommands,
5153
private context: ExtensionContext,
5254
private wsfsAccessVerifier: WorkspaceFsAccessVerifier
@@ -58,6 +60,7 @@ export class DatabricksDebugAdapterFactory
5860
return new DebugAdapterInlineImplementation(
5961
new DatabricksDebugSession(
6062
this.connection,
63+
this.configModel,
6164
this.bundleCommands,
6265
this.context,
6366
this.wsfsAccessVerifier
@@ -73,6 +76,7 @@ export class DatabricksDebugSession extends LoggingDebugSession {
7376

7477
constructor(
7578
connection: ConnectionManager,
79+
configModel: ConfigModel,
7680
bundleCommands: BundleCommands,
7781
context: ExtensionContext,
7882
wsfsAccessVerifier: WorkspaceFsAccessVerifier
@@ -81,6 +85,7 @@ export class DatabricksDebugSession extends LoggingDebugSession {
8185

8286
this.runtime = new DatabricksRuntime(
8387
connection,
88+
configModel,
8489
bundleCommands,
8590
context,
8691
wsfsAccessVerifier

packages/databricks-vscode/src/run/DatabricksRuntime.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ import {
2020
SyncDestinationMapper,
2121
} from "../sync/SyncDestination";
2222
import {ConnectionManager} from "../configuration/ConnectionManager";
23-
import {promptForClusterAttach, promptForClusterStart} from "./prompts";
23+
import {
24+
promptForChangingTargetMode,
25+
promptForClusterAttach,
26+
promptForClusterStart,
27+
} from "./prompts";
2428
import * as fs from "node:fs/promises";
2529
import {parseErrorResult} from "./ErrorParser";
2630
import path from "node:path";
2731
import {WorkspaceFsAccessVerifier} from "../workspace-fs";
2832
import {Time, TimeUnits} from "@databricks/databricks-sdk";
2933
import {BundleCommands} from "../ui/bundle-resource-explorer/BundleCommands";
34+
import {ConfigModel} from "../configuration/models/ConfigModel";
3035

3136
export interface OutputEvent {
3237
type: "prio" | "out" | "err";
@@ -93,6 +98,7 @@ export class DatabricksRuntime implements Disposable {
9398

9499
constructor(
95100
private connection: ConnectionManager,
101+
private readonly configModel: ConfigModel,
96102
private bundleCommands: BundleCommands,
97103
private context: ExtensionContext,
98104
private wsfsAccessVerifier: WorkspaceFsAccessVerifier
@@ -123,6 +129,11 @@ export class DatabricksRuntime implements Disposable {
123129
log("Connecting to databricks...");
124130
await this.cancellable(this.connection.waitForConnect());
125131
}
132+
const mode = await this.configModel.get("mode");
133+
if (mode !== "development") {
134+
promptForChangingTargetMode(mode);
135+
return this._onErrorEmitter.fire(undefined);
136+
}
126137
const syncDestinationMapper = this.connection.syncDestinationMapper;
127138
if (syncDestinationMapper === undefined) {
128139
throw new Error("No sync destination found");

packages/databricks-vscode/src/run/DatabricksWorkflowDebugAdapter.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ import {DebugProtocol} from "@vscode/debugprotocol";
2222
import {ConnectionManager} from "../configuration/ConnectionManager";
2323
import {Subject} from "./Subject";
2424
import {WorkflowRunner} from "./WorkflowRunner";
25-
import {promptForClusterAttach, promptForClusterStart} from "./prompts";
25+
import {
26+
promptForChangingTargetMode,
27+
promptForClusterAttach,
28+
promptForClusterStart,
29+
} from "./prompts";
2630
import {LocalUri} from "../sync/SyncDestination";
2731
import {WorkspaceFsAccessVerifier} from "../workspace-fs";
2832
import {FileUtils} from "../utils";
2933
import {BundleCommands} from "../ui/bundle-resource-explorer/BundleCommands";
34+
import {ConfigModel} from "../configuration/models/ConfigModel";
3035

3136
/**
3237
* This interface describes the mock-debug specific launch attributes
@@ -52,6 +57,7 @@ export class DatabricksWorkflowDebugAdapterFactory
5257

5358
constructor(
5459
private connection: ConnectionManager,
60+
private configModel: ConfigModel,
5561
private wsfsAccessVerifier: WorkspaceFsAccessVerifier,
5662
context: ExtensionContext,
5763
bundleCommands: BundleCommands
@@ -71,6 +77,7 @@ export class DatabricksWorkflowDebugAdapterFactory
7177
return new DebugAdapterInlineImplementation(
7278
new DatabricksWorkflowDebugSession(
7379
this.connection,
80+
this.configModel,
7481
this.workflowRunner,
7582
this.wsfsAccessVerifier
7683
)
@@ -85,6 +92,7 @@ export class DatabricksWorkflowDebugSession extends LoggingDebugSession {
8592

8693
constructor(
8794
private connection: ConnectionManager,
95+
private configModel: ConfigModel,
8896
private workflowRunner: WorkflowRunner,
8997
private wsfsAccessVerifier: WorkspaceFsAccessVerifier
9098
) {
@@ -174,6 +182,12 @@ export class DatabricksWorkflowDebugSession extends LoggingDebugSession {
174182
await this.connection.waitForConnect();
175183
}
176184

185+
const mode = await this.configModel.get("mode");
186+
if (mode !== "development") {
187+
promptForChangingTargetMode(mode);
188+
return this.onError();
189+
}
190+
177191
const cluster = this.connection.cluster;
178192
const workspaceClient = this.connection.workspaceClient;
179193

@@ -184,7 +198,7 @@ export class DatabricksWorkflowDebugSession extends LoggingDebugSession {
184198
const syncDestinationMapper = this.connection.syncDestinationMapper;
185199
if (!syncDestinationMapper) {
186200
return this.onError(
187-
"You must configure code synchronization to run on Databricks"
201+
"No sync destination found. Maybe the databricks.yml is misconfgured."
188202
);
189203
}
190204

packages/databricks-vscode/src/run/RunCommands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {debug, Uri, window} from "vscode";
22
import {ConnectionManager} from "../configuration/ConnectionManager";
3-
import {promptForAttachingSyncDest} from "./prompts";
43
import {FileUtils} from "../utils";
54
import {LocalUri} from "../sync/SyncDestination";
65

@@ -54,8 +53,9 @@ export class RunCommands {
5453
}
5554

5655
if (this.connection.syncDestinationMapper === undefined) {
57-
promptForAttachingSyncDest();
58-
return;
56+
throw new Error(
57+
"No sync destination found. Maybe the databricks.yml is misconfgured."
58+
);
5959
}
6060

6161
await debug.startDebugging(

packages/databricks-vscode/src/run/prompts.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ export async function promptForClusterStart() {
2626
}
2727
}
2828

29-
export async function promptForAttachingSyncDest() {
29+
export async function promptForChangingTargetMode(curMode: string | undefined) {
3030
const response = await window.showErrorMessage(
31-
"Please configure a Sync Destination",
32-
"Configure Sync Destination",
31+
`Running is disabled for non development targets. Current target mode is ${curMode}.`,
32+
"Change Target Mode",
3333
"Cancel"
3434
);
3535
switch (response) {
36-
case "Configure Sync Destination":
36+
case "Change Target Mode":
3737
await commands.executeCommand(
38-
"databricks.connection.attachSyncDestination"
38+
"databricks.connection.bundle.selectTarget"
3939
);
4040
}
4141
}

0 commit comments

Comments
 (0)