-
Notifications
You must be signed in to change notification settings - Fork 140
Provide an option to hook up DTS emulator when locally debugging DTS projects #4538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MicroFish91
wants to merge
24
commits into
main
Choose a base branch
from
mwf/convinced-gray
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f858697
Add new storage type pick and host/local settings logic
MicroFish91 c84b288
Update host.json preview dep
MicroFish91 eb005a9
Install deps
MicroFish91 cbe1707
Update extension bundle
MicroFish91 4cb51ba
Update durable detection logic
MicroFish91 5d5e2dd
Remove extra prop
MicroFish91 8cb081c
Add .NET deps
MicroFish91 ffb7b43
Fix accidental change
MicroFish91 bd1c815
Revert todo
MicroFish91 d89c079
Add todo
MicroFish91 e201fe5
Update comment
MicroFish91 dece3e9
Update comment
MicroFish91 0e94b73
Fully working implementation
MicroFish91 e43c2aa
Update comment
MicroFish91 e96ceb9
Update comment again
MicroFish91 0529729
Formatting
MicroFish91 96eae40
Make storage connection type reuse logic more simple
MicroFish91 98dc295
Merge with main
MicroFish91 3a3512d
Merge branch 'main' of https://github.com/microsoft/vscode-azurefunct…
MicroFish91 612ec9c
Update connection types
MicroFish91 c676ce9
Revert autoformatting change
MicroFish91 2537cc2
Revert more autoformatting
MicroFish91 9cff4b3
Merge branch 'main' of https://github.com/microsoft/vscode-azurefunct…
MicroFish91 b594736
Update wizard title
MicroFish91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/commands/appSettings/connectionSettings/IConnectionTypesContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type ConnectionType } from "../../../constants"; | ||
|
||
export type StorageConnectionType = ConnectionType.Azure | ConnectionType.Emulator; | ||
export type DTSConnectionType = ConnectionType; | ||
export type EventHubsConnectionType = ConnectionType.Azure | ConnectionType.Emulator; | ||
export type SqlDbConnectionType = ConnectionType.Azure | ConnectionType.Custom; | ||
|
||
export interface IConnectionTypesContext { | ||
azureWebJobsStorageType?: StorageConnectionType; | ||
dtsConnectionType?: DTSConnectionType; | ||
eventHubsConnectionType?: EventHubsConnectionType; | ||
sqlDbConnectionType?: SqlDbConnectionType; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ands/appSettings/connectionSettings/durableTaskScheduler/DTSConnectionCustomPromptStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, validationUtils } from '@microsoft/vscode-azext-utils'; | ||
import { ConnectionType } from '../../../../constants'; | ||
import { localize } from '../../../../localize'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSConnectionCustomPromptStep<T extends IDTSConnectionWizardContext> extends AzureWizardPromptStep<T> { | ||
public async prompt(context: T): Promise<void> { | ||
context.newDTSConnection = (await context.ui.showInputBox({ | ||
prompt: localize('customDTSConnectionPrompt', 'Provide a custom DTS connection string.'), | ||
validateInput: (value: string | undefined) => this.validateInput(value) | ||
})).trim(); | ||
} | ||
|
||
public shouldPrompt(context: T): boolean { | ||
return !context.newDTSConnection && context.dtsConnectionType === ConnectionType.Custom; | ||
} | ||
|
||
private validateInput(name: string | undefined): string | undefined { | ||
name = name ? name.trim() : ''; | ||
if (!validationUtils.hasValidCharLength(name)) { | ||
return validationUtils.getInvalidCharLengthMessage(); | ||
} | ||
return undefined; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...mmands/appSettings/connectionSettings/durableTaskScheduler/DTSConnectionSetSettingStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { nonNullProp } from '@microsoft/vscode-azext-utils'; | ||
import { ConnectionKey } from '../../../../constants'; | ||
import { SetConnectionSettingStepBase } from '../SetConnectionSettingStepBase'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSConnectionSetSettingStep<T extends IDTSConnectionWizardContext> extends SetConnectionSettingStepBase<T> { | ||
public priority: number = 240; | ||
public debugDeploySetting: ConnectionKey = ConnectionKey.DTS; | ||
|
||
public async execute(context: T): Promise<void> { | ||
await this.setConnectionSetting(context, nonNullProp(context, 'newDTSConnection')); | ||
} | ||
|
||
public shouldExecute(context: T): boolean { | ||
return !!context.newDTSConnection; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...commands/appSettings/connectionSettings/durableTaskScheduler/DTSConnectionTypeListStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, type AzureWizardExecuteStep, type IWizardOptions } from '@microsoft/vscode-azext-utils'; | ||
import { type MessageItem } from 'vscode'; | ||
import { ConnectionType } from '../../../../constants'; | ||
import { useEmulator } from '../../../../constants-nls'; | ||
import { localize } from '../../../../localize'; | ||
import { DTSConnectionCustomPromptStep } from './DTSConnectionCustomPromptStep'; | ||
import { DTSConnectionSetSettingStep } from './DTSConnectionSetSettingStep'; | ||
import { DTSEmulatorStartStep } from './DTSEmulatorStartStep'; | ||
import { DTSHubNameCustomPromptStep } from './DTSHubNameCustomPromptStep'; | ||
import { DTSHubNameSetSettingStep } from './DTSHubNameSetSettingStep'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSConnectionTypeListStep<T extends IDTSConnectionWizardContext> extends AzureWizardPromptStep<T> { | ||
constructor(readonly connectionTypes: Set<ConnectionType>) { | ||
super(); | ||
} | ||
|
||
public async prompt(context: T): Promise<void> { | ||
const connectAzureButton = { title: localize('connectAzureTaskScheduler', 'Connect Azure Task Scheduler'), data: ConnectionType.Azure }; | ||
const connectEmulatorButton = { title: useEmulator, data: ConnectionType.Emulator }; | ||
const connectCustomDTSButton = { title: localize('connectCustomTaskScheduler', 'Connect Custom Task Scheduler'), data: ConnectionType.Custom }; | ||
|
||
const buttons: MessageItem[] = []; | ||
if (this.connectionTypes.has(ConnectionType.Azure)) { | ||
buttons.push(connectAzureButton); | ||
} | ||
if (this.connectionTypes.has(ConnectionType.Emulator)) { | ||
buttons.push(connectEmulatorButton); | ||
} | ||
if (this.connectionTypes.has(ConnectionType.Custom)) { | ||
buttons.push(connectCustomDTSButton); | ||
} | ||
|
||
const message: string = localize('selectDTSConnection', 'In order to proceed, you must connect a Durable Task Scheduler for internal use by the Azure Functions runtime.'); | ||
context.dtsConnectionType = (await context.ui.showWarningMessage(message, { modal: true }, ...buttons) as { | ||
title: string; | ||
data: ConnectionType; | ||
}).data; | ||
|
||
context.telemetry.properties.dtsConnectionType = context.dtsConnectionType; | ||
} | ||
|
||
public shouldPrompt(context: T): boolean { | ||
return !context.dtsConnectionType; | ||
} | ||
|
||
public async getSubWizard(context: T): Promise<IWizardOptions<T> | undefined> { | ||
const promptSteps: AzureWizardPromptStep<T>[] = []; | ||
const executeSteps: AzureWizardExecuteStep<T>[] = []; | ||
|
||
switch (context.dtsConnectionType) { | ||
case ConnectionType.Azure: | ||
throw new Error('Needs implementation.'); | ||
case ConnectionType.Emulator: | ||
executeSteps.push(new DTSEmulatorStartStep()); | ||
break; | ||
case ConnectionType.Custom: | ||
promptSteps.push( | ||
new DTSConnectionCustomPromptStep(), | ||
new DTSHubNameCustomPromptStep(), | ||
); | ||
break; | ||
} | ||
|
||
executeSteps.push( | ||
new DTSConnectionSetSettingStep(), | ||
new DTSHubNameSetSettingStep(), | ||
); | ||
|
||
return { promptSteps, executeSteps }; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/commands/appSettings/connectionSettings/durableTaskScheduler/DTSEmulatorStartStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardExecuteStep, nonNullValue } from '@microsoft/vscode-azext-utils'; | ||
import { commands } from 'vscode'; | ||
import { ConnectionType } from '../../../../constants'; | ||
import { localize } from '../../../../localize'; | ||
import { type DurableTaskSchedulerEmulator } from '../../../../tree/durableTaskScheduler/DurableTaskSchedulerEmulatorClient'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSEmulatorStartStep<T extends IDTSConnectionWizardContext> extends AzureWizardExecuteStep<T> { | ||
public priority: number = 200; | ||
|
||
public async execute(context: T): Promise<void> { | ||
const emulatorId: string = nonNullValue( | ||
await commands.executeCommand('azureFunctions.durableTaskScheduler.startEmulator'), | ||
localize('failedToStartEmulator', 'Internal error: Failed to start DTS emulator.'), | ||
); | ||
|
||
const emulators: DurableTaskSchedulerEmulator[] = nonNullValue( | ||
await commands.executeCommand('azureFunctions.durableTaskScheduler.getEmulators'), | ||
localize('failedToGetEmulators', 'Internal error: Failed to retrieve the list of DTS emulators.'), | ||
); | ||
|
||
const emulator: DurableTaskSchedulerEmulator = nonNullValue( | ||
emulators.find(e => e.id === emulatorId), | ||
localize('couldNotFindEmulator', 'Internal error: Failed to retrieve info on the started DTS emulator.'), | ||
); | ||
|
||
context.newDTSConnection = `Endpoint=${emulator.schedulerEndpoint};Authentication=None`; | ||
context.newDTSHubName = 'default'; | ||
} | ||
|
||
public shouldExecute(context: T): boolean { | ||
return !context.newDTSConnection && context.dtsConnectionType === ConnectionType.Emulator; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ommands/appSettings/connectionSettings/durableTaskScheduler/DTSHubNameCustomPromptStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, validationUtils, type IActionContext } from '@microsoft/vscode-azext-utils'; | ||
import * as path from 'path'; | ||
import { ConnectionKey, ConnectionType, localSettingsFileName } from '../../../../constants'; | ||
import { getLocalSettingsJson } from '../../../../funcConfig/local.settings'; | ||
import { localize } from '../../../../localize'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSHubNameCustomPromptStep<T extends IDTSConnectionWizardContext> extends AzureWizardPromptStep<T> { | ||
public async prompt(context: T): Promise<void> { | ||
context.newDTSHubName = (await context.ui.showInputBox({ | ||
prompt: localize('customDTSConnectionPrompt', 'Provide the custom DTS hub name.'), | ||
value: await getDTSHubName(context, context.projectPath), | ||
validateInput: (value: string) => this.validateInput(value) | ||
})).trim(); | ||
} | ||
|
||
public shouldPrompt(context: T): boolean { | ||
return !context.newDTSHubName && context.dtsConnectionType === ConnectionType.Custom; | ||
} | ||
|
||
private validateInput(name: string): string | undefined { | ||
name = name.trim(); | ||
|
||
if (!validationUtils.hasValidCharLength(name)) { | ||
return validationUtils.getInvalidCharLengthMessage(); | ||
} | ||
return undefined; | ||
} | ||
} | ||
|
||
async function getDTSHubName(context: IActionContext, projectPath: string): Promise<string | undefined> { | ||
const localSettingsJson = await getLocalSettingsJson(context, path.join(projectPath, localSettingsFileName)); | ||
return localSettingsJson.Values?.[ConnectionKey.DTSHub]; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/commands/appSettings/connectionSettings/durableTaskScheduler/DTSHubNameSetSettingStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { nonNullProp } from '@microsoft/vscode-azext-utils'; | ||
import { ConnectionKey } from '../../../../constants'; | ||
import { SetConnectionSettingStepBase } from '../SetConnectionSettingStepBase'; | ||
import { type IDTSConnectionWizardContext } from './IDTSConnectionWizardContext'; | ||
|
||
export class DTSHubNameSetSettingStep<T extends IDTSConnectionWizardContext> extends SetConnectionSettingStepBase<T> { | ||
public priority: number = 241; | ||
public debugDeploySetting: ConnectionKey = ConnectionKey.DTSHub; | ||
|
||
public async execute(context: T): Promise<void> { | ||
await this.setConnectionSetting(context, nonNullProp(context, 'newDTSHubName')); | ||
} | ||
|
||
public shouldExecute(context: T): boolean { | ||
return !!context.newDTSHubName; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...mmands/appSettings/connectionSettings/durableTaskScheduler/IDTSConnectionWizardContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type ResourceGroup } from "@azure/arm-resources"; | ||
import { type ConnectionType } from "../../../../constants"; | ||
import { type StorageConnectionType } from "../IConnectionTypesContext"; | ||
import { type ISetConnectionSettingContext } from "../ISetConnectionSettingContext"; | ||
|
||
export interface IDTSConnectionWizardContext extends ISetConnectionSettingContext { | ||
resourceGroup?: ResourceGroup; | ||
|
||
// Connection Types | ||
azureWebJobsStorageType?: StorageConnectionType; | ||
dtsConnectionType?: ConnectionType; | ||
|
||
newDTSConnection?: string; | ||
newDTSHubName?: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how important it is for me to add all these failure messages since
preDebugValidate
will end up swallowing these messages anyway 😆