Skip to content

Commit

Permalink
[Synapse] Add SQL pool related cmdlets (#13243)
Browse files Browse the repository at this point in the history
Force merge after CI passed

* add new cmdlets for sql pool

* add test for sql pool

* update help docs

* update change log

* fix for test

Co-authored-by: Wan Yang <[email protected]>
Co-authored-by: Yunchi Wang <[email protected]>
Co-authored-by: Dingmeng Xue <[email protected]>
Co-authored-by: Jin Lei <[email protected]>
  • Loading branch information
5 people authored Oct 21, 2020
1 parent 40879b9 commit 9f33a5e
Show file tree
Hide file tree
Showing 23 changed files with 8,214 additions and 1,399 deletions.
26 changes: 26 additions & 0 deletions src/Synapse/Synapse.Test/ScenarioTests/SqlPoolTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Test-SynapseSqlPool
$resourceGroupName = (Get-ResourceGroupName),
$workspaceName = (Get-SynapseWorkspaceName),
$sqlPoolName = (Get-SynapseSqlPoolName),
$restoreFromSqlPoolName = 'dwtestbackup',
$sqlPoolPerformanceLevel = 'DW200c'
)

Expand Down Expand Up @@ -90,6 +91,31 @@ function Test-SynapseSqlPool

# Verify that it is gone by trying to get it again
Assert-Throws {Get-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName}

# Get restore point
[array]$restorePoint = Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $restoreFromSqlPoolName

Assert-AreEqual "DISCRETE" $restorePoint[0].RestorePointType

# Restore SqlPool
$sqlPoolRestored = Restore-AzSynapseSqlPool -FromRestorePoint -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -SourceWorkspaceName $workspaceName -SourceSqlPoolName $restoreFromSqlPoolName -PerformanceLevel $sqlPoolPerformanceLevel

Assert-AreEqual $sqlPoolName $sqlPoolRestored.Name
Assert-AreEqual "Microsoft.Synapse/Workspaces/sqlPools" $sqlPoolRestored.Type
Assert-True {$sqlPoolRestored.Id -like "*$resourceGroupName*"}

# Suspend SqlPool
$sqlPoolSuspended = Suspend-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName

Assert-AreEqual "Paused" $sqlPoolSuspended.Status

# Resume SqlPool
$sqlPoolResumed = Resume-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName

Assert-AreEqual "Online" $sqlPoolResumed.Status

# Delete SqlPool
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -PassThru} "Remove SqlPool failed."
}
finally
{
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Synapse/Synapse/Az.Synapse.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ CmdletsToExport = 'Get-AzSynapseSparkJob', 'Stop-AzSynapseSparkJob',
'New-AzSynapseWorkspace', 'Remove-AzSynapseWorkspace',
'Update-AzSynapseWorkspace', 'Get-AzSynapseSqlPool',
'New-AzSynapseSqlPool', 'Remove-AzSynapseSqlPool',
'Suspend-AzSynapseSqlPool', 'Resume-AzSynapseSqlPool',
'Get-AzSynapseSqlPoolRestorePoint', 'Restore-AzSynapseSqlPool',
'Update-AzSynapseSqlPool', 'Test-AzSynapseWorkspace',
'Test-AzSynapseSparkPool', 'Test-AzSynapseSqlPool',
'New-AzSynapseFirewallRule', 'Remove-AzSynapseFirewallRule',
Expand Down
7 changes: 7 additions & 0 deletions src/Synapse/Synapse/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
- Add `Remove-AzSynapseDataset` cmdlet
- Add `Set-AzSynapseDataset` cmdlet
- Add `New-AzSynapseDataset` cmdlet
* Removed parameter sets related 'create from backup' and 'create from restore point' from the `New-AzSynapseSqlPool` cmdlet
* Removed parameter sets related 'pause' and 'resume' from the `Update-AzSynapseSqlPool`
* Added support for operation of Synapse Sql pool
- Add `Get-AzSynapseSqlPoolRestorePoint` cmdlet
- Add `Restore-AzSynapseSqlPool` cmdlet
- Add `Resume-AzSynapseSqlPool` cmdlet
- Add `Suspend-AzSynapseSqlPool` cmdlet

## Version 0.2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPool + SynapseConstants.RestorePoint,
DefaultParameterSetName = GetByNameParameterSet)]
[OutputType(typeof(PSRestorePoint))]
public class GetAzureSynapseSqlPoolRestorePoint : SynapseManagementCmdletBase
{
private const string GetByNameParameterSet = "GetByNameParameterSet";
private const string GetByParentObjectParameterSet = "GetByParentObjectParameterSet";
private const string GetByInputObjectParameterSet = "GetByInputObjectParameterSet";
private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet";

[Parameter(Mandatory = false, 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 = true, ParameterSetName = GetByNameParameterSet, HelpMessage = HelpMessages.SqlPoolName)]
[Parameter(Mandatory = true, ParameterSetName = GetByParentObjectParameterSet, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(ValueFromPipeline = true, ParameterSetName = GetByParentObjectParameterSet,
Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)]
[ValidateNotNull]
public PSSynapseWorkspace WorkspaceObject { get; set; }

[Parameter(ValueFromPipeline = true, ParameterSetName = GetByInputObjectParameterSet, Mandatory = true,
HelpMessage = HelpMessages.SqlPoolObject)]
[ValidateNotNull]
public PSSynapseSqlPool InputObject { get; set; }

[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = GetByResourceIdParameterSet,
Mandatory = true, HelpMessage = HelpMessages.SqlPoolResourceId)]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.WorkspaceObject))
{
this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
this.WorkspaceName = this.WorkspaceObject.Name;
}

if (this.IsParameterBound(c => c.InputObject))
{
var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.Name = resourceIdentifier.ResourceName;
}

if (this.IsParameterBound(c => c.ResourceId))
{
var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.Name = resourceIdentifier.ResourceName;
}

if (string.IsNullOrEmpty(this.ResourceGroupName))
{
this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
}

var result = this.SynapseAnalyticsClient.ListSqlPoolRestorePoints(this.ResourceGroupName, this.WorkspaceName, this.Name)
.Select(element => new PSRestorePoint(element));
WriteObject(result, true);
}
}
}
Loading

0 comments on commit 9f33a5e

Please sign in to comment.