Skip to content

Commit 37e25e1

Browse files
author
Maddie Clayton
authored
Merge pull request #8504 from jaredmoo/sqlSkuUtils
Add support for SQL DB Hyperscale tier
2 parents 7c5fa58 + 84fe287 commit 37e25e1

File tree

9 files changed

+248
-20
lines changed

9 files changed

+248
-20
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Sql.Database.Cmdlet;
16+
using Microsoft.Azure.Commands.Sql.Test.Utilities;
17+
using Microsoft.Azure.ServiceManagement.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using System;
20+
using Microsoft.Azure.Commands.Sql.Database.Services;
21+
using Xunit;
22+
using Xunit.Abstractions;
23+
24+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
25+
{
26+
public class AzureSqlDatabaseUnitTests
27+
{
28+
public AzureSqlDatabaseUnitTests(ITestOutputHelper output)
29+
{
30+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void GetDatabaseSkuName()
36+
{
37+
Assert.Equal(
38+
"Basic",
39+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Basic"));
40+
Assert.Equal(
41+
"Standard",
42+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Standard"));
43+
Assert.Equal(
44+
"Premium",
45+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Premium"));
46+
Assert.Equal(
47+
"DataWarehouse",
48+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("DataWarehouse"));
49+
Assert.Equal(
50+
"Stretch",
51+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Stretch"));
52+
Assert.Equal(
53+
"GP",
54+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("GeneralPurpose"));
55+
Assert.Equal(
56+
"BC",
57+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("BusinessCritical"));
58+
Assert.Equal(
59+
"HS",
60+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Hyperscale"));
61+
}
62+
}
63+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet;
16+
using Microsoft.Azure.Commands.Sql.Test.Utilities;
17+
using Microsoft.Azure.ServiceManagement.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using System;
20+
using Microsoft.Azure.Commands.Sql.ElasticPool.Services;
21+
using Xunit;
22+
using Xunit.Abstractions;
23+
24+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
25+
{
26+
public class AzureSqlElasticPoolUnitTests
27+
{
28+
public AzureSqlElasticPoolUnitTests(ITestOutputHelper output)
29+
{
30+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void GetPoolSkuName()
36+
{
37+
Assert.Equal(
38+
"BasicPool",
39+
AzureSqlElasticPoolAdapter.GetPoolSkuName("Basic"));
40+
Assert.Equal(
41+
"StandardPool",
42+
AzureSqlElasticPoolAdapter.GetPoolSkuName("Standard"));
43+
Assert.Equal(
44+
"PremiumPool",
45+
AzureSqlElasticPoolAdapter.GetPoolSkuName("Premium"));
46+
Assert.Equal(
47+
"GP",
48+
AzureSqlElasticPoolAdapter.GetPoolSkuName("GeneralPurpose"));
49+
Assert.Equal(
50+
"BC",
51+
AzureSqlElasticPoolAdapter.GetPoolSkuName("BusinessCritical"));
52+
}
53+
}
54+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet;
16+
using Microsoft.Azure.Commands.Sql.Test.Utilities;
17+
using Microsoft.Azure.ServiceManagement.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using System;
20+
using Microsoft.Azure.Commands.Sql.ElasticPool.Services;
21+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
22+
using Xunit;
23+
using Xunit.Abstractions;
24+
25+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
26+
{
27+
public class AzureSqlInstanceUnitTests
28+
{
29+
public AzureSqlInstanceUnitTests(ITestOutputHelper output)
30+
{
31+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
32+
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void GetInstanceSkuPrefix()
37+
{
38+
Assert.Equal(
39+
"GP",
40+
AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("GeneralPurpose"));
41+
Assert.Equal(
42+
"BC",
43+
AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("BusinessCritical"));
44+
}
45+
}
46+
}

src/Sql/Sql/Common/SqlSkuUtils.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Sql.Common
16+
{
17+
/// <summary>
18+
/// Utility methods to help with SKU's.
19+
/// </summary>
20+
internal static class SqlSkuUtils
21+
{
22+
/// <summary>
23+
/// Gets sku name based on edition name for vcore editions.
24+
/// Returns null for unknown editions.
25+
///
26+
/// Edition | SkuName
27+
/// GeneralPurpose | GP
28+
/// BusinessCritical | BC
29+
/// Hyperscale | HS
30+
/// </summary>
31+
/// <param name="tier">Azure Sql database edition</param>
32+
/// <returns>The sku name</returns>
33+
public static string GetVcoreSkuPrefix(string tier)
34+
{
35+
if (string.IsNullOrWhiteSpace(tier))
36+
{
37+
return null;
38+
}
39+
40+
switch (tier.ToLowerInvariant())
41+
{
42+
case "generalpurpose":
43+
return "GP";
44+
case "businesscritical":
45+
return "BC";
46+
case "hyperscale":
47+
return "HS";
48+
default:
49+
return null;
50+
}
51+
}
52+
}
53+
}

src/Sql/Sql/Database/Services/AzureSqlDatabaseAdapter.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Collections.Generic;
2424
using System.Globalization;
2525
using System.Linq;
26+
using Microsoft.Azure.Commands.Sql.Common;
2627
using Microsoft.Azure.Management.Sql.Models;
2728

2829
namespace Microsoft.Azure.Commands.Sql.Database.Services
@@ -333,6 +334,7 @@ public void RenameDatabase(string resourceGroupName, string serverName, string d
333334
/// Edition | SkuName
334335
/// GeneralPurpose | GP
335336
/// BusinessCritical | BC
337+
/// Hyperscale | HS
336338
/// Standard | Standard
337339
/// Basic | Basic
338340
/// Premium | Premium
@@ -342,17 +344,11 @@ public void RenameDatabase(string resourceGroupName, string serverName, string d
342344
public static string GetDatabaseSkuName(string tier)
343345
{
344346
if (string.IsNullOrWhiteSpace(tier))
345-
return null;
346-
347-
switch(tier.ToLowerInvariant())
348347
{
349-
case "generalpurpose":
350-
return "GP";
351-
case "businesscritical":
352-
return "BC";
353-
default:
354-
return tier;
348+
return null;
355349
}
350+
351+
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? tier;
356352
}
357353

358354
/// <summary>

src/Sql/Sql/Elastic Pools/Services/AzureSqlElasticPoolAdapter.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2626
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2727
using System.Globalization;
28+
using Microsoft.Azure.Commands.Sql.Common;
2829

2930
namespace Microsoft.Azure.Commands.Sql.ElasticPool.Services
3031
{
@@ -420,17 +421,11 @@ private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resou
420421
public static string GetPoolSkuName(string tier)
421422
{
422423
if (string.IsNullOrWhiteSpace(tier))
423-
return null;
424-
425-
switch (tier.ToLowerInvariant())
426424
{
427-
case "generalpurpose":
428-
return "GP";
429-
case "businesscritical":
430-
return "BC";
431-
default:
432-
return string.Format("{0}Pool", tier);
425+
return null;
433426
}
427+
428+
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? string.Format("{0}Pool", tier);
434429
}
435430
}
436431
}

src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Linq;
2323
using System.Management.Automation;
2424
using System.Security;
25+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
2526

2627
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
2728
{
@@ -221,7 +222,7 @@ public override void ExecuteCmdlet()
221222
}
222223
else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase))
223224
{
224-
string editionShort = Edition.Equals(Constants.GeneralPurposeEdition) ? "GP" : Edition.Equals(Constants.BusinessCriticalEdition) ? "BC" : "Unknown";
225+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
225226
Sku.Name = editionShort + "_" + ComputeGeneration;
226227
}
227228

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Security;
2323
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2424
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
25+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
2526
using Microsoft.Azure.Commands.Sql.ManagedInstance.Model;
2627

2728
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
@@ -172,7 +173,7 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
172173
if (Edition != null)
173174
{
174175
string computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
175-
string editionShort = Edition.Equals(Constants.GeneralPurposeEdition) ? "GP" : Edition.Equals(Constants.BusinessCriticalEdition) ? "BC" : "Unknown";
176+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
176177
Sku.Name = editionShort + "_" + computeGeneration;
177178
Sku.Tier = Edition;
178179
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Security.Permissions;
2323
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2424
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
25+
using Microsoft.Azure.Commands.Sql.Common;
2526
using Microsoft.WindowsAzure.Commands.Common;
2627

2728
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter
@@ -183,5 +184,23 @@ private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromRespon
183184

184185
return managedInstance;
185186
}
187+
188+
/// <summary>
189+
/// Get instance sku name based on edition
190+
/// Edition | SkuName
191+
/// GeneralPurpose | GP
192+
/// BusinessCritical | BC
193+
/// </summary>
194+
/// <param name="tier">Azure Sql database edition</param>
195+
/// <returns>The sku name</returns>
196+
public static string GetInstanceSkuPrefix(string tier)
197+
{
198+
if (string.IsNullOrWhiteSpace(tier))
199+
{
200+
return null;
201+
}
202+
203+
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? "Unknown";
204+
}
186205
}
187206
}

0 commit comments

Comments
 (0)