From 04d572e256c10e032adde63571995a8127cd321c Mon Sep 17 00:00:00 2001 From: Milan Brkic Date: Tue, 12 Jan 2021 03:43:11 +0100 Subject: [PATCH] [SQL] [LogReplay] Make Start-AzSqlInstanceDatabaseLogReplay synchronous command (#13903) * initial * remove model * Add AsJob Switch parameter so user can execute as background process as this is a long-running op * change log updated * regenerated help files Co-authored-by: Milan Brkic --- src/Sql/Sql/ChangeLog.md | 1 + .../StartAzureSqlInstanceDatabaseLogReplay.cs | 9 +++++++-- .../AzureSqlManagedDatabaseAdapter.cs | 5 +++-- .../AzureSqlManagedDatabaseCommunicator.cs | 4 ++-- .../Start-AzSqlInstanceDatabaseLogReplay.md | 19 +++++++++++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Sql/Sql/ChangeLog.md b/src/Sql/Sql/ChangeLog.md index 43a7c0a5deb1..4fed76483772 100644 --- a/src/Sql/Sql/ChangeLog.md +++ b/src/Sql/Sql/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Made `Start-AzSqlInstanceDatabaseLogReplay` cmdlet synchronous, added -AsJob flag ## Version 2.14.0 * Fixed parameter description for `InstanceFailoverGroup` command. diff --git a/src/Sql/Sql/ManagedDatabase/Cmdlet/StartAzureSqlInstanceDatabaseLogReplay.cs b/src/Sql/Sql/ManagedDatabase/Cmdlet/StartAzureSqlInstanceDatabaseLogReplay.cs index 6e9beecc37fd..acb3ee2abf8d 100644 --- a/src/Sql/Sql/ManagedDatabase/Cmdlet/StartAzureSqlInstanceDatabaseLogReplay.cs +++ b/src/Sql/Sql/ManagedDatabase/Cmdlet/StartAzureSqlInstanceDatabaseLogReplay.cs @@ -69,6 +69,12 @@ public class StartAzureSqlInstanceDatabaseLogReplay : AzureSqlManagedDatabaseLog [PSArgumentCompleter("SQL_Latin1_General_CP1_CI_AS", "Latin1_General_100_CS_AS_SC")] public string Collation { get; set; } + /// + /// Gets or sets whether or not to run this cmdlet in the background as a job + /// + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + /// /// Get the entities from the service /// @@ -128,8 +134,7 @@ protected override AzureSqlManagedDatabaseModel ApplyUserInputToModel(AzureSqlMa protected override AzureSqlManagedDatabaseModel PersistChanges(AzureSqlManagedDatabaseModel entity) { - ModelAdapter.StartManagedDatabaseLogReplay(entity); - return entity; + return ModelAdapter.StartManagedDatabaseLogReplay(entity); } } } diff --git a/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseAdapter.cs b/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseAdapter.cs index de26700a604f..1909cc2c4ede 100644 --- a/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseAdapter.cs +++ b/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseAdapter.cs @@ -182,7 +182,7 @@ public string GetDeletedManagedDatabaseResourceId(string resourceGroupName, stri /// Start the managed database log replay /// /// The parameters for log replay - public void StartManagedDatabaseLogReplay(AzureSqlManagedDatabaseModel parameters) + public AzureSqlManagedDatabaseModel StartManagedDatabaseLogReplay(AzureSqlManagedDatabaseModel parameters) { var model = new Management.Sql.Models.ManagedDatabase() { @@ -194,7 +194,8 @@ public void StartManagedDatabaseLogReplay(AzureSqlManagedDatabaseModel parameter StorageContainerUri = parameters.StorageContainerUri, StorageContainerSasToken = parameters.StorageContainerSasToken }; - Communicator.StartLogReplay(parameters.ResourceGroupName, parameters.ManagedInstanceName, parameters.Name, model); + var response = Communicator.StartLogReplay(parameters.ResourceGroupName, parameters.ManagedInstanceName, parameters.Name, model); + return CreateManagedDatabaseModelFromResponse(parameters.ResourceGroupName, parameters.ManagedInstanceName, response); } /// diff --git a/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseCommunicator.cs b/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseCommunicator.cs index 5520656d6062..627b3b9800ec 100644 --- a/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseCommunicator.cs +++ b/src/Sql/Sql/ManagedDatabase/Services/AzureSqlManagedDatabaseCommunicator.cs @@ -153,9 +153,9 @@ public void CompleteLogReplay(string resourceGroupName, string managedInstanceNa /// The name of the Azure SQL Managed Instance /// The name of the Azure SQL Managed database /// Model describing the managed database log replay request - public Task StartLogReplay(string resourceGroupName, string managedInstanceName, string databaseName, Management.Sql.Models.ManagedDatabase model) + public Management.Sql.Models.ManagedDatabase StartLogReplay(string resourceGroupName, string managedInstanceName, string databaseName, Management.Sql.Models.ManagedDatabase model) { - return GetCurrentSqlClient().ManagedDatabases.CreateOrUpdateAsync( + return GetCurrentSqlClient().ManagedDatabases.CreateOrUpdate( resourceGroupName, managedInstanceName, databaseName, diff --git a/src/Sql/Sql/help/Start-AzSqlInstanceDatabaseLogReplay.md b/src/Sql/Sql/help/Start-AzSqlInstanceDatabaseLogReplay.md index df0ffe1e7b1a..318c9d350a0d 100644 --- a/src/Sql/Sql/help/Start-AzSqlInstanceDatabaseLogReplay.md +++ b/src/Sql/Sql/help/Start-AzSqlInstanceDatabaseLogReplay.md @@ -15,7 +15,7 @@ Starts a Log Replay service with the given parameters. ### LogReplayInstanceDatabaseFromInputParameters (Default) ``` Start-AzSqlInstanceDatabaseLogReplay -StorageContainerUri -StorageContainerSasToken - [-AutoCompleteRestore] [-LastBackupName ] [-Collation ] [-Name] + [-AutoCompleteRestore] [-LastBackupName ] [-Collation ] [-AsJob] [-Name] [-InstanceName] [-ResourceGroupName] [-PassThru] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -23,7 +23,7 @@ Start-AzSqlInstanceDatabaseLogReplay -StorageContainerUri -StorageConta ### LogReplayInstanceDatabaseFromAzureSqlManagedDatabaseModelInstanceDefinition ``` Start-AzSqlInstanceDatabaseLogReplay -StorageContainerUri -StorageContainerSasToken - [-AutoCompleteRestore] [-LastBackupName ] [-Collation ] [-PassThru] + [-AutoCompleteRestore] [-LastBackupName ] [-Collation ] [-AsJob] [-PassThru] [-InputObject] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -54,6 +54,21 @@ This command will create new managed database and will start restoring backups f ## PARAMETERS +### -AsJob +Run cmdlet in the background + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -AutoCompleteRestore The indicator whether or not to auto-complete restore upon completion.