Skip to content

Commit d2bd6ee

Browse files
committed
Extract common SKU prefixes
1 parent cf9e1aa commit d2bd6ee

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

src/Sql/Sql.Test/UnitTests/AzureSqlDatabaseUnitTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void GetDatabaseSkuName()
5555
Assert.Equal(
5656
"BC",
5757
AzureSqlDatabaseAdapter.GetDatabaseSkuName("BusinessCritical"));
58+
Assert.Equal(
59+
"HS",
60+
AzureSqlDatabaseAdapter.GetDatabaseSkuName("Hyperscale"));
5861
}
5962
}
6063
}

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
}

0 commit comments

Comments
 (0)