Skip to content

Commit 9cd3a43

Browse files
committed
Merge pull request Azure#1471 from adumitr/cross_server_gt
Cmdlets for Cross server gt
2 parents 2fe3530 + c05a38d commit 9cd3a43

14 files changed

+941
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Private>True</Private>
7474
</Reference>
7575
<Reference Include="Microsoft.Azure.Management.Sql">
76+
<SpecificVersion>False</SpecificVersion>
7677
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.43.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
7778
</Reference>
7879
<Reference Include="Microsoft.Azure.Management.Storage">
@@ -207,6 +208,10 @@
207208
<None Include="ScenarioTests\ServerActiveDirectoryAdministratorTest.ps1">
208209
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
209210
</None>
211+
<None Include="ScenarioTests\ServerCommunicationLinkCrudTests.ps1">
212+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
213+
214+
</None>
210215
<None Include="ScenarioTests\ServiceTierAdvisorTests.ps1">
211216
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
212217
</None>
@@ -224,6 +229,7 @@
224229
</None>
225230
<Compile Include="ScenarioTests\LocationCapabilitiesTests.cs" />
226231
<Compile Include="ScenarioTests\ServerActiveDirectoryAdministratorTest.cs" />
232+
<Compile Include="ScenarioTests\ServerCommunicationLinkCrudTests.cs" />
227233
<Compile Include="ScenarioTests\ServiceTierAdvisorTests.cs" />
228234
<Compile Include="ScenarioTests\RecommendedElasticPoolTests.cs" />
229235
<Compile Include="ScenarioTests\ElasticPoolCrudTests.cs" />
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
20+
{
21+
public class ServerCommunicationLinkCrudTests : SqlTestsBase
22+
{
23+
// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
24+
// [Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
public void TestServerCommunicationLinkCreate()
27+
{
28+
RunPowerShellTest("Test-CreateServerCommunicationLink");
29+
}
30+
31+
// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
32+
// [Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void TestServerCommunicationLinkGet()
35+
{
36+
RunPowerShellTest("Test-GetServerCommunicationLink");
37+
}
38+
39+
// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
40+
// [Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
public void TestServerCommunicationLinkRemove()
43+
{
44+
RunPowerShellTest("Test-RemoveServerCommunicationLink");
45+
}
46+
}
47+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
.SYNOPSIS
17+
Tests creating a server communication link
18+
#>
19+
function Test-CreateServerCommunicationLink
20+
{
21+
# Setup
22+
$rg = Create-ResourceGroupForTest
23+
$server = Create-ServerForTest $rg "Japan East"
24+
$server2 = Create-ServerForTest $rg "Japan East"
25+
26+
try
27+
{
28+
$linkName = Get-ElasticPoolName
29+
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
30+
-LinkName $linkName -PartnerServer $server2.ServerName
31+
32+
Assert-NotNull $ep1
33+
Assert-AreEqual $server2.ServerName $ep1.PartnerServer
34+
}
35+
finally
36+
{
37+
Remove-ResourceGroupForTest $rg
38+
}
39+
}
40+
41+
<#
42+
.SYNOPSIS
43+
Tests getting a server communication link
44+
#>
45+
function Test-GetServerCommunicationLink
46+
{
47+
# Setup
48+
$rg = Create-ResourceGroupForTest
49+
$server = Create-ServerForTest $rg "Japan East"
50+
$server2 = Create-ServerForTest $rg "Japan East"
51+
52+
$linkName = Get-ElasticPoolName
53+
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
54+
-LinkName $linkName -PartnerServer $server2.ServerName
55+
Assert-NotNull $ep1
56+
57+
try
58+
{
59+
$gep1 = Get-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
60+
-LinkName $ep1.LinkName
61+
Assert-NotNull $ep1
62+
Assert-AreEqual $server2.ServerName $ep1.PartnerServer
63+
64+
$all = $server | Get-AzureRmSqlServerCommunicationLink
65+
Assert-AreEqual $all.Count 1
66+
}
67+
finally
68+
{
69+
Remove-ResourceGroupForTest $rg
70+
}
71+
}
72+
73+
<#
74+
.SYNOPSIS
75+
Tests removing a server communication link
76+
#>
77+
function Test-RemoveServerCommunicationLink
78+
{
79+
# Setup
80+
$rg = Create-ResourceGroupForTest
81+
$server1 = Create-ServerForTest $rg "Japan East"
82+
$server2 = Create-ServerForTest $rg "Japan East"
83+
84+
$linkName = Get-ElasticPoolName
85+
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
86+
-LinkName $linkName -PartnerServer $server2.ServerName
87+
Assert-NotNull $ep1
88+
89+
try
90+
{
91+
Remove-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName -LinkName $ep1.LinkName -Force
92+
93+
$all = $server | Get-AzureRmSqlServerCommunicationLink
94+
Assert-AreEqual $all.Count 0
95+
}
96+
finally
97+
{
98+
Remove-ResourceGroupForTest $rg
99+
}
100+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@
196196
<Compile Include="Secure Connection\Model\DatabaseSecureConnectionPolicyModel.cs" />
197197
<Compile Include="Secure Connection\Services\SecureConnectionEndpointsCommunicator.cs" />
198198
<Compile Include="Secure Connection\Services\SqlSecureConnectionAdapter.cs" />
199+
<Compile Include="ServerCommunicationLink\Cmdlet\AzureSqlServerCommunicationLinkCmdletBase.cs" />
200+
<Compile Include="ServerCommunicationLink\Cmdlet\GetAzureSqlServerCommunicationLink.cs" />
201+
<Compile Include="ServerCommunicationLink\Cmdlet\NewAzureSqlServerCommunicationLink.cs" />
202+
<Compile Include="ServerCommunicationLink\Cmdlet\RemoveAzureSqlServerCommunicationLink.cs" />
203+
<Compile Include="ServerCommunicationLink\Cmdlet\SetAzureSqlServerCommunicationLink.cs" />
204+
<Compile Include="ServerCommunicationLink\Model\AzureSqlServerCommunicationLinkModel.cs" />
205+
<Compile Include="ServerCommunicationLink\Services\AzureSqlServerCommunicationLinkAdapter.cs" />
206+
<Compile Include="ServerCommunicationLink\Services\AzureSqlServerCommunicationLinkCommunicator.cs" />
199207
<Compile Include="Server\Cmdlet\AzureSqlServerCmdletBase.cs" />
200208
<Compile Include="Server\Cmdlet\GetAzureSqlServer.cs" />
201209
<Compile Include="Server\Cmdlet\NewAzureSqlServer.cs" />
@@ -275,6 +283,7 @@
275283
<Private>True</Private>
276284
</Reference>
277285
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
286+
<SpecificVersion>False</SpecificVersion>
278287
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.43.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
279288
<Private>True</Private>
280289
</Reference>

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

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@
252252
<data name="ServerNotApplicableForDataMasking" xml:space="preserve">
253253
<value>Dynamic Data Masking is only available in the latest SQL Database Update (V12). Please upgrade to set it up on your database.</value>
254254
</data>
255+
<data name="RemoveAzureSqlServerCommunicationLinkDescription" xml:space="preserve">
256+
<value>Permanently removing Azure Sql Server communication link '{0}' on server '{1}'.</value>
257+
</data>
258+
<data name="RemoveAzureSqlServerCommunicationLinkWarning" xml:space="preserve">
259+
<value>Are you sure you want to remove the Azure Sql Server communication link '{0}' on server '{1}'?</value>
260+
</data>
261+
<data name="ServerCommunicationLinkNameExists" xml:space="preserve">
262+
<value>Server communication link with name: '{0}' already exists in server '{1}'.</value>
263+
</data>
255264
<data name="EmailsAreNotValid" xml:space="preserve">
256265
<value>One or more of the email addresses you entered are not valid.</value>
257266
</data>
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+
using System.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Sql.Common;
18+
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Model;
19+
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Services;
20+
21+
namespace Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Cmdlet
22+
{
23+
public abstract class AzureSqlServerCommunicationLinkCmdletBase : AzureSqlCmdletBase<IEnumerable<AzureSqlServerCommunicationLinkModel>, AzureSqlServerCommunicationLinkAdapter>
24+
{
25+
/// <summary>
26+
/// Gets or sets the name of the server to use.
27+
/// </summary>
28+
[Parameter(Mandatory = true,
29+
ValueFromPipelineByPropertyName = true,
30+
Position = 1,
31+
HelpMessage = "The name of the Azure SQL Server.")]
32+
[ValidateNotNullOrEmpty]
33+
public string ServerName { get; set; }
34+
35+
/// <summary>
36+
/// Initializes the adapter
37+
/// </summary>
38+
/// <param name="subscription">The subscription</param>
39+
/// <returns>Link adapter for ServerCommunicationLink</returns>
40+
protected override AzureSqlServerCommunicationLinkAdapter InitModelAdapter(Azure.Common.Authentication.Models.AzureSubscription subscription)
41+
{
42+
return new AzureSqlServerCommunicationLinkAdapter(DefaultProfile.Context);
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 System.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Model;
18+
19+
namespace Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Cmdlet
20+
{
21+
[Cmdlet(VerbsCommon.Get, "AzureRmSqlServerCommunicationLink",
22+
ConfirmImpact = ConfirmImpact.None), OutputType(typeof(AzureSqlServerCommunicationLinkModel))]
23+
public class GetAzureSqlServerCommunicationLink : AzureSqlServerCommunicationLinkCmdletBase
24+
{
25+
/// <summary>
26+
/// Gets or sets the name of the server communication link to use.
27+
/// </summary>
28+
[Parameter(Mandatory = false,
29+
ValueFromPipelineByPropertyName = true,
30+
Position = 2,
31+
HelpMessage = "The name of the Azure SQL server communication link to retrieve.")]
32+
[ValidateNotNullOrEmpty]
33+
public string LinkName { get; set; }
34+
35+
/// <summary>
36+
/// Get the entities from the service
37+
/// </summary>
38+
/// <returns>The list of entities</returns>
39+
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> GetEntity()
40+
{
41+
ICollection<AzureSqlServerCommunicationLinkModel> results;
42+
43+
if (MyInvocation.BoundParameters.ContainsKey("LinkName"))
44+
{
45+
results = new List<AzureSqlServerCommunicationLinkModel>();
46+
results.Add(ModelAdapter.GetServerCommunicationLink(this.ResourceGroupName, this.ServerName, this.LinkName));
47+
}
48+
else
49+
{
50+
results = ModelAdapter.ListServerCommunicationLinks(this.ResourceGroupName, this.ServerName);
51+
}
52+
53+
return results;
54+
}
55+
56+
/// <summary>
57+
/// No user input to apply to model
58+
/// </summary>
59+
/// <param name="model">Model retrieved from service</param>
60+
/// <returns>The model that was passed in</returns>
61+
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> ApplyUserInputToModel(IEnumerable<AzureSqlServerCommunicationLinkModel> model)
62+
{
63+
return model;
64+
}
65+
66+
/// <summary>
67+
/// No changes to persist to server
68+
/// </summary>
69+
/// <param name="entity">The output of apply user input to model</param>
70+
/// <returns>The input entity</returns>
71+
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> PersistChanges(IEnumerable<AzureSqlServerCommunicationLinkModel> entity)
72+
{
73+
return entity;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)