Skip to content
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

Get-AzSynapseSqlPoolGeoBackup and Get-AzSynapseDroppedSqlPool. #13621

Merged
merged 22 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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
18 changes: 18 additions & 0 deletions src/Synapse/Synapse.Test/ScenarioTests/SqlPoolBackupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ public void TestSqlPoolRestorePoint(){
"Test-SqlPoolRestorePoint");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSqlPoolGeoBackup()
{
NewInstance.RunPsTest(
_logger,
"Test-SqlPoolGeoBackup");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDroppedSqlPool()
{
NewInstance.RunPsTest(
_logger,
"Test-DroppedSqlPool");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRestoreFromRestorePoint()
Expand Down
72 changes: 72 additions & 0 deletions src/Synapse/Synapse.Test/ScenarioTests/SqlPoolBackupTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,78 @@ function Test-SqlPoolRestorePoint
}
}

function Test-SqlPoolGeoBackup
{
# Setup
$testSuffix = 'ps2502'
zesluo marked this conversation as resolved.
Show resolved Hide resolved
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix

try
{
$SqlPoolGeoBackupGet =Get-AzSynapseSqlPoolGeoBackup -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName
Assert-AreEqual $params.sqlPoolName $SqlPoolGeoBackupGet[0].Name
Assert-Null $SqlPoolGeoBackupGet[0].ElasticPoolName
Assert-NotNull $SqlPoolGeoBackupGet[0].Edition
Assert-NotNull $SqlPoolGeoBackupGet[0].LastAvailableBackupDate

$SqlPoolGeoBackupGetByPool =Get-AzSynapseSqlPoolGeoBackup -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName
Assert-AreEqual $params.sqlPoolName $SqlPoolGeoBackupGetByPool.Name
Assert-Null $SqlPoolGeoBackupGetByPool.ElasticPoolName
Assert-NotNull $SqlPoolGeoBackupGetByPool.Edition
Assert-NotNull $SqlPoolGeoBackupGetByPool.LastAvailableBackupDate
}
finally
{
# Cleanup
#Remove-SqlPoolBackupTestEnvironment $testSuffix
zesluo marked this conversation as resolved.
Show resolved Hide resolved
}
}

function Test-DroppedSqlPool
{
# Setup
$testSuffix = 'ps2503'
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix

$rgname = $params.rgname
$workspaceName = $params.workspaceName
$sqlPoolName = $params.sqlPoolName

try
{
New-AzSynapseSqlPool -ResourceGroupName $rgname -WorkspaceName $workspaceName -Name $sqlPoolName -PerformanceLevel DW400c

# wait for a short while since it needs some time to create
Wait-Seconds 80

Remove-AzSynapseSqlPool -ResourceGroupName $rgname -WorkspaceName $workspaceName -Name $sqlPoolName -Force

zesluo marked this conversation as resolved.
Show resolved Hide resolved
$DroppedSqlPoolGet =Get-AzSynapseDroppedSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName
Assert-AreEqual $sqlPoolName $DroppedSqlPoolGet[0].DatabaseName
Assert-Null $DroppedSqlPoolGet[0].ElasticPoolName
Assert-NotNull $DroppedSqlPoolGet[0].Edition
Assert-NotNull $DroppedSqlPoolGet[0].MaxSizeBytes
Assert-NotNull $DroppedSqlPoolGet[0].ServiceLevelObjective
Assert-NotNull $DroppedSqlPoolGet[0].CreationDate
Assert-NotNull $DroppedSqlPoolGet[0].DeletionDate
Assert-NotNull $DroppedSqlPoolGet[0].EarliestRestoreDate

$DroppedSqlPoolGetByPool= Get-AzSynapseDroppedSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName
Assert-AreEqual $sqlPoolName $DroppedSqlPoolGetByPool[0].DatabaseName
Assert-Null $DroppedSqlPoolGetByPool[0].ElasticPoolName
Assert-NotNull $DroppedSqlPoolGetByPool[0].Edition
Assert-NotNull $DroppedSqlPoolGetByPool[0].MaxSizeBytes
Assert-NotNull $DroppedSqlPoolGetByPool[0].ServiceLevelObjective
Assert-NotNull $DroppedSqlPoolGetByPool[0].CreationDate
Assert-NotNull $DroppedSqlPoolGetByPool[0].DeletionDate
Assert-NotNull $DroppedSqlPoolGetByPool[0].EarliestRestoreDate
}
finally
{
# Cleanup
#Remove-SqlPoolBackupTestEnvironment $testSuffix
zesluo marked this conversation as resolved.
Show resolved Hide resolved
}
}
<#
.SYNOPSIS
Tests for restoring from restore point
Expand Down
1 change: 1 addition & 0 deletions src/Synapse/Synapse/Az.Synapse.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ CmdletsToExport = 'Get-AzSynapseSparkJob', 'Stop-AzSynapseSparkJob',
'New-AzSynapseWorkspace', 'Remove-AzSynapseWorkspace',
'Update-AzSynapseWorkspace', 'Get-AzSynapseSqlPool',
'New-AzSynapseSqlPool', 'Remove-AzSynapseSqlPool',
'Get-AzSynapseSqlPoolGeoBackup', 'Get-AzSynapseDroppedSqlPool',
'Suspend-AzSynapseSqlPool', 'Resume-AzSynapseSqlPool',
'Get-AzSynapseSqlPoolRestorePoint', 'Restore-AzSynapseSqlPool',
'New-AzSynapseSqlPoolRestorePoint',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.DroppedSqlPool,
DefaultParameterSetName = GetByNameParameterSet)]
[OutputType(typeof(PSRestorableDroppedSqlPool))]
public class GetAzureSynapseDroppedSqlPool : SynapseManagementCmdletBase
{
private const string GetByNameParameterSet = "GetByNameParameterSet";

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.ResourceGroupName)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.WorkspaceName)]
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string WorkspaceName { get; set; }

[Parameter(Mandatory = false, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.DeletionDate)]
[ValidateNotNullOrEmpty]
public DateTime? DeletionDate { get; set; }

public override void ExecuteCmdlet()
{
if (MyInvocation.BoundParameters.ContainsKey("Name"))
{
if (MyInvocation.BoundParameters.ContainsKey("DeletionDate"))
{
var result = this.SynapseAnalyticsClient.GetDroppedSqlPoolBackup(this.ResourceGroupName, this.WorkspaceName, this.Name + "," + this.DeletionDate.Value.ToFileTimeUtc().ToString());
WriteObject(result);
}
else
{
var results = this.SynapseAnalyticsClient.ListDroppedSqlPoolBackups(this.ResourceGroupName, this.WorkspaceName).Where(backup => backup.DatabaseName == Name).ToList();
WriteObject(results, true);
}
}
else
{
var results = this.SynapseAnalyticsClient.ListDroppedSqlPoolBackups(this.ResourceGroupName, this.WorkspaceName);
WriteObject(results, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPoolGeoBackup,
DefaultParameterSetName = GetByNameParameterSet)]
[OutputType(typeof(PSRecoverableSqlPool))]
public class GetAzureSynapseSqlPoolGeoBackup : SynapseManagementCmdletBase
{
private const string GetByNameParameterSet = "GetByNameParameterSet";

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.ResourceGroupName)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.WorkspaceName)]
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string WorkspaceName { get; set; }

[Parameter(Mandatory = false, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

public override void ExecuteCmdlet()
{
if (MyInvocation.BoundParameters.ContainsKey("Name") && !WildcardPattern.ContainsWildcardCharacters(Name))
{
var result = this.SynapseAnalyticsClient.GetRecoverableSqlPool(ResourceGroupName, WorkspaceName, Name);
WriteObject(result);
}
else
{
var results = this.SynapseAnalyticsClient.ListRecoverableSqlPool(this.ResourceGroupName, this.WorkspaceName);
WriteObject(results, true);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Synapse/Synapse/Common/HelpMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class HelpMessages

public const string DefaultDataLakeStorageFilesystem = "The default ADLS Gen2 file system.";

public const string DeletionDate = "The deletion date of the Azure Synaspe SQL Database to retrieve backups for, with millisecond precision (e.g. 2016-02-23T00:21:22.847Z)";

public const string ManagedVirtualNetwork = "Name of a Synapse-managed virtual network dedicated for the Azure Synapse workspace.";

public const string DisallowAllConnection = "Azure Synapse Studio and other client tools will only be able to connect to the workspace endpoints if this parameter is not present. Connections from specific IP addresses or all Azure services can be allowed/disallowed after the workspace is provisioned.";
Expand Down
35 changes: 35 additions & 0 deletions src/Synapse/Synapse/Models/PSRecoverableSqlPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.Management.Synapse.Models;

namespace Microsoft.Azure.Commands.Synapse.Models
{
public class PSRecoverableSqlPool : PSSynapseProxyResource
{
public PSRecoverableSqlPool(RecoverableSqlPool recoverableSqlPool)
: base(recoverableSqlPool?.Id, recoverableSqlPool?.Name, recoverableSqlPool?.Type)
{
this.Edition = recoverableSqlPool.Edition;
this.ServiceLevelObjective = recoverableSqlPool.ServiceLevelObjective;
this.ElasticPoolName = recoverableSqlPool.ElasticPoolName;
this.LastAvailableBackupDate = recoverableSqlPool.LastAvailableBackupDate;
}

public string Edition { get; set; }
//
// Summary:
// Gets the service level objective name of the database

public string ServiceLevelObjective { get; set; }
zesluo marked this conversation as resolved.
Show resolved Hide resolved
//
// Summary:
// Gets the elastic pool name of the database
public string ElasticPoolName { get; set; }
//
zesluo marked this conversation as resolved.
Show resolved Hide resolved
// Summary:
// Gets the last available backup date of the database (ISO8601 format)
public DateTime? LastAvailableBackupDate { get; set; }
}
}

71 changes: 71 additions & 0 deletions src/Synapse/Synapse/Models/PSRestorableDroppedSqlPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.Management.Synapse.Models;

namespace Microsoft.Azure.Commands.Synapse.Models
{
public class PSRestorableDroppedSqlPool : PSSynapseProxyResource
{
public PSRestorableDroppedSqlPool(RestorableDroppedSqlPool restorableDroppedSqlPool)
: base(restorableDroppedSqlPool?.Id, restorableDroppedSqlPool?.Name, restorableDroppedSqlPool?.Type)
{
this.Location = restorableDroppedSqlPool.Location;
this.SqlpoolName = restorableDroppedSqlPool.DatabaseName;
this.Edition = restorableDroppedSqlPool.Edition;
this.MaxSizeBytes = restorableDroppedSqlPool.MaxSizeBytes;
this.ServiceLevelObjective = restorableDroppedSqlPool.ServiceLevelObjective;
this.ElasticPoolName = restorableDroppedSqlPool.ElasticPoolName;
this.CreationDate = restorableDroppedSqlPool.CreationDate;
this.DeletionDate = restorableDroppedSqlPool.DeletionDate;
this.EarliestRestoreDate = restorableDroppedSqlPool.EarliestRestoreDate;
}

//
// Summary:
// Gets the geo-location where the resource lives
public string Location { get; }

//
// Summary:
// Gets the name of the database
public string SqlpoolName { get; }

//
// Summary:
// Gets the edition of the database
public string Edition { get; }

//
// Summary:
// Gets the max size in bytes of the database
public string MaxSizeBytes { get; }

//
// Summary:
// Gets the service level objective name of the database

public string ServiceLevelObjective { get; }

//
// Summary:
// Gets the elastic pool name of the database

public string ElasticPoolName { get; }

//
// Summary:
// Gets the creation date of the database (ISO8601 format)
public DateTime? CreationDate { get; }

//
// Summary:
// Gets the deletion date of the database (ISO8601 format)
public DateTime? DeletionDate { get; }

//
// Summary:
// Gets the earliest restore date of the database (ISO8601 format)
public DateTime? EarliestRestoreDate { get; }
}
}
Loading