Skip to content

Commit 87d0440

Browse files
author
Nemanja
committed
Removing SKU name
1 parent e221055 commit 87d0440

File tree

7 files changed

+49
-173
lines changed

7 files changed

+49
-173
lines changed

src/Sql/Sql.Test/ScenarioTests/ManagedInstanceCrudScenarioTests.ps1

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,40 +190,35 @@ function Test-SetManagedInstance
190190
Assert-AreEqual $managedInstance4.ProxyOverride $proxyOverride
191191
Assert-StartsWith ($managedInstance4.ManagedInstanceName + ".") $managedInstance4.FullyQualifiedDomainName
192192

193-
# Test hardware generation change using SkuName
193+
# Test hardware generation change using ComputeGeneration
194194
$credentials = Get-ServerCredential
195-
$skuName = "GP_Gen5"
195+
$computeGeneration = "Gen5"
196196

197197
$managedInstance5 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
198-
-SkuName $skuName -Force
198+
-ComputeGeneration $computeGeneration -Force
199199

200200
Assert-AreEqual $managedInstance5.ManagedInstanceName $managedInstance.ManagedInstanceName
201201
Assert-AreEqual $managedInstance5.AdministratorLogin $managedInstance.AdministratorLogin
202202
Assert-AreEqual $managedInstance5.VCores $managedInstance4.VCores
203203
Assert-AreEqual $managedInstance5.StorageSizeInGB $managedInstance4.StorageSizeInGB
204-
Assert-AreEqual $managedInstance5.Sku.Name $skuName
204+
Assert-AreEqual $managedInstance5.Sku.Tier $managedInstance4.Sku.Tier
205+
Assert-AreEqual $managedInstance5.Sku.Family $computeGeneration
205206
Assert-StartsWith ($managedInstance5.ManagedInstanceName + ".") $managedInstance5.FullyQualifiedDomainName
206207

207-
# Drop test instance becuase its hardware generation cannot be changed to Gen4.
208-
Remove-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName -Force
209-
210-
# Create new managed instance on Gen4 hardware
211-
$managedInstance6 = Create-ManagedInstanceForTest $rg $subnetId
212-
213-
# Test hardware generation change using ComputeGeneration
208+
# Test edition change using Edition
214209
$credentials = Get-ServerCredential
215-
$skuName = "GP_Gen5"
216-
$computeGeneration = "Gen5"
217-
218-
$managedInstance7 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance6.ManagedInstanceName `
219-
-ComputeGeneration $computeGeneration -Force
220-
221-
Assert-AreEqual $managedInstance7.ManagedInstanceName $managedInstance6.ManagedInstanceName
222-
Assert-AreEqual $managedInstance7.AdministratorLogin $managedInstance6.AdministratorLogin
223-
Assert-AreEqual $managedInstance7.VCores $managedInstance6.VCores
224-
Assert-AreEqual $managedInstance7.StorageSizeInGB $managedInstance6.storageSizeInGB
225-
Assert-AreEqual $managedInstance7.Sku.Name $skuName
226-
Assert-StartsWith ($managedInstance7.ManagedInstanceName + ".") $managedInstance7.FullyQualifiedDomainName
210+
$edition = "BusinessCritical"
211+
212+
$managedInstance6 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
213+
-Edition $edition -Force
214+
215+
Assert-AreEqual $managedInstance6.ManagedInstanceName $managedInstance5.ManagedInstanceName
216+
Assert-AreEqual $managedInstance6.AdministratorLogin $managedInstance5.AdministratorLogin
217+
Assert-AreEqual $managedInstance6.VCores $managedInstance5.VCores
218+
Assert-AreEqual $managedInstance6.StorageSizeInGB $managedInstance5.StorageSizeInGB
219+
Assert-AreEqual $managedInstance6.Sku.Tier $edition
220+
Assert-AreEqual $managedInstance6.Sku.Family $managedInstance5.Sku.Family
221+
Assert-StartsWith ($managedInstance6.ManagedInstanceName + ".") $managedInstance6.FullyQualifiedDomainName
227222
}
228223
finally
229224
{

src/Sql/Sql.Test/UnitTests/AzureSqlInstanceUnitTests.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,5 @@ public void GetInstanceSkuPrefix()
4242
"BC",
4343
AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("BusinessCritical"));
4444
}
45-
46-
[Fact]
47-
[Trait(Category.AcceptanceType, Category.CheckIn)]
48-
public void GetHardwareGenerationFromSkuName()
49-
{
50-
Assert.Equal(
51-
"Gen4",
52-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("GP_Gen4"));
53-
Assert.Equal(
54-
"Gen5",
55-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("GP_Gen5"));
56-
Assert.Equal(
57-
"Gen4",
58-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("BC_Gen4"));
59-
Assert.Equal(
60-
"Gen5",
61-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("BC_Gen5"));
62-
Assert.Equal(
63-
"Gen5_Gen5",
64-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("BC_Gen5_Gen5"));
65-
Assert.Equal(
66-
"",
67-
AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("BC_"));
68-
Assert.Null(AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("GPGen5"));
69-
Assert.Null(AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName("GPGen5"));
70-
Assert.Null(AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName(""));
71-
Assert.Null(AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName(null));
72-
}
7345
}
7446
}

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
188188
[PSArgumentCompleter(Constants.ComputeGenerationGen5)]
189189
public string ComputeGeneration { get; set; }
190190

191-
/// <summary>
192-
/// Gets or sets the instance SKU name
193-
/// </summary>
194-
[Parameter(Mandatory = false,
195-
HelpMessage = "The SKU name for the instance e.g. 'GP_Gen5','BC_Gen5'.")]
196-
[ValidateNotNullOrEmpty]
197-
[PSArgumentCompleter(Constants.GeneralPurposeGen5, Constants.BusinessCriticalGen5)]
198-
public string SkuName { get; set; }
199-
200191
/// <summary>
201192
/// Get the instance to update
202193
/// </summary>
@@ -219,47 +210,18 @@ protected bool ShouldConfirmHardwareFamilyChange()
219210
// Get current hardware family
220211
string currentHardwareFamily = existingInstance.Sku.Family;
221212

222-
// Get requested hardware family
223-
string requestedHardwareFamily = !string.IsNullOrWhiteSpace(this.SkuName) ? AzureSqlManagedInstanceAdapter.GetHardwareGenerationFromSkuName(this.SkuName) : this.ComputeGeneration;
224-
225-
bool isHardwareFamilyChanged = !string.IsNullOrWhiteSpace(requestedHardwareFamily) && !currentHardwareFamily.Equals(requestedHardwareFamily, StringComparison.InvariantCultureIgnoreCase);
213+
// Check whether the hardware family was changed
214+
bool isHardwareFamilyChanged = !currentHardwareFamily.Equals(this.ComputeGeneration, StringComparison.InvariantCultureIgnoreCase);
226215

227-
// Check whether hardware family is being changed to a deprecated hardware family
228-
if (isHardwareFamilyChanged && requestedHardwareFamily.Equals(Constants.ComputeGenerationGen5, StringComparison.InvariantCultureIgnoreCase))
216+
// Check whether hardware family is being changed to a newer hardware family
217+
if (isHardwareFamilyChanged && currentHardwareFamily.Equals(Constants.ComputeGenerationGen4, StringComparison.InvariantCultureIgnoreCase))
229218
{
230219
shouldConfirmHardwareFamilyChange = true;
231220
}
232221

233222
return shouldConfirmHardwareFamilyChange;
234223
}
235224

236-
/// <summary>
237-
/// Get edition from SKU name.
238-
/// </summary>
239-
/// <returns>The model to send to the update</returns>
240-
protected string GetEditionFromSkuName(string skuName)
241-
{
242-
if (string.IsNullOrWhiteSpace(skuName))
243-
{
244-
return null;
245-
}
246-
247-
string edition = null;
248-
249-
if (skuName.Equals(Constants.GeneralPurposeGen4, StringComparison.InvariantCultureIgnoreCase)
250-
|| skuName.Equals(Constants.GeneralPurposeGen5, StringComparison.InvariantCultureIgnoreCase))
251-
{
252-
edition = Constants.GeneralPurposeEdition;
253-
}
254-
else if (skuName.Equals(Constants.BusinessCriticalGen4, StringComparison.InvariantCultureIgnoreCase)
255-
|| skuName.Equals(Constants.BusinessCriticalGen5, StringComparison.InvariantCultureIgnoreCase))
256-
{
257-
edition = Constants.BusinessCriticalEdition;
258-
}
259-
260-
return edition;
261-
}
262-
263225
/// <summary>
264226
/// Constructs the model to send to the update API
265227
/// </summary>
@@ -270,26 +232,21 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
270232
AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);
271233
Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();
272234

273-
// Get current edition
235+
// Get current edition and family
274236
string currentEdition = existingInstance.Sku.Tier;
237+
string currentComputeGeneration = existingInstance.Sku.Family;
275238

276-
// Get current hardware family
277-
string currentComputeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
278-
279-
if (SkuName != null)
280-
{
281-
Sku.Name = SkuName;
282-
}
283-
else if (Edition != null || ComputeGeneration != null)
239+
// If either edition or compute generation are set, get the new sku
240+
if (this.Edition != null || this.ComputeGeneration != null)
284241
{
285-
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? Edition : currentEdition);
286-
Sku.Name = editionShort + "_" + (!string.IsNullOrWhiteSpace(ComputeGeneration) ? ComputeGeneration : currentComputeGeneration);
287-
Sku.Tier = !string.IsNullOrWhiteSpace(Edition) ? Edition : null;
288-
Sku.Family = !string.IsNullOrWhiteSpace(ComputeGeneration) ? ComputeGeneration : currentComputeGeneration;
242+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition);
243+
Sku.Name = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration);
244+
Sku.Tier = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null;
245+
Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration;
289246
}
290247
else
291248
{
292-
Sku = null;
249+
Sku = existingInstance.Sku;
293250
}
294251

295252
// Construct a new entity so we only send the relevant data to the Managed instance
@@ -329,6 +286,7 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> PersistChanges(IEnu
329286
/// </summary>
330287
public override void ExecuteCmdlet()
331288
{
289+
System.Diagnostics.Debugger.Launch();
332290
if (!Force.IsPresent && !ShouldContinue(
333291
string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetAzureSqlInstanceDescription, this.Name),
334292
string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetAzureSqlInstanceWarning, this.Name)))
@@ -350,14 +308,14 @@ public override void ExecuteCmdlet()
350308
}
351309

352310
// Validate requested hardware family
353-
if (!string.IsNullOrWhiteSpace(this.SkuName) || !string.IsNullOrWhiteSpace(this.ComputeGeneration))
311+
if (!string.IsNullOrWhiteSpace(this.ComputeGeneration))
354312
{
355313
// Hardware family is being changed to a newer hardware family and it is not possible to scale back - Give confirmation message
356314
if (this.ShouldConfirmHardwareFamilyChange())
357315
{
358316
if (!Force.IsPresent && !ShouldContinue(
359317
string.Format(CultureInfo.InvariantCulture, Properties.Resources.DoYouWantToProceed, this.Name),
360-
string.Format(CultureInfo.InvariantCulture, Properties.Resources.ChangingHardwareFamilyIsIrreversable, this.Name)))
318+
string.Format(CultureInfo.InvariantCulture, string.Format(Properties.Resources.ChangingHardwareFamilyIsIrreversable, this.ComputeGeneration), this.Name)))
361319
{
362320
return;
363321
}

src/Sql/Sql/ManagedInstance/Services/AzureSqlManagedInstanceAdapter.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,5 @@ public static string GetInstanceSkuPrefix(string tier)
229229

230230
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? "Unknown";
231231
}
232-
233-
/// <summary>
234-
/// Get hardware family from SKU name.
235-
/// </summary>
236-
/// <returns>The model to send to the update</returns>
237-
public static string GetHardwareGenerationFromSkuName(string skuName)
238-
{
239-
if (string.IsNullOrWhiteSpace(skuName))
240-
{
241-
return null;
242-
}
243-
244-
string hardwareFamily = null;
245-
246-
int underscoreIndex = skuName.IndexOf('_');
247-
if (underscoreIndex >= 0)
248-
{
249-
hardwareFamily = skuName.Substring(underscoreIndex + 1);
250-
}
251-
252-
return hardwareFamily;
253-
}
254232
}
255233
}

src/Sql/Sql/Properties/Resources.Designer.cs

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sql/Sql/Properties/Resources.resx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,9 @@
584584
<value>Do you want to proceed?</value>
585585
</data>
586586
<data name="ChangingHardwareFamilyIsIrreversable" xml:space="preserve">
587-
<value>For this update operation provided compute generation parameter is Gen5. Once the hardware generation is upgraded, it is not possible to switch back to Gen4 compute generation as this hardware is being deprecated.</value>
587+
<value>For this update operation provided compute generation parameter is '{0}'. Once the hardware generation is upgraded, it is not possible to switch back to Gen4 compute generation as this hardware is being deprecated.</value>
588588
</data>
589589
<data name="CannotChangeHardwareFamily" xml:space="preserve">
590590
<value>You cannot change hardware family.</value>
591591
</data>
592-
<data name="InvalidManagedInstanceSkuName" xml:space="preserve">
593-
<value>Provided SkuName '{0}' is invalid '{1}'. Please enter a valid SkuName value and execute command again.</value>
594-
</data>
595592
</root>

0 commit comments

Comments
 (0)