Skip to content

Commit 9ddd7bb

Browse files
authored
Merge pull request Azure#3840 from jaredmoo/migrate_provisioning
Migrate SQL elastic pool, capabilities, and service objectives to AutoRest SDK
2 parents 2a963a8 + 24947db commit 9ddd7bb

16 files changed

+157
-129
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AppDesignerFolder>Properties</AppDesignerFolder>
1212
<RootNamespace>Microsoft.Azure.Commands.Sql.Test</RootNamespace>
1313
<AssemblyName>Microsoft.Azure.Commands.Sql.Test</AssemblyName>
14-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1515
<FileAlignment>512</FileAlignment>
1616
<TargetFrameworkProfile />
1717
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
@@ -74,7 +74,7 @@
7474
<Private>True</Private>
7575
</Reference>
7676
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.2.0-preview\lib\net45\Microsoft.Azure.Management.Sql.dll</HintPath>
77+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.3.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
7878
<Private>True</Private>
7979
</Reference>
8080
<Reference Include="Microsoft.Azure.Management.Storage">

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ protected override void SetupManagementClients(Rest.ClientRuntime.Azure.TestFram
3232
{
3333
// Only SqlClient is needed.
3434
var sqlClient = GetSqlClient(context);
35+
var sqlLegacyClient = GetLegacySqlClient();
3536
var resourcesClient = GetResourcesClient();
3637
var authorizationClient = GetAuthorizationManagementClient();
37-
helper.SetupSomeOfManagementClients(sqlClient, resourcesClient, authorizationClient);
38+
helper.SetupSomeOfManagementClients(sqlClient, sqlLegacyClient, resourcesClient, authorizationClient);
3839
}
3940

4041
[Fact]

src/ResourceManager/Sql/Commands.Sql.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
11-
<package id="Microsoft.Azure.Management.Sql" version="1.2.0-preview" targetFramework="net45" />
11+
<package id="Microsoft.Azure.Management.Sql" version="1.3.0-preview" targetFramework="net452" />
1212
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
1414
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>Microsoft.Azure.Commands.Sql</RootNamespace>
1212
<AssemblyName>Microsoft.Azure.Commands.Sql</AssemblyName>
13-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<TargetFrameworkProfile />
1616
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
@@ -397,7 +397,7 @@
397397
<Private>True</Private>
398398
</Reference>
399399
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
400-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.2.0-preview\lib\net45\Microsoft.Azure.Management.Sql.dll</HintPath>
400+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.3.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
401401
<Private>True</Private>
402402
</Reference>
403403
<Reference Include="Microsoft.Azure.Management.Storage">

src/ResourceManager/Sql/Commands.Sql/Database/Model/AzureSqlDatabaseModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
186186
/// <param name="database">Database object</param>
187187
public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management.Sql.Models.Database database)
188188
{
189-
Guid id = Guid.Empty;
190189
DatabaseEdition edition = DatabaseEdition.None;
191190
DatabaseReadScale readScale = DatabaseReadScale.Enabled;
192191

@@ -207,8 +206,7 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
207206

208207
CurrentServiceObjectiveId = database.CurrentServiceObjectiveId.Value;
209208

210-
Guid.TryParse(database.DatabaseId, out id);
211-
DatabaseId = id;
209+
DatabaseId = database.DatabaseId.Value;
212210

213211
Enum.TryParse<DatabaseEdition>(database.Edition, true, out edition);
214212
Edition = edition;

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,28 +248,28 @@ internal IEnumerable<AzureSqlDatabaseActivityModel> ListDatabaseActivity(string
248248
{
249249
return new AzureSqlDatabaseActivityModel()
250250
{
251-
DatabaseName = r.Properties.DatabaseName,
252-
EndTime = r.Properties.EndTime,
253-
ErrorCode = r.Properties.ErrorCode,
254-
ErrorMessage = r.Properties.ErrorMessage,
255-
ErrorSeverity = r.Properties.ErrorSeverity,
256-
Operation = r.Properties.Operation,
257-
OperationId = r.Properties.OperationId,
258-
PercentComplete = r.Properties.PercentComplete,
259-
ServerName = r.Properties.ServerName,
260-
StartTime = r.Properties.StartTime,
261-
State = r.Properties.State,
251+
DatabaseName = r.DatabaseName,
252+
EndTime = r.EndTime,
253+
ErrorCode = r.ErrorCode,
254+
ErrorMessage = r.ErrorMessage,
255+
ErrorSeverity = r.ErrorSeverity,
256+
Operation = r.Operation,
257+
OperationId = r.OperationId,
258+
PercentComplete = r.PercentComplete,
259+
ServerName = r.ServerName,
260+
StartTime = r.StartTime,
261+
State = r.State,
262262
Properties = new AzureSqlDatabaseActivityModel.DatabaseState()
263263
{
264264
Current = new Dictionary<string, string>()
265265
{
266-
{"CurrentElasticPoolName", r.Properties.CurrentElasticPoolName},
267-
{"CurrentServiceObjectiveName", r.Properties.CurrentServiceObjectiveName},
266+
{"CurrentElasticPoolName", r.CurrentElasticPoolName},
267+
{"CurrentServiceObjectiveName", r.CurrentServiceObjective},
268268
},
269269
Requested = new Dictionary<string, string>()
270270
{
271-
{"RequestedElasticPoolName", r.Properties.RequestedElasticPoolName},
272-
{"RequestedServiceObjectiveName", r.Properties.RequestedServiceObjectiveName},
271+
{"RequestedElasticPoolName", r.RequestedElasticPoolName},
272+
{"RequestedServiceObjectiveName", r.RequestedServiceObjective},
273273
}
274274
}
275275
};

src/ResourceManager/Sql/Commands.Sql/Elastic Pools/Cmdlet/NewAzureSqlElasticPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Hyak.Common;
1615
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
1716
using Microsoft.Azure.Commands.Sql.Database.Model;
1817
using Microsoft.Azure.Commands.Sql.ElasticPool.Model;
18+
using Microsoft.Rest.Azure;
1919
using System.Collections;
2020
using System.Collections.Generic;
2121
using System.Linq;

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

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
using Microsoft.Azure.Commands.Sql.ElasticPool.Model;
1919
using Microsoft.Azure.Commands.Sql.Server.Adapter;
2020
using Microsoft.Azure.Commands.Sql.Services;
21-
using Microsoft.Azure.Management.Sql.LegacySdk.Models;
21+
using Microsoft.Azure.Management.Sql.Models;
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Linq;
2525
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
26+
using DatabaseEdition = Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition;
2627

2728
namespace Microsoft.Azure.Commands.Sql.ElasticPool.Services
2829
{
@@ -96,18 +97,15 @@ internal ICollection<AzureSqlElasticPoolModel> ListElasticPools(string resourceG
9697
/// <returns>The upserted Azure Sql Database ElasticPool</returns>
9798
internal AzureSqlElasticPoolModel UpsertElasticPool(AzureSqlElasticPoolModel model)
9899
{
99-
var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, Util.GenerateTracingId(), new ElasticPoolCreateOrUpdateParameters()
100+
var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, Util.GenerateTracingId(), new Management.Sql.Models.ElasticPool
100101
{
101102
Location = model.Location,
102103
Tags = model.Tags,
103-
Properties = new ElasticPoolCreateOrUpdateProperties()
104-
{
105-
DatabaseDtuMax = model.DatabaseDtuMax,
106-
DatabaseDtuMin = model.DatabaseDtuMin,
107-
Edition = model.Edition.ToString(),
108-
Dtu = model.Dtu,
109-
StorageMB = model.StorageMB
110-
}
104+
DatabaseDtuMax = model.DatabaseDtuMax,
105+
DatabaseDtuMin = model.DatabaseDtuMin,
106+
Edition = model.Edition.ToString(),
107+
Dtu = model.Dtu,
108+
StorageMB = model.StorageMB
111109
});
112110

113111
return CreateElasticPoolModelFromResponse(model.ResourceGroupName, model.ServerName, resp);
@@ -224,24 +222,26 @@ private AzureSqlDatabaseActivityModel CreateDatabaseActivityModelFromResponse(El
224222
/// <returns>The converted model</returns>
225223
private AzureSqlElasticPoolActivityModel CreateActivityModelFromResponse(ElasticPoolActivity model)
226224
{
227-
AzureSqlElasticPoolActivityModel activity = new AzureSqlElasticPoolActivityModel();
225+
AzureSqlElasticPoolActivityModel activity = new AzureSqlElasticPoolActivityModel
226+
{
227+
ElasticPoolName = model.ElasticPoolName,
228+
EndTime = model.EndTime,
229+
ErrorCode = model.ErrorCode,
230+
ErrorMessage = model.ErrorMessage,
231+
ErrorSeverity = model.ErrorSeverity,
232+
Operation = model.Operation,
233+
OperationId = model.OperationId,
234+
PercentComplete = model.PercentComplete,
235+
RequestedDatabaseDtuMax = model.RequestedDatabaseDtuMax,
236+
RequestedDatabaseDtuMin = model.RequestedDatabaseDtuMin,
237+
RequestedDtu = model.RequestedDtu,
238+
RequestedElasticPoolName = model.RequestedElasticPoolName,
239+
RequestedStorageLimitInGB = model.RequestedStorageLimitInGB,
240+
ServerName = model.ServerName,
241+
StartTime = model.StartTime,
242+
State = model.State
243+
};
228244

229-
activity.ElasticPoolName = model.Properties.ElasticPoolName;
230-
activity.EndTime = model.Properties.EndTime;
231-
activity.ErrorCode = model.Properties.ErrorCode;
232-
activity.ErrorMessage = model.Properties.ErrorMessage;
233-
activity.ErrorSeverity = model.Properties.ErrorSeverity;
234-
activity.Operation = model.Properties.Operation;
235-
activity.OperationId = model.Properties.OperationId;
236-
activity.PercentComplete = model.Properties.PercentComplete;
237-
activity.RequestedDatabaseDtuMax = model.Properties.RequestedDatabaseDtuMax;
238-
activity.RequestedDatabaseDtuMin = model.Properties.RequestedDatabaseDtuMin;
239-
activity.RequestedDtu = model.Properties.RequestedDtu;
240-
activity.RequestedElasticPoolName = model.Properties.RequestedElasticPoolName;
241-
activity.RequestedStorageLimitInGB = model.Properties.RequestedStorageLimitInGB;
242-
activity.ServerName = model.Properties.ServerName;
243-
activity.StartTime = model.Properties.StartTime;
244-
activity.State = model.Properties.State;
245245

246246
return activity;
247247
}
@@ -266,26 +266,28 @@ public string GetServerLocation(string resourceGroupName, string serverName)
266266
/// <param name="serverName">The name of the Azure Sql Database Server</param>
267267
/// <param name="pool">The service response</param>
268268
/// <returns>The converted model</returns>
269-
private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resourceGroup, string serverName, Management.Sql.LegacySdk.Models.ElasticPool pool)
269+
private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.ElasticPool pool)
270270
{
271-
AzureSqlElasticPoolModel model = new AzureSqlElasticPoolModel();
272-
273-
model.ResourceId = pool.Id;
274-
model.ResourceGroupName = resourceGroup;
275-
model.ServerName = serverName;
276-
model.ElasticPoolName = pool.Name;
277-
model.CreationDate = pool.Properties.CreationDate ?? DateTime.MinValue;
278-
model.DatabaseDtuMax = (int)pool.Properties.DatabaseDtuMax;
279-
model.DatabaseDtuMin = (int)pool.Properties.DatabaseDtuMin;
280-
model.Dtu = (int)pool.Properties.Dtu;
281-
model.State = pool.Properties.State;
282-
model.StorageMB = pool.Properties.StorageMB;
283-
model.Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(pool.Tags), false);
284-
model.Location = pool.Location;
285-
286271
DatabaseEdition edition = DatabaseEdition.None;
287-
Enum.TryParse<DatabaseEdition>(pool.Properties.Edition, out edition);
288-
model.Edition = edition;
272+
Enum.TryParse<DatabaseEdition>(pool.Edition, out edition);
273+
274+
AzureSqlElasticPoolModel model = new AzureSqlElasticPoolModel
275+
{
276+
ResourceId = pool.Id,
277+
ResourceGroupName = resourceGroup,
278+
ServerName = serverName,
279+
ElasticPoolName = pool.Name,
280+
CreationDate = pool.CreationDate ?? DateTime.MinValue,
281+
DatabaseDtuMax = pool.DatabaseDtuMax.Value,
282+
DatabaseDtuMin = pool.DatabaseDtuMin.Value,
283+
Dtu = pool.Dtu,
284+
State = pool.State,
285+
StorageMB = pool.StorageMB,
286+
Tags =
287+
TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(pool.Tags), false),
288+
Location = pool.Location,
289+
Edition = edition
290+
};
289291

290292
return model;
291293
}

0 commit comments

Comments
 (0)