Skip to content

Remove-AzSynapseSqlPoolRestorePoint #13412

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 11 commits into from
Nov 27, 2020
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
5 changes: 5 additions & 0 deletions src/Synapse/Synapse.Test/ScenarioTests/SqlPoolTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function Test-SynapseSqlPool

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

# Delete restore point
$RestorePointCreationDate = Get-Date $restorePoint[-1].RestorePointCreationDate

Assert-True {Remove-AzSynapseSqlPoolRestorePoint -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -SqlPoolName $restoreFromSqlPoolName -RestorePointCreationDate $RestorePointCreationDate -PassThru -Force} "Remove Restore Point failed."

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

Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Synapse/Synapse/Az.Synapse.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ CmdletsToExport = 'Get-AzSynapseSparkJob', 'Stop-AzSynapseSparkJob',
'Get-AzSynapseSqlVulnerabilityAssessmentSetting',
'Update-AzSynapseSqlVulnerabilityAssessmentSetting',
'Reset-AzSynapseSqlVulnerabilityAssessmentSetting',
'Remove-AzSynapseSqlPoolRestorePoint',
'Update-AzSynapseSqlPool', 'Test-AzSynapseWorkspace',
'Test-AzSynapseSparkPool', 'Test-AzSynapseSqlPool',
'New-AzSynapseFirewallRule', 'Remove-AzSynapseFirewallRule',
Expand Down
3 changes: 2 additions & 1 deletion src/Synapse/Synapse/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Upcoming Release
* Added support for operation of Synapse SQL Pool Restore Point
- Add `New-AzSynapseSqlPoolRestorePoint` cmdlet
- Add `Remove-AzSynapseSqlPoolRestorePoint` cmdlet
* Added support for operation of Auditing settings in Workspace-level and SqlPool-level
- Add `Set-AzSynapseSqlAuditSetting` cmdlet
- Add `Get-AzSynapseSqlAuditSetting` cmdlet
Expand All @@ -39,7 +40,7 @@
- Add `Set-AzSynapseSqlActiveDirectoryAdministrator` cmdlet
- Add `Get-AzSynapseSqlActiveDirectoryAdministrator` cmdlet
- Add `Remove-AzSynapseSqlActiveDirectoryAdministrator` cmdlet
* Fix Null Reference Exception when submit spark job.
* Fixed Null Reference Exception when submit spark job.

## Version 0.4.0
* Add `-Force` to all Remove cmdlets
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.Properties;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;
using System;

namespace Microsoft.Azure.Commands.Synapse.Commands
{
[Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPool+ SynapseConstants.RestorePoint, DefaultParameterSetName = DeleteByNameParameterSet, SupportsShouldProcess = true)]
[OutputType(typeof(bool))]
public class RemoveAzureSynapseSqlPoolRestorePoint : SynapseManagementCmdletBase
{
private const string DeleteByNameParameterSet = "DeleteByNameParameterSet";
private const string DeleteByParentObjectParameterSet = "DeleteByParentObjectParameterSet";
private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet";
private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet";

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

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

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

[Parameter(Mandatory = true, ParameterSetName = DeleteByParentObjectParameterSet, HelpMessage = HelpMessages.SqlPoolRestorePointName)]
[Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet, HelpMessage = HelpMessages.SqlPoolRestorePointName)]
[ResourceNameCompleter(
ResourceTypes.SqlPoolRestorePoint,
nameof(ResourceGroupName),
nameof(WorkspaceName),
nameof(SqlPoolName))]
[ValidateNotNullOrEmpty]
public DateTime RestorePointCreationDate { get; set; }

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

[Parameter(ValueFromPipeline = true, ParameterSetName = DeleteByInputObjectParameterSet,
Mandatory = true, HelpMessage = HelpMessages.SqlPoolRestorePointObject)]
[ValidateNotNull]
public PSRestorePoint InputObject { get; set; }

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

[Parameter(Mandatory = false, HelpMessage = HelpMessages.PassThru)]
public SwitchParameter PassThru { get; set; }

[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
public SwitchParameter AsJob { get; set; }

[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
public SwitchParameter Force { get; set; }

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.SqlPoolObject))
{
var resourceIdentifier = new ResourceIdentifier(this.SqlPoolObject.Id);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.SqlPoolName = resourceIdentifier.ResourceName;
}

if (this.IsParameterBound(c => c.InputObject))
{
var dateString = this.InputObject.Id.Substring(this.InputObject.Id.LastIndexOf('/') + 1);
this.RestorePointCreationDate = DateTime.FromFileTime(Convert.ToInt64(dateString));
var resourceId = this.InputObject.Id.Substring(0, this.InputObject.Id.Substring(0, this.InputObject.Id.LastIndexOf("/")).LastIndexOf("/"));
var resourceIdentifier = new ResourceIdentifier(resourceId);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.SqlPoolName = resourceIdentifier.ResourceName;
}

if (this.IsParameterBound(c => c.ResourceId))
{
var dateString = this.ResourceId.Substring(this.ResourceId.LastIndexOf('/') + 1);
this.RestorePointCreationDate = DateTime.FromFileTime(Convert.ToInt64(dateString));
this.ResourceId = this.ResourceId.Substring(0,this.ResourceId.Substring(0, this.ResourceId.LastIndexOf("/")).LastIndexOf("/"));
var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.SqlPoolName = resourceIdentifier.ResourceName;
}

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

ConfirmAction(
Force.IsPresent,
string.Format(Resources.RemoveSynapseSqlPoolRestorePoint, this.RestorePointCreationDate),
string.Format(Resources.RemovingSynapseSqlPoolRestorePoint, this.RestorePointCreationDate, this.ResourceGroupName, this.WorkspaceName, this.SqlPoolName),
this.RestorePointCreationDate.ToFileTimeUtc().ToString(),
() =>
{
this.SynapseAnalyticsClient.DeleteSqlPoolRestorePoint(this.ResourceGroupName, this.WorkspaceName, this.SqlPoolName, this.RestorePointCreationDate.ToFileTimeUtc().ToString());
if (this.PassThru.IsPresent)
{
WriteObject(true);
}
});
}
}
}
6 changes: 6 additions & 0 deletions src/Synapse/Synapse/Common/HelpMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@ public static class HelpMessages

public const string SqlPoolName = "Name of Synapse SQL pool.";

public const string SqlPoolRestorePointName = "Name of Synapse SQL pool restore point name.";

public const string SqlPoolVersion = "Version of Synapse SQL pool. For example, 2 or 3.";

public const string SqlPoolNewName = "The new name to rename the SQL pool to.";

public const string SqlPoolResourceId = "Resource identifier of Synapse SQL Pool.";

public const string SqlPoolRestorePointResourceId = "Resource identifier of Synapse SQL Pool Restore Point.";

public const string SqlPoolObject = "SQL pool input object, usually passed through the pipeline.";

public const string SqlPoolRestorePointObject = "SQL pool restore point input object, usually passed through the pipeline.";

public const string SuspendSqlPool = "Indicates to pause the SQL pool";

public const string ResumeSqlPool = "Indicates to resume the SQL pool";
Expand Down
1 change: 1 addition & 0 deletions src/Synapse/Synapse/Common/ResourceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public static class ResourceTypes
public const string Workspace = "Microsoft.Synapse/workspaces";
public const string SparkPool = "Microsoft.Synapse/workspaces/bigDataPools";
public const string SqlPool = "Microsoft.Synapse/workspaces/sqlPools";
public const string SqlPoolRestorePoint = "Microsoft.Synapse/workspaces/sqlPools/sqlPoolRestorePoints";
public const string RecoverableSqlPool = "Microsoft.Synapse/workspaces/recoverableSqlPools";
public const string StorageAccount = "Microsoft.Storage/storageAccounts";
public const string SqlDatabase = "Microsoft.Sql/servers/databases";
Expand Down
13 changes: 10 additions & 3 deletions src/Synapse/Synapse/Models/SqlPool Backup/PSRestorePoint.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Microsoft.Azure.Management.Synapse.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Azure.Commands.Synapse.Models
{
public class PSRestorePoint
public class PSRestorePoint : PSSynapseResource
{
public PSRestorePoint(RestorePoint restorePoint)
{
Expand All @@ -14,6 +12,9 @@ public PSRestorePoint(RestorePoint restorePoint)
this.EarliestRestoreDate = restorePoint.EarliestRestoreDate;
this.RestorePointCreationDate = restorePoint.RestorePointCreationDate;
this.RestorePointLabel = restorePoint.RestorePointLabel;
this.Id = restorePoint.Id;
this.Name = restorePoint.Name;
this.Type = restorePoint.Type;
}

public string Location { get; }
Expand All @@ -25,5 +26,11 @@ public PSRestorePoint(RestorePoint restorePoint)
public DateTime? RestorePointCreationDate { get; }

public string RestorePointLabel { get; }

public new string Id { get; set; }

public new string Name { get; set; }

public new string Type { get; set; }
}
}
41 changes: 40 additions & 1 deletion src/Synapse/Synapse/Models/SynapseAnalyticsManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,12 +1537,51 @@ public RestorePoint CreateSqlPoolRestorePoint(string resourceGroupName, string w

return this._synapseManagementClient.SqlPoolRestorePoints.Create(resourceGroupName, workspaceName, sqlPoolName, parameters);
}
catch (CloudException ex)
catch (ErrorContractException ex)
{
throw GetSynapseException(ex);
}
}

public void DeleteSqlPoolRestorePoint(string resourceGroupName, string workspaceName, string sqlPoolName, string sqlPoolRestorePointCreationDate)
{
try
{
if (string.IsNullOrEmpty(resourceGroupName))
{
resourceGroupName = GetResourceGroupByWorkspaceName(workspaceName);
}

if (!TestSqlPoolRestorePoint(resourceGroupName, workspaceName, sqlPoolName, sqlPoolRestorePointCreationDate))
{
throw new InvalidOperationException(string.Format(Properties.Resources.SqlPoolRestorePointDoesNotExist, sqlPoolRestorePointCreationDate));
}

this._synapseManagementClient.SqlPoolRestorePoints.Delete(resourceGroupName, workspaceName, sqlPoolName, sqlPoolRestorePointCreationDate);
}
catch (ErrorContractException ex)
{
throw GetSynapseException(ex);
}
}

public bool TestSqlPoolRestorePoint(string resourceGroupName, string workspaceName, string sqlPoolName, string sqlPoolRestorePointName)
{
try
{
RestorePoint respoint = this._synapseManagementClient.SqlPoolRestorePoints.Get(resourceGroupName,
workspaceName,
sqlPoolName,
sqlPoolRestorePointName);

return respoint != null;
}
catch (NotFoundException)
{
return false;
}
}

#endregion

#region SQL Pool V3 operations
Expand Down
27 changes: 27 additions & 0 deletions src/Synapse/Synapse/Properties/Resources.Designer.cs

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

9 changes: 9 additions & 0 deletions src/Synapse/Synapse/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,13 @@ Are you sure you want to continue?</value>
<data name="ComfirmToRemoveSqlActiveDirectoryAdministrator" xml:space="preserve">
<value>Are you sure you want to remove the Azure Sql Server Active Directory Administrator on workspace '{0}'?</value>
</data>
<data name="RemovingSynapseSqlPoolRestorePoint" xml:space="preserve">
<value>Deleting SQL pool Restore Point '{0}' in resource group '{1}' , workspace '{2}', under Sql Pool '{3}'.</value>
</data>
<data name="SqlPoolRestorePointDoesNotExist" xml:space="preserve">
<value>Cannot perform the requested operation because the specified Restore Point '{0}' does not exist.</value>
</data>
<data name="RemoveSynapseSqlPoolRestorePoint" xml:space="preserve">
<value>Are you sure you want to remove Synapse Sql Pool Restore Point '{0}'?</value>
</data>
</root>
Loading