From 6078e9f4591d49630082fdd0fafe577741d05739 Mon Sep 17 00:00:00 2001 From: nasc17 <69922333+nasc17@users.noreply.github.com> Date: Wed, 7 Jul 2021 12:25:07 -0700 Subject: [PATCH] Make it so user cannot create or scale PG server group to 1 worker node (#16005) * Added not equals validation * Added validation to worker node in deploy * Fixed info * Change string * Change string * Change string --- extensions/arc/package.json | 5 +++++ extensions/arc/package.nls.json | 1 + extensions/arc/src/localizedConstants.ts | 3 ++- .../postgres/postgresComputeAndStoragePage.ts | 8 +++++++- .../src/ui/validation/validations.ts | 12 +++++++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/extensions/arc/package.json b/extensions/arc/package.json index eedaec3c86..7c7219ba71 100644 --- a/extensions/arc/package.json +++ b/extensions/arc/package.json @@ -615,6 +615,11 @@ { "type": "is_integer", "description": "%should.be.integer%" + }, + { + "type": "!=", + "target": "1", + "description": "%worker.node.count.should.not.be.one%" } ], "defaultValue": "2", diff --git a/extensions/arc/package.nls.json b/extensions/arc/package.nls.json index 14067db4d0..dda62decce 100644 --- a/extensions/arc/package.nls.json +++ b/extensions/arc/package.nls.json @@ -148,6 +148,7 @@ "arc.agreement.sql.terms.conditions": "Azure SQL managed instance - Azure Arc terms and conditions", "arc.agreement.postgres.terms.conditions": "Azure Arc-enabled PostgreSQL Hyperscale terms and conditions", "should.be.integer": "Value must be an integer", + "worker.node.count.should.not.be.one": "Value of 1 is not supported.", "requested.cores.less.than.or.equal.to.cores.limit": "Requested cores must be less than or equal to cores limit", "cores.limit.greater.than.or.equal.to.requested.cores": "Cores limit must be greater than or equal to requested cores", "requested.memory.less.than.or.equal.to.memory.limit": "Requested memory must be less than or equal to memory limit", diff --git a/extensions/arc/src/localizedConstants.ts b/extensions/arc/src/localizedConstants.ts index f26e5a670a..6e189962c0 100644 --- a/extensions/arc/src/localizedConstants.ts +++ b/extensions/arc/src/localizedConstants.ts @@ -83,7 +83,8 @@ export const addingWorkerNodes = localize('arc.addingWorkerNodes', "adding worke export const workerNodesDescription = localize('arc.workerNodesDescription', "Expand your server group and scale your database by adding worker nodes."); export const workerNodesConfigurationInformation = localize('arc.workerNodesConfigurationInformation', "You can configure the number of CPU cores and storage size that will apply to all worker nodes. Adjust the number of CPU cores and memory settings for your server group. To reset the requests and/or limits, pass in empty value."); export const coordinatorNodeConfigurationInformation = localize('arc.coordinatorNodeConfigurationInformation', "You can configure the number of CPU cores and storage size that will apply to the coordinator node. Adjust the number of CPU cores and memory settings for your server group. To reset the requests and/or limits, pass in empty value."); -export const workerNodesInformation = localize('arc.workerNodeInformation', "It is possible to scale in and out your server group by reducing or increasing the number of worker nodes."); +export const workerNodesInformation = localize('arc.workerNodeInformation', "It is possible to scale in and out your server group by reducing or increasing the number of worker nodes. The value must be 0 or greater than 1."); +export const workerOneNodeValidationMessage = localize('arc.workerOneNodeValidationMessage', "Value of 1 is not supported."); export const vCores = localize('arc.vCores', "vCores"); export const ram = localize('arc.ram', "RAM"); export const refresh = localize('arc.refresh', "Refresh"); diff --git a/extensions/arc/src/ui/dashboards/postgres/postgresComputeAndStoragePage.ts b/extensions/arc/src/ui/dashboards/postgres/postgresComputeAndStoragePage.ts index 25e98c239d..1d4b81032c 100644 --- a/extensions/arc/src/ui/dashboards/postgres/postgresComputeAndStoragePage.ts +++ b/extensions/arc/src/ui/dashboards/postgres/postgresComputeAndStoragePage.ts @@ -248,7 +248,13 @@ export class PostgresComputeAndStoragePage extends DashboardPage { inputType: 'number', placeHolder: loc.loading, required: true, - ariaLabel: loc.workerNodeCount + ariaLabel: loc.workerNodeCount, + validationErrorMessage: loc.workerOneNodeValidationMessage + }).withValidation((component) => { + if (component.value === '1') { + return false; + } + return true; }).component(); this.disposables.push( diff --git a/extensions/resource-deployment/src/ui/validation/validations.ts b/extensions/resource-deployment/src/ui/validation/validations.ts index a0965f984f..ccf0481130 100644 --- a/extensions/resource-deployment/src/ui/validation/validations.ts +++ b/extensions/resource-deployment/src/ui/validation/validations.ts @@ -25,7 +25,8 @@ export const enum ValidationType { IsInteger = 'is_integer', Regex = 'regex_match', LessThanOrEqualsTo = '<=', - GreaterThanOrEqualsTo = '>=' + GreaterThanOrEqualsTo = '>=', + NotEqualTo = '!=' } export type ValidationInfo = RegexValidationInfo | IntegerValidationInfo | ComparisonValidationInfo; @@ -175,12 +176,21 @@ export class GreaterThanOrEqualsValidation extends Comparison { } } +export class NotEqualValidation extends Comparison { + async isComparisonSuccessful() { + const value = (await this.getValue()); + const targetValue = this.target; + return (isUndefinedOrEmpty(value) || isUndefinedOrEmpty(targetValue)) ? true : value!.toString() !== targetValue!; + } +} + export function createValidation(validation: ValidationInfo, valueGetter: ValueGetter, targetValueGetter?: TargetValueGetter, onTargetValidityChangedGetter?: OnTargetValidityChangedGetter, onDisposableCreated?: (disposable: vscode.Disposable) => void): Validation { switch (validation.type) { case ValidationType.Regex: return new RegexValidation(validation, valueGetter); case ValidationType.IsInteger: return new IntegerValidation(validation, valueGetter); case ValidationType.LessThanOrEqualsTo: return new LessThanOrEqualsValidation(validation, valueGetter, targetValueGetter!, onTargetValidityChangedGetter!, onDisposableCreated!); case ValidationType.GreaterThanOrEqualsTo: return new GreaterThanOrEqualsValidation(validation, valueGetter, targetValueGetter!, onTargetValidityChangedGetter!, onDisposableCreated!); + case ValidationType.NotEqualTo: return new NotEqualValidation(validation, valueGetter, targetValueGetter!, onTargetValidityChangedGetter!, onDisposableCreated!); default: throw new Error(`unknown validation type:${validation.type}`); //dev error } }