|
5 | 5 |
|
6 | 6 | import { ContainerAppsAPIClient } from "@azure/arm-appcontainers"; |
7 | 7 | import { getResourceGroupFromId, LocationListStep } from "@microsoft/vscode-azext-azureutils"; |
8 | | -import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils"; |
| 8 | +import { GenericTreeItem } from "@microsoft/vscode-azext-utils"; |
9 | 9 | import { Progress } from "vscode"; |
10 | | -import { managedEnvironmentsAppProvider } from "../../constants"; |
11 | | -import { ext } from "../../extensionVariables"; |
| 10 | +import { activityFailContext, activityFailIcon, activitySuccessContext, activitySuccessIcon, managedEnvironmentsAppProvider } from "../../constants"; |
| 11 | +import { createActivityChildContext } from "../../utils/activity/activityUtils"; |
| 12 | +import { ExecuteActivityOutput, ExecuteActivityOutputStepBase } from "../../utils/activity/ExecuteActivityOutputStepBase"; |
12 | 13 | import { createContainerAppsAPIClient, createOperationalInsightsManagementClient } from '../../utils/azureClients'; |
13 | 14 | import { localize } from "../../utils/localize"; |
14 | 15 | import { nonNullProp, nonNullValueAndProp } from "../../utils/nonNull"; |
15 | 16 | import { IManagedEnvironmentContext } from "./IManagedEnvironmentContext"; |
16 | 17 |
|
17 | | -export class ManagedEnvironmentCreateStep extends AzureWizardExecuteStep<IManagedEnvironmentContext> { |
| 18 | +export class ManagedEnvironmentCreateStep extends ExecuteActivityOutputStepBase<IManagedEnvironmentContext> { |
18 | 19 | public priority: number = 250; |
19 | 20 |
|
20 | | - public async execute(context: IManagedEnvironmentContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> { |
| 21 | + protected async executeCore(context: IManagedEnvironmentContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> { |
21 | 22 | const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context); |
22 | 23 | const opClient = await createOperationalInsightsManagementClient(context); |
23 | | - const rgName = nonNullValueAndProp(context.resourceGroup, 'name'); |
| 24 | + |
| 25 | + const resourceGroupName = nonNullValueAndProp(context.resourceGroup, 'name'); |
| 26 | + const managedEnvironmentName = nonNullProp(context, 'newManagedEnvironmentName'); |
24 | 27 | const logAnalyticsWorkspace = nonNullProp(context, 'logAnalyticsWorkspace'); |
25 | 28 |
|
26 | | - const creatingKuEnv: string = localize('creatingManagedEnvironment', 'Creating new Container Apps environment "{0}"...', context.newManagedEnvironmentName); |
27 | | - progress.report({ message: creatingKuEnv }); |
28 | | - ext.outputChannel.appendLog(creatingKuEnv); |
| 29 | + const creating: string = localize('creatingManagedEnvironment', 'Creating environment...'); |
| 30 | + progress.report({ message: creating }); |
29 | 31 |
|
30 | 32 | const sharedKeys = await opClient.sharedKeysOperations.getSharedKeys( |
31 | 33 | getResourceGroupFromId(nonNullProp(logAnalyticsWorkspace, 'id')), |
32 | 34 | nonNullProp(logAnalyticsWorkspace, 'name')); |
33 | 35 |
|
34 | | - context.managedEnvironment = await client.managedEnvironments.beginCreateOrUpdateAndWait(rgName, nonNullProp(context, 'newManagedEnvironmentName'), |
| 36 | + context.managedEnvironment = await client.managedEnvironments.beginCreateOrUpdateAndWait(resourceGroupName, managedEnvironmentName, |
35 | 37 | { |
36 | 38 | location: (await LocationListStep.getLocation(context)).name, |
37 | 39 | appLogsConfiguration: { |
38 | 40 | "destination": "log-analytics", |
39 | 41 | "logAnalyticsConfiguration": { |
40 | | - "customerId": nonNullProp(context, 'logAnalyticsWorkspace').customerId, |
| 42 | + "customerId": logAnalyticsWorkspace.customerId, |
41 | 43 | "sharedKey": sharedKeys.primarySharedKey |
42 | 44 | } |
43 | 45 | } |
44 | 46 | } |
45 | 47 | ); |
46 | 48 |
|
47 | | - context.activityResult = { |
48 | | - id: nonNullProp(context.managedEnvironment, 'id'), |
49 | | - name: nonNullProp(context, 'newManagedEnvironmentName'), |
50 | | - type: managedEnvironmentsAppProvider |
| 49 | + if (!context.activityChildren) { |
| 50 | + context.activityResult = { |
| 51 | + id: nonNullProp(context.managedEnvironment, 'id'), |
| 52 | + name: managedEnvironmentName, |
| 53 | + type: managedEnvironmentsAppProvider |
| 54 | + }; |
51 | 55 | } |
52 | | - |
53 | | - const createdKuEnv: string = localize('createKuEnv', 'Successfully created new Container Apps environment "{0}".', context.newManagedEnvironmentName); |
54 | | - ext.outputChannel.appendLog(createdKuEnv); |
55 | 56 | } |
56 | 57 |
|
57 | 58 | public shouldExecute(context: IManagedEnvironmentContext): boolean { |
58 | 59 | return !context.managedEnvironment; |
59 | 60 | } |
| 61 | + |
| 62 | + protected createSuccessOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput { |
| 63 | + return { |
| 64 | + item: new GenericTreeItem(undefined, { |
| 65 | + contextValue: createActivityChildContext(['managedEnvironmentCreateStep', activitySuccessContext]), |
| 66 | + label: localize('createManagedEnvironment', 'Create container apps environment "{0}"', context.newManagedEnvironmentName), |
| 67 | + iconPath: activitySuccessIcon |
| 68 | + }), |
| 69 | + message: localize('createdManagedEnvironmentSuccess', 'Created container apps environment "{0}".', context.newManagedEnvironmentName) |
| 70 | + }; |
| 71 | + } |
| 72 | + |
| 73 | + protected createFailOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput { |
| 74 | + return { |
| 75 | + item: new GenericTreeItem(undefined, { |
| 76 | + contextValue: createActivityChildContext(['managedEnvironmentCreateStep', activityFailContext]), |
| 77 | + label: localize('createManagedEnvironment', 'Create container apps environment "{0}"', context.newManagedEnvironmentName), |
| 78 | + iconPath: activityFailIcon |
| 79 | + }), |
| 80 | + message: localize('createdManagedEnvironmentFail', 'Failed to create container apps environment "{0}".', context.newManagedEnvironmentName) |
| 81 | + }; |
| 82 | + } |
60 | 83 | } |
0 commit comments