-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for Durable Task Scheduler resources (#4361)
* Scaffold BDP. Signed-off-by: Phillip Hoff <[email protected]> * Refactor type hierarchy. Signed-off-by: Phillip Hoff <[email protected]> * Sketch retrieval of task hubs. Signed-off-by: Phillip Hoff <[email protected]> * Update task hub icon. Signed-off-by: Phillip Hoff <[email protected]> * Enable "open in portal" command for task hubs. Signed-off-by: Phillip Hoff <[email protected]> * Scaffold "open in dashboard" command. Signed-off-by: Phillip Hoff <[email protected]> * Sketch "open in dashboard" implementation. Signed-off-by: Phillip Hoff <[email protected]> * Move DTS management to separate client type. Signed-off-by: Phillip Hoff <[email protected]> * Support viewing task hub properties. Signed-off-by: Phillip Hoff <[email protected]> * Split apart types. Signed-off-by: Phillip Hoff <[email protected]> * Add file headers. Signed-off-by: Phillip Hoff <[email protected]> * Consolidate client logic and add localizable strings. Signed-off-by: Phillip Hoff <[email protected]> --------- Signed-off-by: Phillip Hoff <[email protected]>
- Loading branch information
1 parent
51fb959
commit 02aeea2
Showing
11 changed files
with
285 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,16 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { openUrl, type IActionContext } from "@microsoft/vscode-azext-utils"; | ||
import { type DurableTaskHubResourceModel } from "../../tree/durableTaskScheduler/DurableTaskHubResourceModel"; | ||
import { localize } from '../../localize'; | ||
|
||
export async function openTaskHubDashboard(_: IActionContext, taskHub: DurableTaskHubResourceModel | undefined): Promise<void> { | ||
if (!taskHub) { | ||
throw new Error(localize('noTaskHubSelectedErrorMessage', 'No task hub was selected.')); | ||
} | ||
|
||
await openUrl(taskHub?.dashboardUrl.toString(/* skipEncoding: */ true)); | ||
} |
This file contains 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 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
65 changes: 65 additions & 0 deletions
65
src/tree/durableTaskScheduler/DurableTaskHubResourceModel.ts
This file contains 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,65 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type AzureResource, type ViewPropertiesModel } from "@microsoft/vscode-azureresources-api"; | ||
import { type DurableTaskSchedulerModel } from "./DurableTaskSchedulerModel"; | ||
import { type DurableTaskHubResource, type DurableTaskSchedulerClient } from "./DurableTaskSchedulerClient"; | ||
import { type ProviderResult, TreeItem, Uri } from "vscode"; | ||
import { treeUtils } from "../../utils/treeUtils"; | ||
import { localize } from '../../localize'; | ||
|
||
export class DurableTaskHubResourceModel implements DurableTaskSchedulerModel { | ||
constructor( | ||
private readonly schedulerResource: AzureResource, | ||
private readonly resource: DurableTaskHubResource, | ||
private readonly schedulerClient: DurableTaskSchedulerClient) { | ||
} | ||
|
||
public get azureResourceId() { return this.resource.id; } | ||
|
||
get dashboardUrl(): Uri { return Uri.parse(this.resource.properties.dashboardUrl); } | ||
|
||
get id(): string { return this.resource.id; } | ||
|
||
get portalUrl(): Uri { | ||
const url: string = `${this.schedulerResource.subscription.environment.portalUrl}/#@${this.schedulerResource.subscription.tenantId}/resource${this.id}`; | ||
|
||
return Uri.parse(url); | ||
} | ||
|
||
get viewProperties(): ViewPropertiesModel { | ||
return { | ||
label: this.resource.name, | ||
getData: async () => { | ||
if (!this.schedulerResource.resourceGroup) { | ||
throw new Error(localize('noResourceGroupErrorMessage', 'Azure resource does not have a valid resource group name.')); | ||
} | ||
|
||
const json = await this.schedulerClient.getSchedulerTaskHub( | ||
this.schedulerResource.subscription, | ||
this.schedulerResource.resourceGroup, | ||
this.schedulerResource.name, | ||
this.resource.name); | ||
|
||
return json; | ||
} | ||
}; | ||
} | ||
|
||
getChildren(): ProviderResult<DurableTaskSchedulerModel[]> | ||
{ | ||
return []; | ||
} | ||
|
||
getTreeItem(): TreeItem | Thenable<TreeItem> | ||
{ | ||
const treeItem = new TreeItem(this.resource.name) | ||
|
||
treeItem.iconPath = treeUtils.getIconPath('durableTaskScheduler/DurableTaskScheduler'); | ||
treeItem.contextValue = 'azFunc.dts.taskHub'; | ||
|
||
return treeItem; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/tree/durableTaskScheduler/DurableTaskSchedulerClient.ts
This file contains 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,69 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type AzureAuthentication, type AzureSubscription } from "@microsoft/vscode-azureresources-api"; | ||
import { localize } from '../../localize'; | ||
|
||
export interface DurableTaskHubResource { | ||
readonly id: string; | ||
readonly name: string; | ||
readonly properties: { | ||
readonly dashboardUrl: string; | ||
}; | ||
} | ||
|
||
export interface DurableTaskSchedulerClient { | ||
getSchedulerTaskHub(subscription: AzureSubscription, resourceGroupName: string, schedulerName: string, taskHubName: string): Promise<DurableTaskHubResource>; | ||
getSchedulerTaskHubs(subscription: AzureSubscription, resourceGroupName: string, schedulerName: string): Promise<DurableTaskHubResource[]>; | ||
} | ||
|
||
export class HttpDurableTaskSchedulerClient implements DurableTaskSchedulerClient { | ||
async getSchedulerTaskHub(subscription: AzureSubscription, resourceGroupName: string, schedulerName: string, taskHubName: string): Promise<DurableTaskHubResource> { | ||
const taskHubsUrl = `${HttpDurableTaskSchedulerClient.getBaseUrl(subscription, resourceGroupName, schedulerName)}/taskHubs/${taskHubName}`; | ||
|
||
const taskHub = await this.getAsJson<DurableTaskHubResource>(taskHubsUrl, subscription.authentication); | ||
|
||
return taskHub; | ||
} | ||
|
||
async getSchedulerTaskHubs(subscription: AzureSubscription, resourceGroupName: string, schedulerName: string): Promise<DurableTaskHubResource[]> { | ||
const taskHubsUrl = `${HttpDurableTaskSchedulerClient.getBaseUrl(subscription, resourceGroupName, schedulerName)}/taskHubs`; | ||
|
||
const response = await this.getAsJson<{ value: DurableTaskHubResource[] }>(taskHubsUrl, subscription.authentication); | ||
|
||
return response.value; | ||
} | ||
|
||
private static getBaseUrl(subscription: AzureSubscription, resourceGroupName: string, schedulerName: string) { | ||
const provider = 'Microsoft.DurableTask'; | ||
|
||
return `${subscription.environment.resourceManagerEndpointUrl}/subscriptions/${subscription.subscriptionId}/resourceGroups/${resourceGroupName}/providers/${provider}/schedulers/${schedulerName}`; | ||
} | ||
|
||
private async getAsJson<T>(url: string, authentication: AzureAuthentication): Promise<T> { | ||
const apiVersion = '2024-10-01-preview'; | ||
const versionedUrl = `${url}?api-version=${apiVersion}`; | ||
|
||
const authSession = await authentication.getSession(); | ||
|
||
if (!authSession) { | ||
throw new Error(localize('noAuthenticationSessionErrorMessage', 'Unable to obtain an authentication session.')); | ||
} | ||
|
||
const accessToken = authSession.accessToken; | ||
|
||
const request = new Request(versionedUrl); | ||
|
||
request.headers.append('Authorization', `Bearer ${accessToken}`); | ||
|
||
const response = await fetch(request); | ||
|
||
if (!response.ok) { | ||
throw new Error(localize('failureInvokingArmErrorMessage', 'Azure management API returned an unsuccessful response.')); | ||
} | ||
|
||
return await response.json() as T; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/tree/durableTaskScheduler/DurableTaskSchedulerDataBranchProvider.ts
This file contains 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,27 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type AzureResource, type AzureResourceBranchDataProvider } from "@microsoft/vscode-azureresources-api"; | ||
import { type ProviderResult, type TreeItem } from "vscode"; | ||
import { type DurableTaskSchedulerClient } from "./DurableTaskSchedulerClient"; | ||
import { type DurableTaskSchedulerModel } from "./DurableTaskSchedulerModel"; | ||
import { DurableTaskSchedulerResourceModel } from "./DurableTaskSchedulerResourceModel"; | ||
|
||
export class DurableTaskSchedulerDataBranchProvider implements AzureResourceBranchDataProvider<DurableTaskSchedulerModel> { | ||
constructor(private readonly schedulerClient: DurableTaskSchedulerClient) { | ||
} | ||
|
||
getChildren(element: DurableTaskSchedulerModel): ProviderResult<DurableTaskSchedulerModel[]> { | ||
return element.getChildren(); | ||
} | ||
|
||
getResourceItem(element: AzureResource): DurableTaskSchedulerResourceModel | Thenable<DurableTaskSchedulerResourceModel> { | ||
return new DurableTaskSchedulerResourceModel(element, this.schedulerClient); | ||
} | ||
|
||
getTreeItem(element: DurableTaskSchedulerModel): TreeItem | Thenable<TreeItem> { | ||
return element.getTreeItem(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/tree/durableTaskScheduler/DurableTaskSchedulerModel.ts
This file contains 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,13 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type AzureResourceModel } from "@microsoft/vscode-azureresources-api"; | ||
import { type ProviderResult, type TreeItem } from "vscode"; | ||
|
||
export interface DurableTaskSchedulerModel extends AzureResourceModel { | ||
getChildren(): ProviderResult<DurableTaskSchedulerModel[]>; | ||
|
||
getTreeItem(): TreeItem | Thenable<TreeItem>; | ||
} |
Oops, something went wrong.