-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathLogAnalyticsCreateStep.ts
More file actions
56 lines (48 loc) · 3.33 KB
/
LogAnalyticsCreateStep.ts
File metadata and controls
56 lines (48 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { GenericTreeItem, activityFailContext, activityFailIcon, activitySuccessContext, activitySuccessIcon } from "@microsoft/vscode-azext-utils";
import { type Progress } from "vscode";
import { ExecuteActivityOutputStepBase, type ExecuteActivityOutput } from "../../utils/activity/ExecuteActivityOutputStepBase";
import { createActivityChildContext } from "../../utils/activity/activityUtils";
import { createOperationalInsightsManagementClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { nonNullProp } from "../../utils/nonNull";
import { type IManagedEnvironmentContext } from "./IManagedEnvironmentContext";
export class LogAnalyticsCreateStep extends ExecuteActivityOutputStepBase<IManagedEnvironmentContext> {
public priority: number = 220;
protected async executeCore(context: IManagedEnvironmentContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const opClient = await createOperationalInsightsManagementClient(context);
const resourceGroup = nonNullProp(context, 'resourceGroup');
const workspaceName = nonNullProp(context, 'newManagedEnvironmentName');
const creating: string = localize('creatingLogAnalyticsWorkspace', 'Creating log analytics workspace...');
progress.report({ message: creating });
context.logAnalyticsWorkspace = await opClient.workspaces.beginCreateOrUpdateAndWait(
nonNullProp(resourceGroup, 'name'), workspaceName, { location: (await LocationListStep.getLocation(context)).name });
}
public shouldExecute(context: IManagedEnvironmentContext): boolean {
return !context.logAnalyticsWorkspace;
}
protected createSuccessOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['logAnalyticsCreateStep', activitySuccessContext]),
label: localize('createWorkspace', 'Create log analytics workspace "{0}"', context.newManagedEnvironmentName),
iconPath: activitySuccessIcon
}),
message: localize('createLogAnalyticsWorkspaceSuccess', 'Created log analytics workspace "{0}".', context.newManagedEnvironmentName)
};
}
protected createFailOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['logAnalyticsCreateStep', activityFailContext]),
label: localize('createWorkspace', 'Create log analytics workspace "{0}"', context.newManagedEnvironmentName),
iconPath: activityFailIcon
}),
message: localize('createLogAnalyticsWorkspaceFail', 'Failed to create log analytics workspace "{0}".', context.newManagedEnvironmentName)
};
}
}