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 1 commit
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
1 change: 1 addition & 0 deletions src/Synapse/Synapse/Az.Synapse.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ CmdletsToExport = 'Get-AzSynapseSparkJob', 'Stop-AzSynapseSparkJob',
'Get-AzSynapseSqlDatabase', 'New-AzSynapseSqlDatabase',
'Remove-AzSynapseSqlDatabase', 'Update-AzSynapseSqlDatabase',
'Test-AzSynapseSqlDatabase', 'Get-AzSynapseIntegrationRuntime',
'Get-AzSynapseSqlPoolGeoBackup',
'Get-AzSynapseIntegrationRuntimeKey',
'Get-AzSynapseIntegrationRuntimeMetric',
'Get-AzSynapseIntegrationRuntimeNode',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlDataBaseGeoBackup,
DefaultParameterSetName = GetByNameParameterSet)]
[OutputType(typeof(PSBackupModel))]
public class GetAzureSynapseSqlPoolGeoBackup : 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.SqlDataBaseGeoBackup,
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 (string.IsNullOrEmpty(this.ResourceGroupName))
{
this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
}

if (MyInvocation.BoundParameters.ContainsKey("Name") && !WildcardPattern.ContainsWildcardCharacters(Name))
zesluo marked this conversation as resolved.
Show resolved Hide resolved
{
var results = this.SynapseAnalyticsClient.GetRecoverableManagedDatabase(ResourceGroupName, WorkspaceName, Name).ConfigureAwait(true).GetAwaiter().GetResult();
WriteObject(results, true);
}
else
{
var results = this.SynapseAnalyticsClient.ListRecoverableManagedDatabases(this.ResourceGroupName, this.WorkspaceName);
WriteObject(results, true);
}
}
}
}
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 SqlDataBaseGeoBackup = "Microsoft.Synapse/workspaces/SqlDataBaseGeoBackup";
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
34 changes: 34 additions & 0 deletions src/Synapse/Synapse/Models/PSBackupModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.Management.Synapse.Models;

namespace Microsoft.Azure.Commands.Synapse.Models
{
public class PSBackupModel : ProxyResource
zesluo marked this conversation as resolved.
Show resolved Hide resolved
{
public PSBackupModel(RecoverableSqlPool recoverableSqlPool)
zesluo marked this conversation as resolved.
Show resolved Hide resolved
{
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; }
//
// Summary:
// Gets the elastic pool name of the database
public string ElasticPoolName { get; set; }
//
// Summary:
// Gets the last available backup date of the database (ISO8601 format)
public DateTime? LastAvailableBackupDate { get; set; }
}
}

39 changes: 39 additions & 0 deletions src/Synapse/Synapse/Models/SynapseAnalyticsManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,45 @@ public SqlDatabase CreateSqlDatabase(string resourceGroupName, string workspaceN
}
}

public virtual async Task<PSBackupModel> GetRecoverableManagedDatabase(string resourceGroupName, string workspaceName, string sqlPoolName)
zesluo marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
var taskGetResults = Task.Run(
async () => await _synapseManagementClient.WorkspaceManagedSqlServerRecoverableSqlpools.GetWithHttpMessagesAsync(resourceGroupName, workspaceName, sqlPoolName));
await Task.WhenAll(taskGetResults);

return new PSBackupModel(taskGetResults.Result.Body);
}
catch (ErrorContractException ex)
{
throw GetSynapseException(ex);
}
}

public virtual async Task<List<PSBackupModel>> ListRecoverableManagedDatabases(string resourceGroupName, string workspaceName)
zesluo marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
var taskGetResults = (IPage<PSBackupModel>)Task.Run(
async () => await _synapseManagementClient.WorkspaceManagedSqlServerRecoverableSqlpools.ListWithHttpMessagesAsync(resourceGroupName, workspaceName));
await Task.WhenAll((IEnumerable<Task>)taskGetResults);

var results = new List<PSBackupModel>();

foreach (var res in taskGetResults.ToList())
{
results.Add(res);
}

return results;
}
catch (ErrorContractException ex)
{
throw GetSynapseException(ex);
}
}

internal SqlDatabase GetSqlDatabase(string resourceGroupName, string workspaceName, string sqlDatabaseName)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/Synapse/Synapse/Models/SynapseConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static class SynapseConstants

public const string SqlPool = nameof(SqlPool);

public const string SqlDataBaseGeoBackup = nameof(SqlDataBaseGeoBackup);

public const string SqlDatabase = nameof(SqlDatabase);

public const string SparkPoolName = nameof(SparkPoolName);
Expand Down