Skip to content

Commit 480b1a3

Browse files
authored
Migrating from management SDK to autogenerated C# code for deployments and related cmdlets (#21813)
* Initial commit for SDK migration * Update sdk namespace * Namespace change for sdk in some classes * Split SDK client to use old and new bits * Upgrade API version * Update resources proj * Add explanation comments for duplicated classes * Update changelog * Remove no op changes * Remove no op changes * Update Tags.csproj * Update Tags.csproj * Add SDK readme * Switch from ReosurceManagerSdkClient to NewResourceManagerSdkClient in some files * Suppress breaking change errors
1 parent 607df6c commit 480b1a3

File tree

394 files changed

+97650
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

394 files changed

+97650
-858
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
//This class is identical to Comparers.ChangeTypeComparer with the only difference being the import of Management.Resources instead of Management.ResourceManager.
16+
//The reason for this is this module has both cmdlets that use the old sdk version and cmdlets that use the new one, so this one acts as the class to be used by the cmdlets using the newer bits for the time being
17+
18+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
19+
{
20+
using Management.Resources.Models;
21+
using System.Collections.Generic;
22+
23+
public class ChangeTypeComparer : IComparer<ChangeType>
24+
{
25+
private static readonly IReadOnlyDictionary<ChangeType, int> WeightsByChangeType =
26+
new Dictionary<ChangeType, int>
27+
{
28+
[ChangeType.Delete] = 0,
29+
[ChangeType.Create] = 1,
30+
[ChangeType.Deploy] = 2,
31+
[ChangeType.Modify] = 3,
32+
[ChangeType.Unsupported] = 4,
33+
[ChangeType.NoChange] = 5,
34+
[ChangeType.Ignore] = 6,
35+
};
36+
37+
public int Compare(ChangeType first, ChangeType second)
38+
{
39+
return WeightsByChangeType[first] - WeightsByChangeType[second];
40+
}
41+
}
42+
}
43+
44+
45+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
//This class is identical to Comparers.PSChangeTypeComparer, but in a different namespace
16+
//The reason for this is this module has both cmdlets that use the old sdk version and cmdlets that use the new one, so this one acts as the class to be used by the cmdlets using the newer bits for the time being
17+
18+
using System.Collections.Generic;
19+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
20+
21+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
22+
{
23+
public class PSChangeTypeComparer : IComparer<PSChangeType>
24+
{
25+
private static readonly IReadOnlyDictionary<PSChangeType, int> WeightsByPSChangeType =
26+
new Dictionary<PSChangeType, int>
27+
{
28+
[PSChangeType.Delete] = 0,
29+
[PSChangeType.Create] = 1,
30+
[PSChangeType.Deploy] = 2,
31+
[PSChangeType.Modify] = 3,
32+
[PSChangeType.Unsupported] = 4,
33+
[PSChangeType.NoEffect] = 5,
34+
[PSChangeType.NoChange] = 6,
35+
[PSChangeType.Ignore] = 7,
36+
};
37+
38+
public int Compare(PSChangeType first, PSChangeType second)
39+
{
40+
return WeightsByPSChangeType[first] - WeightsByPSChangeType[second];
41+
}
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
16+
//This class is identical to Comparers.PropertyChangeTypeComparer with the only difference being the import of Management.Resources instead of Management.ResourceManager.
17+
//The reason for this is this module has both cmdlets that use the old sdk version and cmdlets that use the new one, so this one acts as the class to be used by the cmdlets using the newer bits for the time being
18+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
19+
{
20+
using Management.Resources.Models;
21+
using System.Collections.Generic;
22+
23+
public class PropertyChangeTypeComparer : IComparer<PropertyChangeType>
24+
{
25+
private static readonly IReadOnlyDictionary<PropertyChangeType, int> WeightsByPropertyChangeType =
26+
new Dictionary<PropertyChangeType, int>
27+
{
28+
[PropertyChangeType.Delete] = 0,
29+
[PropertyChangeType.Create] = 1,
30+
// Modify and Array are set to have the same weight by intention.
31+
[PropertyChangeType.Modify] = 2,
32+
[PropertyChangeType.Array] = 2,
33+
[PropertyChangeType.NoEffect] = 3,
34+
};
35+
36+
public int Compare(PropertyChangeType first, PropertyChangeType second)
37+
{
38+
return WeightsByPropertyChangeType[first] - WeightsByPropertyChangeType[second];
39+
}
40+
}
41+
}
42+
43+

src/Resources/ResourceManager/Components/TemplateSpecPackagingEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components
1616
{
1717
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
18-
using Microsoft.Azure.Management.ResourceManager.Models;
18+
using Microsoft.Azure.Management.Resources.Models;
1919
using Newtonsoft.Json.Linq;
2020
using System;
2121
using System.Collections.Generic;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
//This class is identical to Extensions.ChangeTypeExtensions with the only difference being the import of Management.Resources instead of Management.ResourceManager.
16+
//The reason for this is this module has both cmdlets that use the old sdk version and cmdlets that use the new one, so this one acts as the class to be used by the cmdlets using the newer bits for the time being
17+
18+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewExtensions
19+
{
20+
using Formatters;
21+
using Management.Resources.Models;
22+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
23+
using System;
24+
using System.Collections.Generic;
25+
26+
public static class ChangeTypeExtensions
27+
{
28+
private static readonly IReadOnlyDictionary<ChangeType, Color> ColorsByChangeType =
29+
new Dictionary<ChangeType, Color>
30+
{
31+
[ChangeType.NoChange] = Color.Reset,
32+
[ChangeType.Ignore] = Color.Gray,
33+
[ChangeType.Deploy] = Color.Blue,
34+
[ChangeType.Create] = Color.Green,
35+
[ChangeType.Delete] = Color.Orange,
36+
[ChangeType.Modify] = Color.Purple,
37+
[ChangeType.Unsupported] = Color.Gray,
38+
};
39+
40+
private static readonly IReadOnlyDictionary<ChangeType, Symbol> SymbolsByChangeType =
41+
new Dictionary<ChangeType, Symbol>
42+
{
43+
[ChangeType.NoChange] = Symbol.Equal,
44+
[ChangeType.Ignore] = Symbol.Asterisk,
45+
[ChangeType.Deploy] = Symbol.ExclamationPoint,
46+
[ChangeType.Create] = Symbol.Plus,
47+
[ChangeType.Delete] = Symbol.Minus,
48+
[ChangeType.Modify] = Symbol.Tilde,
49+
[ChangeType.Unsupported] = Symbol.Cross,
50+
};
51+
52+
private static readonly IReadOnlyDictionary<ChangeType, PSChangeType> PSChangeTypesByChangeType =
53+
new Dictionary<ChangeType, PSChangeType>
54+
{
55+
[ChangeType.NoChange] = PSChangeType.NoChange,
56+
[ChangeType.Ignore] = PSChangeType.Ignore,
57+
[ChangeType.Deploy] = PSChangeType.Deploy,
58+
[ChangeType.Create] = PSChangeType.Create,
59+
[ChangeType.Delete] = PSChangeType.Delete,
60+
[ChangeType.Modify] = PSChangeType.Modify,
61+
[ChangeType.Unsupported] = PSChangeType.Unsupported,
62+
};
63+
64+
public static Color ToColor(this ChangeType changeType)
65+
{
66+
bool success = ColorsByChangeType.TryGetValue(changeType, out Color colorCode);
67+
68+
if (!success)
69+
{
70+
throw new ArgumentOutOfRangeException(nameof(changeType));
71+
}
72+
73+
return colorCode;
74+
}
75+
76+
public static Symbol ToSymbol(this ChangeType changeType)
77+
{
78+
bool success = SymbolsByChangeType.TryGetValue(changeType, out Symbol symbol);
79+
80+
if (!success)
81+
{
82+
throw new ArgumentOutOfRangeException(nameof(changeType));
83+
}
84+
85+
return symbol;
86+
}
87+
88+
public static PSChangeType ToPSChangeType(this ChangeType changeType)
89+
{
90+
bool success = PSChangeTypesByChangeType.TryGetValue(changeType, out PSChangeType psChangeType);
91+
92+
if (!success)
93+
{
94+
throw new ArgumentOutOfRangeException(nameof(changeType));
95+
}
96+
97+
return psChangeType;
98+
}
99+
100+
}
101+
}
102+
103+
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
//This class is identical to Extensions.PropertyChangeTypeExtensions with the only difference being the import of Management.Resources instead of Management.ResourceManager.
16+
//The reason for this is this module has both cmdlets that use the old sdk version and cmdlets that use the new one, so this one acts as the class to be used by the cmdlets using the newer bits for the time being
17+
18+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewExtensions
19+
{
20+
using Formatters;
21+
using Management.Resources.Models;
22+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
23+
using System;
24+
using System.Collections.Generic;
25+
26+
public static class PropertyChangeTypeExtensions
27+
{
28+
private static readonly IReadOnlyDictionary<PropertyChangeType, Color> ColorsByPropertyChangeType =
29+
new Dictionary<PropertyChangeType, Color>
30+
{
31+
[PropertyChangeType.Create] = Color.Green,
32+
[PropertyChangeType.Delete] = Color.Orange,
33+
[PropertyChangeType.Modify] = Color.Purple,
34+
[PropertyChangeType.Array] = Color.Purple,
35+
[PropertyChangeType.NoEffect] = Color.Gray,
36+
};
37+
38+
private static readonly IReadOnlyDictionary<PropertyChangeType, Symbol> SymbolsByPropertyChangeType =
39+
new Dictionary<PropertyChangeType, Symbol>
40+
{
41+
[PropertyChangeType.Create] = Symbol.Plus,
42+
[PropertyChangeType.Delete] = Symbol.Minus,
43+
[PropertyChangeType.Modify] = Symbol.Tilde,
44+
[PropertyChangeType.Array] = Symbol.Tilde,
45+
[PropertyChangeType.NoEffect] = Symbol.Cross,
46+
};
47+
48+
private static readonly IReadOnlyDictionary<PropertyChangeType, PSChangeType> PSChangeTypesByPropertyChangeType =
49+
new Dictionary<PropertyChangeType, PSChangeType>
50+
{
51+
[PropertyChangeType.Create] = PSChangeType.Create,
52+
[PropertyChangeType.Delete] = PSChangeType.Delete,
53+
[PropertyChangeType.Modify] = PSChangeType.Modify,
54+
[PropertyChangeType.Array] = PSChangeType.Modify,
55+
[PropertyChangeType.NoEffect] = PSChangeType.NoEffect,
56+
};
57+
58+
public static Color ToColor(this PropertyChangeType propertyChangeType)
59+
{
60+
bool success = ColorsByPropertyChangeType.TryGetValue(propertyChangeType, out Color colorCode);
61+
62+
if (!success)
63+
{
64+
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
65+
}
66+
67+
return colorCode;
68+
}
69+
70+
public static Symbol ToSymbol(this PropertyChangeType propertyChangeType)
71+
{
72+
bool success = SymbolsByPropertyChangeType.TryGetValue(propertyChangeType, out Symbol symbol);
73+
74+
if (!success)
75+
{
76+
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
77+
}
78+
79+
return symbol;
80+
}
81+
82+
public static PSChangeType ToPSChangeType(this PropertyChangeType propertyChangeType)
83+
{
84+
bool success = PSChangeTypesByPropertyChangeType.TryGetValue(propertyChangeType, out PSChangeType changeType);
85+
86+
if (!success)
87+
{
88+
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
89+
}
90+
91+
return changeType;
92+
}
93+
94+
public static bool IsDelete(this PropertyChangeType propertyChangeType)
95+
{
96+
return propertyChangeType == PropertyChangeType.Delete;
97+
}
98+
99+
public static bool IsCreate(this PropertyChangeType propertyChangeType)
100+
{
101+
return propertyChangeType == PropertyChangeType.Create;
102+
}
103+
104+
public static bool IsModify(this PropertyChangeType propertyChangeType)
105+
{
106+
return propertyChangeType == PropertyChangeType.Modify;
107+
}
108+
109+
public static bool IsArray(this PropertyChangeType propertyChangeType)
110+
{
111+
return propertyChangeType == PropertyChangeType.Array;
112+
}
113+
}
114+
}
115+

src/Resources/ResourceManager/Formatters/WhatIfOperationResultFormatter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Formatters
1717
using System;
1818
using System.Collections.Generic;
1919
using System.Linq;
20-
using Comparers;
20+
using NewComparers;
21+
using NewExtensions;
2122
using Extensions;
22-
using Microsoft.Azure.Management.ResourceManager.Models;
23+
using Microsoft.Azure.Management.Resources.Models;
2324
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2425
using Newtonsoft.Json.Linq;
2526
using Properties;

src/Resources/ResourceManager/Implementation/CmdletBase/DeploymentCreateCmdlet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Cmdlet
2222
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties;
2323
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
2424
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
25-
using Microsoft.Azure.Management.ResourceManager.Models;
25+
using Microsoft.Azure.Management.Resources.Models;
2626

2727
public abstract class DeploymentCreateCmdlet: DeploymentWhatIfCmdlet
2828
{
@@ -83,11 +83,11 @@ protected void ExecuteDeployment()
8383

8484
if (this.DeploymentParameters.ScopeType == DeploymentScopeType.ResourceGroup)
8585
{
86-
this.WriteObject(this.ResourceManagerSdkClient.ExecuteResourceGroupDeployment(this.DeploymentParameters));
86+
this.WriteObject(this.NewResourceManagerSdkClient.ExecuteResourceGroupDeployment(this.DeploymentParameters));
8787
}
8888
else
8989
{
90-
this.WriteObject(this.ResourceManagerSdkClient.ExecuteDeployment(this.DeploymentParameters));
90+
this.WriteObject(this.NewResourceManagerSdkClient.ExecuteDeployment(this.DeploymentParameters));
9191
}
9292
}
9393

0 commit comments

Comments
 (0)