Skip to content

Cmdlets for Cross server gt #1471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Sql">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.43.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Storage">
Expand Down Expand Up @@ -207,6 +208,10 @@
<None Include="ScenarioTests\ServerActiveDirectoryAdministratorTest.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\ServerCommunicationLinkCrudTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

</None>
<None Include="ScenarioTests\ServiceTierAdvisorTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -224,6 +229,7 @@
</None>
<Compile Include="ScenarioTests\LocationCapabilitiesTests.cs" />
<Compile Include="ScenarioTests\ServerActiveDirectoryAdministratorTest.cs" />
<Compile Include="ScenarioTests\ServerCommunicationLinkCrudTests.cs" />
<Compile Include="ScenarioTests\ServiceTierAdvisorTests.cs" />
<Compile Include="ScenarioTests\RecommendedElasticPoolTests.cs" />
<Compile Include="ScenarioTests\ElasticPoolCrudTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
{
public class ServerCommunicationLinkCrudTests : SqlTestsBase
{
// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
// [Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestServerCommunicationLinkCreate()
{
RunPowerShellTest("Test-CreateServerCommunicationLink");
}

// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
// [Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestServerCommunicationLinkGet()
{
RunPowerShellTest("Test-GetServerCommunicationLink");
}

// TODO: adumitr: re-enable the tests when feature is fully enabled in the region the tests use
// [Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestServerCommunicationLinkRemove()
{
RunPowerShellTest("Test-RemoveServerCommunicationLink");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests creating a server communication link
#>
function Test-CreateServerCommunicationLink
{
# Setup
$rg = Create-ResourceGroupForTest
$server = Create-ServerForTest $rg "Japan East"
$server2 = Create-ServerForTest $rg "Japan East"

try
{
$linkName = Get-ElasticPoolName
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
-LinkName $linkName -PartnerServer $server2.ServerName

Assert-NotNull $ep1
Assert-AreEqual $server2.ServerName $ep1.PartnerServer
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Tests getting a server communication link
#>
function Test-GetServerCommunicationLink
{
# Setup
$rg = Create-ResourceGroupForTest
$server = Create-ServerForTest $rg "Japan East"
$server2 = Create-ServerForTest $rg "Japan East"

$linkName = Get-ElasticPoolName
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
-LinkName $linkName -PartnerServer $server2.ServerName
Assert-NotNull $ep1

try
{
$gep1 = Get-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
-LinkName $ep1.LinkName
Assert-NotNull $ep1
Assert-AreEqual $server2.ServerName $ep1.PartnerServer

$all = $server | Get-AzureRmSqlServerCommunicationLink
Assert-AreEqual $all.Count 1
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Tests removing a server communication link
#>
function Test-RemoveServerCommunicationLink
{
# Setup
$rg = Create-ResourceGroupForTest
$server1 = Create-ServerForTest $rg "Japan East"
$server2 = Create-ServerForTest $rg "Japan East"

$linkName = Get-ElasticPoolName
$ep1 = New-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName `
-LinkName $linkName -PartnerServer $server2.ServerName
Assert-NotNull $ep1

try
{
Remove-AzureRmSqlServerCommunicationLink -ServerName $server1.ServerName -ResourceGroupName $rg.ResourceGroupName -LinkName $ep1.LinkName -Force

$all = $server | Get-AzureRmSqlServerCommunicationLink
Assert-AreEqual $all.Count 0
}
finally
{
Remove-ResourceGroupForTest $rg
}
}
9 changes: 9 additions & 0 deletions src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@
<Compile Include="Secure Connection\Model\DatabaseSecureConnectionPolicyModel.cs" />
<Compile Include="Secure Connection\Services\SecureConnectionEndpointsCommunicator.cs" />
<Compile Include="Secure Connection\Services\SqlSecureConnectionAdapter.cs" />
<Compile Include="ServerCommunicationLink\Cmdlet\AzureSqlServerCommunicationLinkCmdletBase.cs" />
<Compile Include="ServerCommunicationLink\Cmdlet\GetAzureSqlServerCommunicationLink.cs" />
<Compile Include="ServerCommunicationLink\Cmdlet\NewAzureSqlServerCommunicationLink.cs" />
<Compile Include="ServerCommunicationLink\Cmdlet\RemoveAzureSqlServerCommunicationLink.cs" />
<Compile Include="ServerCommunicationLink\Cmdlet\SetAzureSqlServerCommunicationLink.cs" />
<Compile Include="ServerCommunicationLink\Model\AzureSqlServerCommunicationLinkModel.cs" />
<Compile Include="ServerCommunicationLink\Services\AzureSqlServerCommunicationLinkAdapter.cs" />
<Compile Include="ServerCommunicationLink\Services\AzureSqlServerCommunicationLinkCommunicator.cs" />
<Compile Include="Server\Cmdlet\AzureSqlServerCmdletBase.cs" />
<Compile Include="Server\Cmdlet\GetAzureSqlServer.cs" />
<Compile Include="Server\Cmdlet\NewAzureSqlServer.cs" />
Expand Down Expand Up @@ -275,6 +283,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.43.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
<Private>True</Private>
</Reference>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="ServerNotApplicableForDataMasking" xml:space="preserve">
<value>Dynamic Data Masking is only available in the latest SQL Database Update (V12). Please upgrade to set it up on your database.</value>
</data>
<data name="RemoveAzureSqlServerCommunicationLinkDescription" xml:space="preserve">
<value>Permanently removing Azure Sql Server communication link '{0}' on server '{1}'.</value>
</data>
<data name="RemoveAzureSqlServerCommunicationLinkWarning" xml:space="preserve">
<value>Are you sure you want to remove the Azure Sql Server communication link '{0}' on server '{1}'?</value>
</data>
<data name="ServerCommunicationLinkNameExists" xml:space="preserve">
<value>Server communication link with name: '{0}' already exists in server '{1}'.</value>
</data>
<data name="EmailsAreNotValid" xml:space="preserve">
<value>One or more of the email addresses you entered are not valid.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.Sql.Common;
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Model;
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Services;

namespace Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Cmdlet
{
public abstract class AzureSqlServerCommunicationLinkCmdletBase : AzureSqlCmdletBase<IEnumerable<AzureSqlServerCommunicationLinkModel>, AzureSqlServerCommunicationLinkAdapter>
{
/// <summary>
/// Gets or sets the name of the server to use.
/// </summary>
[Parameter(Mandatory = true,
ValueFromPipelineByPropertyName = true,
Position = 1,
HelpMessage = "The name of the Azure SQL Server.")]
[ValidateNotNullOrEmpty]
public string ServerName { get; set; }

/// <summary>
/// Initializes the adapter
/// </summary>
/// <param name="subscription">The subscription</param>
/// <returns>Link adapter for ServerCommunicationLink</returns>
protected override AzureSqlServerCommunicationLinkAdapter InitModelAdapter(Azure.Common.Authentication.Models.AzureSubscription subscription)
{
return new AzureSqlServerCommunicationLinkAdapter(DefaultProfile.Context);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Model;

namespace Microsoft.Azure.Commands.Sql.ServerCommunicationLink.Cmdlet
{
[Cmdlet(VerbsCommon.Get, "AzureRmSqlServerCommunicationLink",
ConfirmImpact = ConfirmImpact.None), OutputType(typeof(AzureSqlServerCommunicationLinkModel))]
public class GetAzureSqlServerCommunicationLink : AzureSqlServerCommunicationLinkCmdletBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adumitr What is the OutputType for this cmdlet? Please add the attribute for OutputType with the cmdlet OutputType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

{
/// <summary>
/// Gets or sets the name of the server communication link to use.
/// </summary>
[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
Position = 2,
HelpMessage = "The name of the Azure SQL server communication link to retrieve.")]
[ValidateNotNullOrEmpty]
public string LinkName { get; set; }

/// <summary>
/// Get the entities from the service
/// </summary>
/// <returns>The list of entities</returns>
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> GetEntity()
{
ICollection<AzureSqlServerCommunicationLinkModel> results;

if (MyInvocation.BoundParameters.ContainsKey("LinkName"))
{
results = new List<AzureSqlServerCommunicationLinkModel>();
results.Add(ModelAdapter.GetServerCommunicationLink(this.ResourceGroupName, this.ServerName, this.LinkName));
}
else
{
results = ModelAdapter.ListServerCommunicationLinks(this.ResourceGroupName, this.ServerName);
}

return results;
}

/// <summary>
/// No user input to apply to model
/// </summary>
/// <param name="model">Model retrieved from service</param>
/// <returns>The model that was passed in</returns>
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> ApplyUserInputToModel(IEnumerable<AzureSqlServerCommunicationLinkModel> model)
{
return model;
}

/// <summary>
/// No changes to persist to server
/// </summary>
/// <param name="entity">The output of apply user input to model</param>
/// <returns>The input entity</returns>
protected override IEnumerable<AzureSqlServerCommunicationLinkModel> PersistChanges(IEnumerable<AzureSqlServerCommunicationLinkModel> entity)
{
return entity;
}
}
}
Loading