From 7139b04bcf8087b4206892feb2cad2d9984c82ce Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Tue, 19 May 2020 02:55:32 -0700 Subject: [PATCH 1/8] add private link parameters to data sync cmdlets --- .../Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs | 8 ++ .../Data Sync/Cmdlet/NewAzureSqlSyncMember.cs | 30 ++++++++ .../Cmdlet/UpdateAzureSqlSyncGroup.cs | 11 +++ .../Cmdlet/UpdateAzureSqlSyncMember.cs | 33 +++++++- .../Data Sync/Model/AzureSqlSyncGroupModel.cs | 6 ++ .../AzureSqlSyncGroupSchemaColumnModel.cs | 8 +- .../Model/AzureSqlSyncGroupSchemaModel.cs | 4 +- .../AzureSqlSyncGroupSchemaTableModel.cs | 8 +- .../Model/AzureSqlSyncMemberModel.cs | 12 +++ .../Services/AzureSqlDataSyncAdapter.cs | 75 ++++++++----------- .../Services/AzureSqlDataSyncCommunicator.cs | 44 +++++++---- src/Sql/Sql/Properties/Resources.Designer.cs | 9 +++ src/Sql/Sql/Properties/Resources.resx | 3 + 13 files changed, 181 insertions(+), 70 deletions(-) diff --git a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs index 048a9548b1c0..5084d60d1e97 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs @@ -95,6 +95,12 @@ public class NewAzureSqlSyncGroup : AzureSqlSyncGroupCmdletBase [ValidateNotNullOrEmpty] public string SchemaFile { get; set; } + /// + /// Gets or sets if private link should be used + /// + [Parameter(Mandatory = false, HelpMessage = "Use a private link connection when connecting to the hub of this sync group.")] + public SwitchParameter UsePrivateLinkConnection { get; set; } + /// /// The id of database used to store sync related metadata /// @@ -153,6 +159,8 @@ protected override IEnumerable ApplyUserInputToModel(IEn newModel.IntervalInSeconds = this.IntervalInSeconds; } + newModel.UsePrivateLinkConnection = UsePrivateLinkConnection.IsPresent; + if (MyInvocation.BoundParameters.ContainsKey("SyncDatabaseResourceGroupName") && MyInvocation.BoundParameters.ContainsKey("SyncDatabaseServerName") && MyInvocation.BoundParameters.ContainsKey("SyncDatabaseName")) diff --git a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs index e3a96dce1ee8..837b48eecf9d 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs @@ -146,6 +146,24 @@ public class NewAzureSqlSyncMember : AzureSqlSyncMemberCmdletBase [ValidateSet("Bidirectional", "OneWayMemberToHub", "OneWayHubToMember", IgnoreCase = true)] public string SyncDirection { get; set; } + /// + /// Gets or sets a value indicating whether to use private link connection + /// + [Parameter(Mandatory = false, HelpMessage = "Use a private link connection when connecting to this sync member.")] + public SwitchParameter UsePrivateLinkConnection { get; set; } + + /// + /// Gets or sets the sync member resource Id + /// + /// + /// The sync member database id (only for sync member using Azure SQL Database), e.g. "subscriptions/{subscriptionId}/resourceGroups/{syncDatabaseResourceGroup01}/servers/{syncMemberServer01}/databases/{syncMemberDatabaseName01}" + /// + /// + /// This needs to be a sync member sql azure database id (i.e. full arm uri) so that we can validate calling user's R/W access to this database via RBAC. + /// + [Parameter(Mandatory = false, HelpMessage = "The resource ID for the sync member database, used if UsePrivateLinkConnection is set to true.")] + public string SyncMemberAzureDatabaseResourceId { get; set; } + /// /// The id of the sync agent which is connected by the on-premises SQL server. /// @@ -198,6 +216,18 @@ protected override IEnumerable ApplyUserInputToModel(IE SyncDirection = this.SyncDirection, MemberDatabaseType = this.MemberDatabaseType }; + + if (UsePrivateLinkConnection.IsPresent) + { + if (!MyInvocation.BoundParameters.ContainsKey(nameof(SyncMemberAzureDatabaseResourceId))) + { + throw new PSArgumentException( + Microsoft.Azure.Commands.Sql.Properties.Resources.SyncMemberIdRequired, nameof(SyncMemberAzureDatabaseResourceId)); + } + + newModel.UsePrivateLinkConnection = true; + newModel.SyncMemberAzureDatabaseResourceId = this.SyncMemberAzureDatabaseResourceId; + } if(ParameterSetName == AzureSqlSet) { diff --git a/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncGroup.cs b/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncGroup.cs index f83d3bb89fa5..4c3f4f4f0039 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncGroup.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncGroup.cs @@ -56,6 +56,12 @@ public class UpdateAzureSqlSyncGroup : AzureSqlSyncGroupCmdletBase [Parameter(Mandatory = false, HelpMessage = "The path of the schema file.")] public string SchemaFile { get; set; } + /// + /// Gets or sets if private link should be used + /// + [Parameter(Mandatory = false, HelpMessage = "Whether to use a private link connection when connecting to the hub of this sync group.")] + public bool UsePrivateLinkConnection { get; set; } + /// /// Get the entities from the service /// @@ -81,6 +87,11 @@ protected override IEnumerable ApplyUserInputToModel(IEn newModel.IntervalInSeconds = this.IntervalInSeconds; } + if (MyInvocation.BoundParameters.ContainsKey(nameof(UsePrivateLinkConnection))) + { + newModel.UsePrivateLinkConnection = this.UsePrivateLinkConnection; + } + if (MyInvocation.BoundParameters.ContainsKey("DatabaseCredential")) { newModel.HubDatabaseUserName = this.DatabaseCredential.UserName; diff --git a/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncMember.cs b/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncMember.cs index 972b73ba7da6..0301ba307d07 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncMember.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/UpdateAzureSqlSyncMember.cs @@ -40,10 +40,27 @@ public class UpdateAzureSqlSyncMember : AzureSqlSyncMemberCmdletBase /// /// Gets or sets the credential (username and password) of the Azure SQL Database. /// - [Parameter(Mandatory = true, HelpMessage = "The credential (username and password) of the Azure SQL Database.")] - [ValidateNotNull] + [Parameter(Mandatory = false, HelpMessage = "The credential (username and password) of the Azure SQL Database.")] public PSCredential MemberDatabaseCredential { get; set; } + /// + /// Gets or sets a value indicating whether to use private link connection + /// + [Parameter(Mandatory = false, HelpMessage = "Whether to use private link when connecting to this sync member.")] + public bool? UsePrivateLinkConnection { get; set; } + + /// + /// Gets or sets the sync member resource Id + /// + /// + /// The sync member database id (only for sync member using Azure SQL Database), e.g. "subscriptions/{subscriptionId}/resourceGroups/{syncDatabaseResourceGroup01}/servers/{syncMemberServer01}/databases/{syncMemberDatabaseName01}" + /// + /// + /// This needs to be a sync member sql azure database id (i.e. full arm uri) so that we can validate calling user's R/W access to this database via RBAC. + /// + [Parameter(Mandatory = false, HelpMessage = "The resource ID for the sync member database, used if UsePrivateLinkConnection is set to true.")] + public string SyncMemberAzureDatabaseResourceId { get; set; } + /// /// Get the entities from the service /// @@ -64,6 +81,18 @@ protected override IEnumerable ApplyUserInputToModel(IE { AzureSqlSyncMemberModel newModel = model.First(); + if (MyInvocation.BoundParameters.ContainsKey(nameof(UsePrivateLinkConnection))) + { + if (this.UsePrivateLinkConnection.GetValueOrDefault() && !MyInvocation.BoundParameters.ContainsKey(nameof(SyncMemberAzureDatabaseResourceId))) + { + throw new PSArgumentException( + Microsoft.Azure.Commands.Sql.Properties.Resources.SyncMemberIdRequired, nameof(SyncMemberAzureDatabaseResourceId)); + } + + newModel.UsePrivateLinkConnection = this.UsePrivateLinkConnection; + newModel.SyncMemberAzureDatabaseResourceId = this.SyncMemberAzureDatabaseResourceId; + } + if (MyInvocation.BoundParameters.ContainsKey("MemberDatabaseCredential")) { newModel.MemberDatabaseUserName = this.MemberDatabaseCredential.UserName; diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs index ec6bfcdff9f8..efc671c8bc07 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs @@ -88,6 +88,11 @@ public class AzureSqlSyncGroupModel /// public AzureSqlSyncGroupSchemaModel Schema { get; set; } + /// + /// Gets or sets if private link connection should be used + /// + public bool? UsePrivateLinkConnection { get; set; } + /// /// Construct AzureSqlSyncGroupModel /// @@ -117,6 +122,7 @@ public AzureSqlSyncGroupModel(string resourceGroupName, string serverName, strin SyncState = syncGroup.Properties.SyncState; LastSyncTime = syncGroup.Properties.LastSyncTime; Schema = syncGroup.Properties.Schema == null ? null : new AzureSqlSyncGroupSchemaModel(syncGroup.Properties.Schema); + UsePrivateLinkConnection = syncGroup.Properties.UsePrivateLinkConnection; } } } diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs index 18752ac38b37..f4fa1a452119 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs @@ -14,7 +14,7 @@ using System; using System.Collections.Generic; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; namespace Microsoft.Azure.Commands.Sql.DataSync.Model { @@ -50,16 +50,16 @@ public AzureSqlSyncGroupSchemaColumnModel() /// Construct AzureSqlSyncGroupSchemaColumnModel /// /// sync group schema column - public AzureSqlSyncGroupSchemaColumnModel(SyncGroupSchemaColumn column) + public AzureSqlSyncGroupSchemaColumnModel(Management.Sql.LegacySdk.Models.SyncGroupSchemaColumn column) { QuotedName = column != null ? column.QuotedName : null; DataSize = column != null ? column.DataSize : null; DataType = column != null ? column.DataType : null; } - public SyncGroupSchemaColumn ToSyncGroupSchemaColumn() + public SyncGroupSchemaTableColumn ToSyncGroupSchemaColumn() { - return new SyncGroupSchemaColumn + return new SyncGroupSchemaTableColumn { DataSize = this.DataSize, DataType = this.DataType, diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs index 5d61eaf5c93e..ce8ef102b007 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs @@ -14,7 +14,7 @@ using System; using System.Collections.Generic; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; namespace Microsoft.Azure.Commands.Sql.DataSync.Model { @@ -41,7 +41,7 @@ public AzureSqlSyncGroupSchemaModel() } - public AzureSqlSyncGroupSchemaModel(SyncGroupSchema schema) + public AzureSqlSyncGroupSchemaModel(Management.Sql.LegacySdk.Models.SyncGroupSchema schema) { if(schema.Tables != null){ Tables = new List(); diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs index 0df9a9513e71..d1ca29907d0c 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs @@ -14,7 +14,7 @@ using System; using System.Collections.Generic; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; namespace Microsoft.Azure.Commands.Sql.DataSync.Model { @@ -45,7 +45,7 @@ public AzureSqlSyncGroupSchemaTableModel() /// Construct AzureSqlSyncGroupSchemaTableModel /// /// sync group schema table - public AzureSqlSyncGroupSchemaTableModel(SyncGroupSchemaTable table) + public AzureSqlSyncGroupSchemaTableModel(Management.Sql.LegacySdk.Models.SyncGroupSchemaTable table) { if (table != null && table.Columns != null) { @@ -64,10 +64,10 @@ public AzureSqlSyncGroupSchemaTableModel(SyncGroupSchemaTable table) /// The result SyncGroupSchemaTable public SyncGroupSchemaTable ToSyncGroupSchemaTable() { - List syncGroupSchemaColumns = null; + List syncGroupSchemaColumns = null; if (Columns != null) { - syncGroupSchemaColumns = new List(); + syncGroupSchemaColumns = new List(); foreach (var column in Columns) { syncGroupSchemaColumns.Add(column.ToSyncGroupSchemaColumn()); diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs index 408a536ed873..2514359b4f2b 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs @@ -97,6 +97,16 @@ public class AzureSqlSyncMemberModel /// public string SyncState { get; set; } + /// + /// Gets or sets the sync member resource Id + /// + public string SyncMemberAzureDatabaseResourceId { get; set; } + + /// + /// Gets or sets whether to use private link connection + /// + public bool? UsePrivateLinkConnection { get; set; } + /// /// Construct AzureSqlSyncMemberModel /// @@ -128,6 +138,8 @@ public AzureSqlSyncMemberModel(string resourceGroup, string serverName, string d MemberDatabaseUserName = syncMember.Properties.UserName; MemberDatabaseType = syncMember.Properties.DatabaseType == null ? null : syncMember.Properties.DatabaseType.ToString(); SyncState = syncMember.Properties.SyncState; + UsePrivateLinkConnection = syncMember.Properties.UsePrivateLinkConnection; + SyncMemberAzureDatabaseResourceId = syncMember.Properties.SyncMemberAzureDatabaseResourceId; } } } diff --git a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs index 7f5ca1bd3493..727afbb372b2 100644 --- a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs +++ b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs @@ -164,21 +164,18 @@ public void InvokeSyncMemberSchemaRefresh(string resourceGroupName, string serve /// Created AzureSqlSyncGroupModel object internal AzureSqlSyncGroupModel CreateSyncGroup(AzureSqlSyncGroupModel model, string syncDatabaseId) { - var resp = Communicator.CreateSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, syncDatabaseId, new SyncGroupCreateOrUpdateParameters() + var createResp = Communicator.CreateSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, syncDatabaseId, model.SyncGroupName, new Management.Sql.Models.SyncGroup() { - SyncGroupName = model.SyncGroupName, - Properties = new SyncGroupCreateOrUpdateProperties - { - ConflictResolutionPolicy = (ConflictResolutionPolicyType)(model.ConflictResolutionPolicy != null ? Enum.Parse(typeof(ConflictResolutionPolicyType), model.ConflictResolutionPolicy, true) : null), - Interval = model.IntervalInSeconds, - HubDatabaseUserName = model.HubDatabaseUserName, - HubDatabasePassword = model.HubDatabasePassword == null ? null : AzureSqlServerAdapter.Decrypt(model.HubDatabasePassword), - Schema = model.Schema == null ? null : model.Schema.ToSyncGroupSchema(), - }, + ConflictResolutionPolicy = model.ConflictResolutionPolicy, + Interval = model.IntervalInSeconds, + HubDatabaseUserName = model.HubDatabaseUserName, + HubDatabasePassword = model.HubDatabasePassword == null ? null : AzureSqlServerAdapter.Decrypt(model.HubDatabasePassword), + Schema = model.Schema == null ? null : model.Schema.ToSyncGroupSchema(), + UsePrivateLinkConnection = model.UsePrivateLinkConnection, }); // Workaround for Rest API return response value incorrect issue. Remove this line after backend fix is deployed - resp = Communicator.GetSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName); + var resp = Communicator.GetSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName); return CreateSyncGroupModelFromResponse(model.ResourceGroupName, model.ServerName, model.DatabaseName, resp); } @@ -189,20 +186,17 @@ internal AzureSqlSyncGroupModel CreateSyncGroup(AzureSqlSyncGroupModel model, st /// Updated AzureSqlSyncGroupModel object internal AzureSqlSyncGroupModel UpdateSyncGroup(AzureSqlSyncGroupModel model) { - var resp = Communicator.UpdateSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncGroupCreateOrUpdateParameters() + var updateResp = Communicator.UpdateSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName, new Management.Sql.Models.SyncGroup() { - SyncGroupName = model.SyncGroupName, - Properties = new SyncGroupCreateOrUpdateProperties - { - Interval = model.IntervalInSeconds, - HubDatabaseUserName = model.HubDatabaseUserName, - HubDatabasePassword = model.HubDatabasePassword == null ? null: AzureSqlServerAdapter.Decrypt(model.HubDatabasePassword), - Schema = model.Schema == null ? null : model.Schema.ToSyncGroupSchema(), - }, + Interval = model.IntervalInSeconds, + HubDatabaseUserName = model.HubDatabaseUserName, + HubDatabasePassword = model.HubDatabasePassword == null ? null: AzureSqlServerAdapter.Decrypt(model.HubDatabasePassword), + Schema = model.Schema == null ? null : model.Schema.ToSyncGroupSchema(), + UsePrivateLinkConnection = model.UsePrivateLinkConnection, }); // Workaround for Rest API return response value incorrect issue. Remove this line after backend fix is deployed - resp = Communicator.GetSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName); + var resp = Communicator.GetSyncGroup(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName); return CreateSyncGroupModelFromResponse(model.ResourceGroupName, model.ServerName, model.DatabaseName, resp); } @@ -306,32 +300,30 @@ public void RemoveSyncMember(string resourceGroupName, string serverName, string /// Created AzureSqlSyncGroupModel object internal AzureSqlSyncMemberModel CreateSyncMember(AzureSqlSyncMemberModel model, string syncAgentId) { - SyncMemberCreateOrUpdateProperties properties = new SyncMemberCreateOrUpdateProperties() + Management.Sql.Models.SyncMember properties = new Management.Sql.Models.SyncMember() { - SyncDirection = (SyncDirectionEnum?)(model.SyncDirection != null ? Enum.Parse(typeof(SyncDirectionEnum), model.SyncDirection, true) : null), - DatabaseType = (DatabaseTypeEnum)(model.MemberDatabaseType != null ? Enum.Parse(typeof(DatabaseTypeEnum), model.MemberDatabaseType, true) : null) + SyncDirection = model.SyncDirection, + DatabaseType = model.MemberDatabaseType, }; - if (properties.DatabaseType == DatabaseTypeEnum.AzureSqlDatabase) + + if (properties.DatabaseType == DatabaseTypeEnum.AzureSqlDatabase.ToString()) { properties.DatabaseName = model.MemberDatabaseName; properties.ServerName = model.MemberServerName; properties.UserName = model.MemberDatabaseUserName; properties.Password = model.MemberDatabasePassword == null ? null : AzureSqlServerAdapter.Decrypt(model.MemberDatabasePassword); + properties.UsePrivateLinkConnection = model.UsePrivateLinkConnection; + properties.SyncMemberAzureDatabaseResourceId = model.SyncMemberAzureDatabaseResourceId; } else { - properties.SqlServerDatabaseId = model.SqlServerDatabaseId; + properties.SqlServerDatabaseId = model.SqlServerDatabaseId == null ? null : (Guid?)Guid.Parse(model.SqlServerDatabaseId); properties.SyncAgentId = model.SyncAgentId; } - var resp = Communicator.CreateSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, syncAgentId, new SyncMemberCreateOrUpdateParameters() - { - SyncGroupName = model.SyncGroupName, - SyncMemberName = model.SyncMemberName, - Properties = properties, - }); + var createResp = Communicator.CreateSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName, model.SyncMemberName, syncAgentId, properties); // Workaround for Rest API return response value incorrect issue. Remove this line after backend fix is deployed - resp = Communicator.GetSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncMemberGeneralParameters() + var resp = Communicator.GetSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncMemberGeneralParameters() { SyncGroupName = model.SyncGroupName, SyncMemberName = model.SyncMemberName, @@ -348,23 +340,20 @@ internal AzureSqlSyncMemberModel CreateSyncMember(AzureSqlSyncMemberModel model, /// Updated AzureSqlSyncGroupModel object internal AzureSqlSyncMemberModel UpdateSyncMember(AzureSqlSyncMemberModel model) { - SyncMemberCreateOrUpdateProperties properties = new SyncMemberCreateOrUpdateProperties() + Management.Sql.Models.SyncMember properties = new Management.Sql.Models.SyncMember() { - DatabaseType = (DatabaseTypeEnum)(model.MemberDatabaseType != null ? Enum.Parse(typeof(DatabaseTypeEnum), model.MemberDatabaseType, true) : null), + DatabaseType = model.MemberDatabaseType, DatabaseName = model.MemberDatabaseName, ServerName = model.MemberServerName, UserName = model.MemberDatabaseUserName, - Password = model.MemberDatabasePassword == null ? null : AzureSqlServerAdapter.Decrypt(model.MemberDatabasePassword) + Password = model.MemberDatabasePassword == null ? null : AzureSqlServerAdapter.Decrypt(model.MemberDatabasePassword), + UsePrivateLinkConnection = model.UsePrivateLinkConnection, + SyncMemberAzureDatabaseResourceId = model.SyncMemberAzureDatabaseResourceId }; - var resp = Communicator.UpdateSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncMemberCreateOrUpdateParameters() - { - SyncGroupName = model.SyncGroupName, - SyncMemberName = model.SyncMemberName, - Properties = properties - }); + var updateResp = Communicator.UpdateSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.SyncGroupName, model.SyncMemberName, properties); // Workaround for Rest API return response value incorrect issue. Remove this line after backend fix is deployed - resp = Communicator.GetSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncMemberGeneralParameters() + var resp = Communicator.GetSyncMember(model.ResourceGroupName, model.ServerName, model.DatabaseName, new SyncMemberGeneralParameters() { SyncGroupName = model.SyncGroupName, SyncMemberName = model.SyncMemberName, diff --git a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs index 9c3948d744a9..2c1f919f4a6d 100644 --- a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs +++ b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs @@ -16,6 +16,7 @@ using Microsoft.Azure.Management.Sql.LegacySdk.Models; using System.Linq; using System.Collections.Generic; +using Microsoft.Azure.Management.Sql; using Microsoft.Azure.Commands.Common.Authentication; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; @@ -29,7 +30,7 @@ public class AzureSqlDataSyncCommunicator /// /// The Sql client to be used by this end points communicator /// - private static SqlManagementClient LegacySqlClient { get; set; } + private static Management.Sql.LegacySdk.SqlManagementClient LegacySqlClient { get; set; } /// /// Gets or set the Azure subscription @@ -39,7 +40,7 @@ public class AzureSqlDataSyncCommunicator /// /// Gets or sets the Azure profile /// - public IAzureContext Context { get; set; } + public static IAzureContext Context { get; set; } /// /// Creates a communicator for Azure Sql Data Sync @@ -107,19 +108,19 @@ public void RemoveSyncGroup(string resourceGroupName, string serverName, string /// /// Create a sync group /// - public SyncGroup CreateSyncGroup(string resourceGroupName, string serverName, string databaseName, string syncDatabaseId, SyncGroupCreateOrUpdateParameters parameters) + public Management.Sql.Models.SyncGroup CreateSyncGroup(string resourceGroupName, string serverName, string databaseName, string syncDatabaseId, string syncGroupName, Management.Sql.Models.SyncGroup parameters) { - SqlManagementClient client = GetLegacySqlClient(); - parameters.Properties.SyncDatabaseId = syncDatabaseId == null ? null : string.Format("/subscriptions/{0}/{1}", client.Credentials.SubscriptionId, syncDatabaseId); - return client.DataSync.CreateOrUpdateSyncGroup(resourceGroupName, serverName, databaseName, parameters).SyncGroup; + Management.Sql.SqlManagementClient client = GetCurrentSqlClient(); + parameters.SyncDatabaseId = syncDatabaseId == null ? null : string.Format("/subscriptions/{0}/{1}", Subscription.Id, syncDatabaseId); + return client.SyncGroups.CreateOrUpdate(resourceGroupName, serverName, databaseName, syncGroupName, parameters); } /// /// Update a sync group /// - public SyncGroup UpdateSyncGroup(string resourceGroupName, string serverName, string databaseName, SyncGroupCreateOrUpdateParameters parameters) + public Management.Sql.Models.SyncGroup UpdateSyncGroup(string resourceGroupName, string serverName, string databaseName, string syncGroupName, Management.Sql.Models.SyncGroup parameters) { - return GetLegacySqlClient().DataSync.UpdateSyncGroup(resourceGroupName, serverName, databaseName, parameters).SyncGroup; + return GetCurrentSqlClient().SyncGroups.Update(resourceGroupName, serverName, databaseName, syncGroupName, parameters); } /// @@ -198,22 +199,22 @@ public void RemoveSyncMember(string resourceGroupName, string serverName, string /// /// Create a new sync member /// - public SyncMember CreateSyncMember(string resourceGroupName, string serverName, string databaseName, string syncAgentId, SyncMemberCreateOrUpdateParameters parameters) + public Management.Sql.Models.SyncMember CreateSyncMember(string resourceGroupName, string serverName, string databaseName, string syncGroupName, string syncMemberName, string syncAgentId, Management.Sql.Models.SyncMember parameters) { - SqlManagementClient client = GetLegacySqlClient(); + Management.Sql.SqlManagementClient client = GetCurrentSqlClient(); if (syncAgentId != null) { - parameters.Properties.SyncAgentId = string.Format("/subscriptions/{0}/{1}", client.Credentials.SubscriptionId, syncAgentId); + parameters.SyncAgentId = string.Format("/subscriptions/{0}/{1}", Subscription.Id, syncAgentId); } - return client.DataSync.CreateOrUpdateSyncMember(resourceGroupName, serverName, databaseName, parameters).SyncMember; + return client.SyncMembers.CreateOrUpdate(resourceGroupName, serverName, databaseName, syncGroupName, syncMemberName, parameters); } /// /// Update an existing sync member /// - public SyncMember UpdateSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberCreateOrUpdateParameters parameters) + public Management.Sql.Models.SyncMember UpdateSyncMember(string resourceGroupName, string serverName, string databaseName, string syncGroupName, string syncMemberName, Management.Sql.Models.SyncMember parameters) { - return GetLegacySqlClient().DataSync.UpdateSyncMember(resourceGroupName, serverName, databaseName, parameters).SyncMember; + return GetCurrentSqlClient().SyncMembers.Update(resourceGroupName, serverName, databaseName, syncGroupName, syncMemberName, parameters); } /// @@ -245,7 +246,7 @@ public void RemoveSyncAgent(string resourceGroupName, string serverName, string /// public SyncAgent CreateSyncAgent(string resourceGroupName, string serverName, string syncAgentName, string syncDatabaseId, SyncAgentCreateOrUpdateParameters parameters) { - SqlManagementClient client = GetLegacySqlClient(); + Management.Sql.LegacySdk.SqlManagementClient client = GetLegacySqlClient(); if (syncDatabaseId != null) { parameters.Properties.SyncDatabaseId = string.Format("/subscriptions/{0}/{1}", client.Credentials.SubscriptionId, syncDatabaseId); @@ -261,6 +262,19 @@ public SyncAgentKeyResponse CreateSyncAgentKey(string resourceGroupName, string return GetLegacySqlClient().DataSync.CreateSyncAgentKey(resourceGroupName, serverName, syncAgentName); } + /// + /// Retrieve the SQL Management client for the currently selected subscription, adding the session and request + /// id tracing headers for the current cmdlet invocation. + /// + /// The SQL Management client for the currently selected subscription. + public static Management.Sql.SqlManagementClient GetCurrentSqlClient() + { + // Get the SQL management client for the current subscription + // Note: client is not cached in static field because that causes ObjectDisposedException in functional tests. + var sqlClient = AzureSession.Instance.ClientFactory.CreateArmClient(Context, AzureEnvironment.Endpoint.ResourceManager); + return sqlClient; + } + /// /// Retrieve the SQL Management client for the currently selected subscription, adding the session and request /// id tracing headers for the current cmdlet invocation. diff --git a/src/Sql/Sql/Properties/Resources.Designer.cs b/src/Sql/Sql/Properties/Resources.Designer.cs index fc40503d5aa4..a8e4a79d0fd7 100644 --- a/src/Sql/Sql/Properties/Resources.Designer.cs +++ b/src/Sql/Sql/Properties/Resources.Designer.cs @@ -1455,6 +1455,15 @@ internal static string SyncGroupNameExists { } } + /// + /// Looks up a localized string similar to SyncMemberAzureDatabaseResourceId is a required parameter when UsePrivateLinkConnection is set to true. Please explicitly provide it.. + /// + internal static string SyncMemberIdRequired { + get { + return ResourceManager.GetString("SyncMemberIdRequired", resourceCulture); + } + } + /// /// Looks up a localized string similar to Sync Member with name: ‘{0}' already exists in Sync Group '{1}'.. /// diff --git a/src/Sql/Sql/Properties/Resources.resx b/src/Sql/Sql/Properties/Resources.resx index a115f7681c2d..9a37cf5d4b1e 100644 --- a/src/Sql/Sql/Properties/Resources.resx +++ b/src/Sql/Sql/Properties/Resources.resx @@ -622,4 +622,7 @@ Adding Storage Blob Data Contributor role for storage account {0} is forbidden + + SyncMemberAzureDatabaseResourceId is a required parameter when UsePrivateLinkConnection is set to true. Please explicitly provide it. + \ No newline at end of file From 7f4fef695665c17be74b501a1c185ac1b76441c1 Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Tue, 19 May 2020 03:24:22 -0700 Subject: [PATCH 2/8] update help files --- src/Sql/Sql/help/New-AzSqlSyncGroup.md | 21 ++++++++++-- src/Sql/Sql/help/New-AzSqlSyncMember.md | 39 ++++++++++++++++++++-- src/Sql/Sql/help/Update-AzSqlSyncGroup.md | 20 +++++++++-- src/Sql/Sql/help/Update-AzSqlSyncMember.md | 33 +++++++++++++++++- 4 files changed, 104 insertions(+), 9 deletions(-) diff --git a/src/Sql/Sql/help/New-AzSqlSyncGroup.md b/src/Sql/Sql/help/New-AzSqlSyncGroup.md index aade5d9029c7..9741d812b44a 100644 --- a/src/Sql/Sql/help/New-AzSqlSyncGroup.md +++ b/src/Sql/Sql/help/New-AzSqlSyncGroup.md @@ -15,9 +15,9 @@ Creates an Azure SQL Database Sync Group. ``` New-AzSqlSyncGroup [-Name] -SyncDatabaseName -SyncDatabaseServerName -SyncDatabaseResourceGroupName [-IntervalInSeconds ] [-DatabaseCredential ] - [-ConflictResolutionPolicy ] [-SchemaFile ] [-ServerName] [-DatabaseName] - [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] - [] + [-ConflictResolutionPolicy ] [-SchemaFile ] [-UsePrivateLinkConnection] [-ServerName] + [-DatabaseName] [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -236,6 +236,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -UsePrivateLinkConnection +Use a private link connection when connecting to the hub of this sync group. + +```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 +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. diff --git a/src/Sql/Sql/help/New-AzSqlSyncMember.md b/src/Sql/Sql/help/New-AzSqlSyncMember.md index 2f2e1d5bec59..7dabb6c1c6b5 100644 --- a/src/Sql/Sql/help/New-AzSqlSyncMember.md +++ b/src/Sql/Sql/help/New-AzSqlSyncMember.md @@ -16,7 +16,8 @@ Creates an Azure SQL Database Sync Member. ``` New-AzSqlSyncMember -Name -MemberDatabaseType -MemberServerName -MemberDatabaseName -MemberDatabaseCredential [-SyncDirection ] - [-SyncGroupName] [-ServerName] [-DatabaseName] [-ResourceGroupName] + [-UsePrivateLinkConnection] [-SyncMemberAzureDatabaseResourceId ] [-SyncGroupName] + [-ServerName] [-DatabaseName] [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -24,14 +25,16 @@ New-AzSqlSyncMember -Name -MemberDatabaseType -MemberServerNam ``` New-AzSqlSyncMember -Name -MemberDatabaseType -SyncAgentResourceGroupName -SyncAgentServerName -SyncAgentName -SqlServerDatabaseId [-SyncDirection ] - [-SyncGroupName] [-ServerName] [-DatabaseName] [-ResourceGroupName] + [-UsePrivateLinkConnection] [-SyncMemberAzureDatabaseResourceId ] [-SyncGroupName] + [-ServerName] [-DatabaseName] [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ### OnPremisesDatabaseSyncAgentResourceID ``` New-AzSqlSyncMember -Name -MemberDatabaseType -SqlServerDatabaseId - -SyncAgentResourceID [-SyncDirection ] [-SyncGroupName] [-ServerName] + -SyncAgentResourceID [-SyncDirection ] [-UsePrivateLinkConnection] + [-SyncMemberAzureDatabaseResourceId ] [-SyncGroupName] [-ServerName] [-DatabaseName] [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -334,6 +337,36 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -SyncMemberAzureDatabaseResourceId +The resource ID for the sync member database, used if UsePrivateLinkConnection is set to true. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UsePrivateLinkConnection +Use a private link connection when connecting to this sync member. + +```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 +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. diff --git a/src/Sql/Sql/help/Update-AzSqlSyncGroup.md b/src/Sql/Sql/help/Update-AzSqlSyncGroup.md index 01fa4654eac0..c9021d72b350 100644 --- a/src/Sql/Sql/help/Update-AzSqlSyncGroup.md +++ b/src/Sql/Sql/help/Update-AzSqlSyncGroup.md @@ -14,8 +14,9 @@ Updates an Azure SQL Database Sync Group. ``` Update-AzSqlSyncGroup [-Name] [-IntervalInSeconds ] [-DatabaseCredential ] - [-SchemaFile ] [-ServerName] [-DatabaseName] [-ResourceGroupName] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-SchemaFile ] [-UsePrivateLinkConnection ] [-ServerName] [-DatabaseName] + [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -172,6 +173,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -UsePrivateLinkConnection +Whether to use a private link connection when connecting to the hub of this sync group. + +```yaml +Type: System.Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. diff --git a/src/Sql/Sql/help/Update-AzSqlSyncMember.md b/src/Sql/Sql/help/Update-AzSqlSyncMember.md index 7a412251ba20..c9022b26ffb1 100644 --- a/src/Sql/Sql/help/Update-AzSqlSyncMember.md +++ b/src/Sql/Sql/help/Update-AzSqlSyncMember.md @@ -13,7 +13,8 @@ Updates an Azure SQL Database Sync Member. ## SYNTAX ``` -Update-AzSqlSyncMember -Name -MemberDatabaseCredential [-SyncGroupName] +Update-AzSqlSyncMember -Name -MemberDatabaseCredential + [-UsePrivateLinkConnection ] [-SyncMemberAzureDatabaseResourceId ] [-SyncGroupName] [-ServerName] [-DatabaseName] [-ResourceGroupName] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -154,6 +155,36 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -SyncMemberAzureDatabaseResourceId +The resource ID for the sync member database, used if UsePrivateLinkConnection is set to true. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UsePrivateLinkConnection +Whether to use private link when connecting to this sync member. + +```yaml +Type: System.Nullable`1[System.Boolean] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. From da170457c78913564ba7a1b4aa5a2df00d03fbfb Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Tue, 19 May 2020 04:09:31 -0700 Subject: [PATCH 3/8] update changelog --- src/Sql/Sql/ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Sql/Sql/ChangeLog.md b/src/Sql/Sql/ChangeLog.md index c82d049941ed..6436ac3f2bd3 100644 --- a/src/Sql/Sql/ChangeLog.md +++ b/src/Sql/Sql/ChangeLog.md @@ -18,6 +18,8 @@ - Additional information about change #1 --> ## Upcoming Release +* Added UsePrivateLinkConnection to `New-AzSqlSyncGroup`, `Update-AzSqlSyncGroup`, `New-AzSqlSyncMember` and `Update-AzSqlSyncMember` +* Added SyncMemberAzureDatabaseResourceId to `New-AzSqlSyncMember` and `Update-AzSqlSyncMember` ## Version 2.6.1 * Enhance performance of: From e948cfd4abe6d907a11215d9b15fce3fa46b491e Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Wed, 20 May 2020 00:29:40 -0700 Subject: [PATCH 4/8] bump sql management nuget version --- src/Sql/Sql.Test/Sql.Test.csproj | 2 +- src/Sql/Sql/Sql.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sql/Sql.Test/Sql.Test.csproj b/src/Sql/Sql.Test/Sql.Test.csproj index 519f8a4f1b35..265028f1d448 100644 --- a/src/Sql/Sql.Test/Sql.Test.csproj +++ b/src/Sql/Sql.Test/Sql.Test.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Sql/Sql/Sql.csproj b/src/Sql/Sql/Sql.csproj index 746cb2603bf0..ac135d9ea292 100644 --- a/src/Sql/Sql/Sql.csproj +++ b/src/Sql/Sql/Sql.csproj @@ -21,7 +21,7 @@ - + From 4cfd710d5bfb4b15e822c04abd1fe8b9b66034c0 Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Wed, 20 May 2020 01:13:04 -0700 Subject: [PATCH 5/8] use models from new sdk --- .../Data Sync/Model/AzureSqlSyncGroupModel.cs | 2 +- .../Data Sync/Model/AzureSqlSyncMemberModel.cs | 2 +- .../Services/AzureSqlDataSyncAdapter.cs | 4 ++-- .../Services/AzureSqlDataSyncCommunicator.cs | 16 ++++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs index efc671c8bc07..9a60cad63516 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs @@ -14,7 +14,7 @@ using System; using System.Security; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; namespace Microsoft.Azure.Commands.Sql.DataSync.Model { diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs index 2514359b4f2b..931f04610f6c 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs @@ -13,7 +13,7 @@ // ---------------------------------------------------------------------------------- using System.Security; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; namespace Microsoft.Azure.Commands.Sql.DataSync.Model { diff --git a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs index 727afbb372b2..2a0499e11b09 100644 --- a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs +++ b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncAdapter.cs @@ -476,7 +476,7 @@ internal ICollection ListSyncAgentLinkedDa /// The name of the database /// The sync group object from the response /// The converted model - public static AzureSqlSyncGroupModel CreateSyncGroupModelFromResponse(string resourceGroupName, string serverName, string databaseName, SyncGroup syncGroup) + public static AzureSqlSyncGroupModel CreateSyncGroupModelFromResponse(string resourceGroupName, string serverName, string databaseName, Management.Sql.Models.SyncGroup syncGroup) { return new AzureSqlSyncGroupModel(resourceGroupName, serverName, databaseName, syncGroup); } @@ -499,7 +499,7 @@ public static AzureSqlSyncGroupLogModel CreateSyncGroupLogModelFromResponse(Sync /// The name of the database /// The sync member object from the response /// The converted model - public static AzureSqlSyncMemberModel CreateSyncMemberModelFromResponse(string resourceGroupName, string serverName, string databaseName, string syncGroupName, SyncMember syncMember) + public static AzureSqlSyncMemberModel CreateSyncMemberModelFromResponse(string resourceGroupName, string serverName, string databaseName, string syncGroupName, Management.Sql.Models.SyncMember syncMember) { return new AzureSqlSyncMemberModel(resourceGroupName, serverName, databaseName, syncGroupName, syncMember); } diff --git a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs index 2c1f919f4a6d..3788fff91ac9 100644 --- a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs +++ b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs @@ -126,17 +126,17 @@ public Management.Sql.Models.SyncGroup UpdateSyncGroup(string resourceGroupName, /// /// Get a sync group /// - public SyncGroup GetSyncGroup(string resourceGroupName, string serverName, string databaseName, string syncGroupName) + public Management.Sql.Models.SyncGroup GetSyncGroup(string resourceGroupName, string serverName, string databaseName, string syncGroupName) { - return GetLegacySqlClient().DataSync.GetSyncGroup(resourceGroupName, serverName, databaseName, syncGroupName).SyncGroup; + return GetCurrentSqlClient().SyncGroups.Get(resourceGroupName, serverName, databaseName, syncGroupName); } /// /// List all sync groups /// - public IList ListSyncGroups(string resourceGroupName, string serverName, string databaseName) + public IEnumerable ListSyncGroups(string resourceGroupName, string serverName, string databaseName) { - return GetLegacySqlClient().DataSync.ListSyncGroup(resourceGroupName, serverName, databaseName).SyncGroups; + return GetCurrentSqlClient().SyncGroups.ListByDatabase(resourceGroupName, serverName, databaseName); } /// @@ -175,17 +175,17 @@ public SyncFullSchema GetSyncHubSchema(string resourceGroupName, string serverNa /// /// Get a sync group /// - public SyncMember GetSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters) + public Management.Sql.Models.SyncMember GetSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters) { - return GetLegacySqlClient().DataSync.GetSyncMember(resourceGroupName, serverName, databaseName, parameters).SyncMember; + return GetCurrentSqlClient().SyncMembers.Get(resourceGroupName, serverName, databaseName, parameters); } /// /// List all sync members /// - public IList ListSyncMembers(string resourceGroupName, string serverName, string databaseName, string syncGroupName) + public IEnumerable ListSyncMembers(string resourceGroupName, string serverName, string databaseName, string syncGroupName) { - return GetLegacySqlClient().DataSync.ListSyncMember(resourceGroupName, serverName, databaseName, syncGroupName).SyncMembers; + return GetCurrentSqlClient().SyncMembers.ListBySyncGroup(resourceGroupName, serverName, databaseName, syncGroupName); } /// From 0c66511e17889da5c7db93bd548d273d30af9bb2 Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Wed, 20 May 2020 01:20:39 -0700 Subject: [PATCH 6/8] remove no longer needed .Properties on sync group model --- .../Data Sync/Model/AzureSqlSyncGroupModel.cs | 16 +++++++-------- .../Model/AzureSqlSyncMemberModel.cs | 20 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs index 9a60cad63516..889cc5b9573e 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupModel.cs @@ -115,14 +115,14 @@ public AzureSqlSyncGroupModel(string resourceGroupName, string serverName, strin DatabaseName = databaseName; ResourceId = syncGroup.Id; SyncGroupName = syncGroup.Name; - IntervalInSeconds = syncGroup.Properties.Interval; - SyncDatabaseId = syncGroup.Properties.SyncDatabaseId; - HubDatabaseUserName = syncGroup.Properties.HubDatabaseUserName; - ConflictResolutionPolicy = syncGroup.Properties.ConflictResolutionPolicy == null ? null : syncGroup.Properties.ConflictResolutionPolicy.ToString(); - SyncState = syncGroup.Properties.SyncState; - LastSyncTime = syncGroup.Properties.LastSyncTime; - Schema = syncGroup.Properties.Schema == null ? null : new AzureSqlSyncGroupSchemaModel(syncGroup.Properties.Schema); - UsePrivateLinkConnection = syncGroup.Properties.UsePrivateLinkConnection; + IntervalInSeconds = syncGroup.Interval; + SyncDatabaseId = syncGroup.SyncDatabaseId; + HubDatabaseUserName = syncGroup.HubDatabaseUserName; + ConflictResolutionPolicy = syncGroup.ConflictResolutionPolicy == null ? null : syncGroup.ConflictResolutionPolicy.ToString(); + SyncState = syncGroup.SyncState; + LastSyncTime = syncGroup.LastSyncTime; + Schema = syncGroup.Schema == null ? null : new AzureSqlSyncGroupSchemaModel(syncGroup.Schema); + UsePrivateLinkConnection = syncGroup.UsePrivateLinkConnection; } } } diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs index 931f04610f6c..e54e90a08016 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs @@ -130,16 +130,16 @@ public AzureSqlSyncMemberModel(string resourceGroup, string serverName, string d ResourceId = syncMember.Id; SyncGroupName = syncGroupName; SyncMemberName = syncMember.Name; - SyncDirection = syncMember.Properties.SyncDirection == null ? null : syncMember.Properties.SyncDirection.ToString(); - SyncAgentId = syncMember.Properties.SyncAgentId; - SqlServerDatabaseId = syncMember.Properties.SqlServerDatabaseId; - MemberServerName = syncMember.Properties.ServerName; - MemberDatabaseName = syncMember.Properties.DatabaseName; - MemberDatabaseUserName = syncMember.Properties.UserName; - MemberDatabaseType = syncMember.Properties.DatabaseType == null ? null : syncMember.Properties.DatabaseType.ToString(); - SyncState = syncMember.Properties.SyncState; - UsePrivateLinkConnection = syncMember.Properties.UsePrivateLinkConnection; - SyncMemberAzureDatabaseResourceId = syncMember.Properties.SyncMemberAzureDatabaseResourceId; + SyncDirection = syncMember.SyncDirection == null ? null : syncMember.SyncDirection.ToString(); + SyncAgentId = syncMember.SyncAgentId; + SqlServerDatabaseId = syncMember.SqlServerDatabaseId; + MemberServerName = syncMember.ServerName; + MemberDatabaseName = syncMember.DatabaseName; + MemberDatabaseUserName = syncMember.UserName; + MemberDatabaseType = syncMember.DatabaseType == null ? null : syncMember.DatabaseType.ToString(); + SyncState = syncMember.SyncState; + UsePrivateLinkConnection = syncMember.UsePrivateLinkConnection; + SyncMemberAzureDatabaseResourceId = syncMember.SyncMemberAzureDatabaseResourceId; } } } From bd13f9ccca6dbf114e1952d86bdc97b6418e7429 Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Wed, 20 May 2020 01:33:08 -0700 Subject: [PATCH 7/8] move operations to new sdk to fix build errors --- .../Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs | 2 +- src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs | 2 +- .../Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs | 2 +- src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs | 2 +- src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs index f4fa1a452119..b52fe9a83ebe 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaColumnModel.cs @@ -50,7 +50,7 @@ public AzureSqlSyncGroupSchemaColumnModel() /// Construct AzureSqlSyncGroupSchemaColumnModel /// /// sync group schema column - public AzureSqlSyncGroupSchemaColumnModel(Management.Sql.LegacySdk.Models.SyncGroupSchemaColumn column) + public AzureSqlSyncGroupSchemaColumnModel(SyncGroupSchemaTableColumn column) { QuotedName = column != null ? column.QuotedName : null; DataSize = column != null ? column.DataSize : null; diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs index ce8ef102b007..54f048660279 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaModel.cs @@ -41,7 +41,7 @@ public AzureSqlSyncGroupSchemaModel() } - public AzureSqlSyncGroupSchemaModel(Management.Sql.LegacySdk.Models.SyncGroupSchema schema) + public AzureSqlSyncGroupSchemaModel(SyncGroupSchema schema) { if(schema.Tables != null){ Tables = new List(); diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs index d1ca29907d0c..b16b90cfa8bb 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncGroupSchemaTableModel.cs @@ -45,7 +45,7 @@ public AzureSqlSyncGroupSchemaTableModel() /// Construct AzureSqlSyncGroupSchemaTableModel /// /// sync group schema table - public AzureSqlSyncGroupSchemaTableModel(Management.Sql.LegacySdk.Models.SyncGroupSchemaTable table) + public AzureSqlSyncGroupSchemaTableModel(SyncGroupSchemaTable table) { if (table != null && table.Columns != null) { diff --git a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs index e54e90a08016..4375e8726510 100644 --- a/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs +++ b/src/Sql/Sql/Data Sync/Model/AzureSqlSyncMemberModel.cs @@ -132,7 +132,7 @@ public AzureSqlSyncMemberModel(string resourceGroup, string serverName, string d SyncMemberName = syncMember.Name; SyncDirection = syncMember.SyncDirection == null ? null : syncMember.SyncDirection.ToString(); SyncAgentId = syncMember.SyncAgentId; - SqlServerDatabaseId = syncMember.SqlServerDatabaseId; + SqlServerDatabaseId = syncMember.SqlServerDatabaseId == null ? null : syncMember.SqlServerDatabaseId.ToString(); MemberServerName = syncMember.ServerName; MemberDatabaseName = syncMember.DatabaseName; MemberDatabaseUserName = syncMember.UserName; diff --git a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs index 3788fff91ac9..a498f2d08988 100644 --- a/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs +++ b/src/Sql/Sql/Data Sync/Services/AzureSqlDataSyncCommunicator.cs @@ -177,7 +177,7 @@ public SyncFullSchema GetSyncHubSchema(string resourceGroupName, string serverNa /// public Management.Sql.Models.SyncMember GetSyncMember(string resourceGroupName, string serverName, string databaseName, SyncMemberGeneralParameters parameters) { - return GetCurrentSqlClient().SyncMembers.Get(resourceGroupName, serverName, databaseName, parameters); + return GetCurrentSqlClient().SyncMembers.Get(resourceGroupName, serverName, databaseName, parameters.SyncGroupName, parameters.SyncMemberName); } /// From 01f14961675b778e65ae2a624027d4583e071cf6 Mon Sep 17 00:00:00 2001 From: Fernando Fonseca Date: Wed, 20 May 2020 02:53:14 -0700 Subject: [PATCH 8/8] replace Hyak.Common with Microsoft.Rest.Azure --- src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs | 2 +- src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs index 5084d60d1e97..daa35d17cdeb 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncGroup.cs @@ -17,7 +17,7 @@ using System.Linq; using Microsoft.Azure.Commands.Sql.DataSync.Model; using Microsoft.Azure.Management.Sql.Models; -using Hyak.Common; +using Microsoft.Rest.Azure; using Newtonsoft.Json.Linq; using System.IO; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; diff --git a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs index 837b48eecf9d..0a14f3a58574 100644 --- a/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs +++ b/src/Sql/Sql/Data Sync/Cmdlet/NewAzureSqlSyncMember.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using System.Linq; using System.Management.Automation; -using Hyak.Common; +using Microsoft.Rest.Azure; using Microsoft.Azure.Commands.Sql.DataSync.Model; using Microsoft.Azure.Commands.Sql.Properties; using Microsoft.Azure.Management.Sql.LegacySdk.Models;