-
Notifications
You must be signed in to change notification settings - Fork 17
Add activity log & draft support to editScaleRange
#466
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,7 @@ Reserved | |
|
|
||
| #### Steps | ||
|
|
||
| - ScaleRangeUpdateStep: 1110 | ||
| - AddScaleRuleStep: 1120 | ||
|
|
||
| ### 10. Unallocated Space | ||
|
|
||
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 was deleted.
Oops, something went wrong.
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,15 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import type { ExecuteActivityContext } from "@microsoft/vscode-azext-utils"; | ||
| import type { IContainerAppContext } from "../../IContainerAppContext"; | ||
|
|
||
| export interface ScaleRangeContext extends IContainerAppContext, ExecuteActivityContext { | ||
| newMinRange?: number; | ||
| newMaxRange?: number; | ||
|
|
||
| scaleMinRange: number; | ||
| scaleMaxRange: number; | ||
| } |
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,44 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils'; | ||
| import { localize } from '../../../utils/localize'; | ||
| import type { ScaleRangeContext } from './ScaleRangeContext'; | ||
|
|
||
| export class ScaleRangePromptStep extends AzureWizardPromptStep<ScaleRangeContext> { | ||
| public async prompt(context: ScaleRangeContext): Promise<void> { | ||
| const scaleRange: string = (await context.ui.showInputBox({ | ||
| prompt: localize('editScalingRange', 'Set the range of application replicas that get created in response to a scale rule. Set any range within the minimum of 0 and the maximum of 10 replicas'), | ||
| value: `${context.scaleMinRange}-${context.scaleMaxRange}`, | ||
| validateInput: this.validateInput, | ||
| })).trim(); | ||
|
|
||
| const [min, max] = scaleRange.split('-').map(range => Number(range)); | ||
| context.newMinRange = min; | ||
| context.newMaxRange = max; | ||
| } | ||
|
|
||
| public shouldPrompt(context: ScaleRangeContext): boolean { | ||
| return !context.newMinRange || !context.newMaxRange; | ||
| } | ||
|
|
||
| private validateInput(range: string | undefined): string | undefined { | ||
| const formatRegex = /^\d{1,2}-\d{1,2}$/; | ||
| if (!range || !formatRegex.test(range)) { | ||
| return localize('enterRange', 'Please enter the range in the following format "0-10"'); | ||
| } | ||
|
|
||
| const [min, max] = range.split('-').map(range => Number(range)); | ||
| if (min > 10 || max > 10) { | ||
| return localize('maxRangeExceeded', 'The maximum number of replicas is 10.'); | ||
| } else if (min > max) { | ||
| return localize('minHigherThanMax', 'The minimum range cannot be larger than the maximum range.'); | ||
| } else if (max === 0) { | ||
| return localize('maxGreaterThan0', 'The maximum replicas must be greater than 0.'); | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
| } |
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,40 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * 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 { ext } from "../../../extensionVariables"; | ||
| import type { RevisionsItemModel } from "../../../tree/revisionManagement/RevisionItem"; | ||
| import { localize } from "../../../utils/localize"; | ||
| import { getParentResourceFromItem } from "../../../utils/revisionDraftUtils"; | ||
| import { RevisionDraftUpdateBaseStep } from "../../revisionDraft/RevisionDraftUpdateBaseStep"; | ||
| import type { ScaleRangeContext } from "./ScaleRangeContext"; | ||
|
|
||
| export class ScaleRangeUpdateStep<T extends ScaleRangeContext> extends RevisionDraftUpdateBaseStep<T> { | ||
| public priority: number = 1110; | ||
|
|
||
| constructor(baseItem: RevisionsItemModel) { | ||
| super(baseItem); | ||
| } | ||
|
|
||
| public async execute(context: ScaleRangeContext): Promise<void> { | ||
| this.revisionDraftTemplate.scale ||= {}; | ||
| this.revisionDraftTemplate.scale.minReplicas = context.newMinRange; | ||
| this.revisionDraftTemplate.scale.maxReplicas = context.newMaxRange; | ||
|
|
||
| this.updateRevisionDraftWithTemplate(); | ||
|
|
||
| context.scaleMinRange = nonNullProp(context, 'newMinRange'); | ||
| context.scaleMaxRange = nonNullProp(context, 'newMaxRange'); | ||
|
|
||
| const parentResourceName = getParentResourceFromItem(this.baseItem).name; | ||
| ext.outputChannel.appendLog(localize('updatedScaleRange', 'Updated replica scaling range to {0}-{1} for "{2}".', context.newMinRange, context.newMaxRange, parentResourceName)); | ||
| } | ||
|
|
||
| public shouldExecute(context: ScaleRangeContext): boolean { | ||
| return context.newMinRange !== undefined && context.newMaxRange !== undefined; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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,45 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import type { Revision, Scale } from "@azure/arm-appcontainers"; | ||
| import { AzureWizard, IActionContext, createSubscriptionContext, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; | ||
| import type { ContainerAppModel } from "../../../tree/ContainerAppItem"; | ||
| import type { ScaleItem } from "../../../tree/scaling/ScaleItem"; | ||
| import { createActivityContext } from "../../../utils/activityUtils"; | ||
| import { localize } from "../../../utils/localize"; | ||
| import { pickScale } from "../../../utils/pickItem/pickScale"; | ||
| import { getParentResource } from "../../../utils/revisionDraftUtils"; | ||
| import type { ScaleRangeContext } from "./ScaleRangeContext"; | ||
| import { ScaleRangePromptStep } from "./ScaleRangePromptStep"; | ||
| import { ScaleRangeUpdateStep } from "./ScaleRangeUpdateStep"; | ||
|
|
||
| export async function editScaleRange(context: IActionContext, node?: ScaleItem): Promise<void> { | ||
| const item: ScaleItem = node ?? await pickScale(context, { autoSelectDraft: true }); | ||
| const { containerApp, revision, subscription } = item; | ||
|
|
||
| const parentResource: ContainerAppModel | Revision = getParentResource(containerApp, revision); | ||
| const scale: Scale = nonNullValueAndProp(parentResource.template, 'scale'); | ||
|
|
||
| const wizardContext: ScaleRangeContext = { | ||
| ...context, | ||
| ...createSubscriptionContext(subscription), | ||
| ...await createActivityContext(), | ||
| containerApp, | ||
| subscription, | ||
| scaleMinRange: scale.minReplicas ?? 0, | ||
| scaleMaxRange: scale.maxReplicas ?? 0 | ||
| }; | ||
|
|
||
| const wizard: AzureWizard<ScaleRangeContext> = new AzureWizard(wizardContext, { | ||
| title: localize('editScaleRangePre', 'Update replica scaling range for "{0}" (draft)', parentResource.name), | ||
| promptSteps: [new ScaleRangePromptStep()], | ||
| executeSteps: [new ScaleRangeUpdateStep(item)], | ||
| showLoadingPrompt: true | ||
| }); | ||
|
|
||
| await wizard.prompt(); | ||
| wizardContext.activityTitle = localize('editScaleRange', 'Update replica scaling range to "{0}-{1}" for "{2}" (draft)', wizardContext.newMinRange, wizardContext.newMaxRange, parentResource.name); | ||
| await wizard.execute(); | ||
| } |
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
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.
nit: excessive breaks