コード例 #1
0
        /// <summary>
        /// Creates an Azure SQL Database Secondary using new Autorest sdk
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="model">The input parameters for the create operation</param>
        /// <returns>The Azure SQL Database ReplicationLink object</returns>
        internal AzureReplicationLinkModel CreateLinkWithNewSdk(string resourceGroupName, string serverName, AzureReplicationLinkModel model)
        {
            // Construct the ARM resource Id of the pool
            string elasticPoolId = string.IsNullOrWhiteSpace(model.SecondaryElasticPoolName) ? null : AzureSqlDatabaseModel.PoolIdTemplate.FormatInvariant(
                _subscription.Id,
                resourceGroupName,
                serverName,
                model.SecondaryElasticPoolName);

            var resp = ReplicationCommunicator.CreateCopy(resourceGroupName, serverName, model.PartnerDatabaseName, new Management.Sql.Models.Database
            {
                Location         = model.PartnerLocation,
                SourceDatabaseId = string.Format(AzureReplicationLinkModel.SourceIdTemplate, _subscription.Id.ToString(),
                                                 model.ResourceGroupName, model.ServerName, model.DatabaseName),
                CreateMode    = Management.Sql.Models.CreateMode.Secondary,
                ElasticPoolId = elasticPoolId,
                Sku           = string.IsNullOrWhiteSpace(model.SkuName) ? null : new Management.Sql.Models.Sku()
                {
                    Name     = model.SkuName,
                    Tier     = model.Edition,
                    Family   = model.Family,
                    Capacity = model.Capacity
                },
                LicenseType        = model.LicenseType,
                StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
            });

            return(GetLink(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.PartnerResourceGroupName, model.PartnerServerName));
        }
コード例 #2
0
        /// <summary>
        /// Creates an Azure SQL Database Copy with new AutoRest SDK
        /// </summary>
        /// <param name="copyResourceGroup">The name of the resource group</param>
        /// <param name="copyServerName">The name of the Azure SQL server</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns></returns>
        internal AzureSqlDatabaseCopyModel CopyDatabaseWithNewSdk(string copyResourceGroup, string copyServerName, AzureSqlDatabaseCopyModel model)
        {
            // Construct the ARM resource Id of the pool
            string elasticPoolId = string.IsNullOrWhiteSpace(model.ElasticPoolName) ? null : AzureSqlDatabaseModel.PoolIdTemplate.FormatInvariant(
                _subscription.Id,
                copyResourceGroup,
                copyServerName,
                model.ElasticPoolName);

            // Create copy of the database
            var resp = ReplicationCommunicator.CreateCopy(copyResourceGroup, copyServerName, model.CopyDatabaseName, new Management.Sql.Models.Database(model.CopyLocation, tags: model.Tags)
            {
                CreateMode       = Management.Sql.Models.CreateMode.Copy,
                SourceDatabaseId = string.Format(AzureReplicationLinkModel.SourceIdTemplate, _subscription.Id.ToString(),
                                                 model.ResourceGroupName, model.ServerName, model.DatabaseName),
                ElasticPoolId = elasticPoolId,
                Sku           = string.IsNullOrWhiteSpace(model.SkuName) ? null : new Management.Sql.Models.Sku()
                {
                    Name     = model.SkuName,
                    Tier     = model.Edition,
                    Family   = model.Family,
                    Capacity = model.Capacity
                },
                LicenseType        = model.LicenseType,
                StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy)
            });

            return(CreateDatabaseCopyModelFromResponse(model.CopyResourceGroupName, model.CopyServerName, model.ResourceGroupName,
                                                       model.ServerName, model.DatabaseName, resp));
        }
コード例 #3
0
        /// <summary>
        /// Gets the Secondary Link by linkId
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="databaseName">The name of primary database</param>
        /// <param name="partnerResourceGroupName">The name of the Resource Group containing the secondary database</param>
        /// <param name="linkId">The linkId of the replication link to the secondary</param>
        /// <returns>The Azure SQL Database ReplicationLink object</returns>
        internal AzureReplicationLinkModel GetLink(string resourceGroupName, string serverName, string databaseName,
                                                   string partnerResourceGroupName, Guid linkId)
        {
            // partnerResourceGroupName is required because it is not exposed in any reponse from the service.

            var resp = ReplicationCommunicator.GetLink(resourceGroupName, serverName, databaseName, linkId);

            return(CreateReplicationLinkModelFromReplicationLinkResponse(resourceGroupName, serverName, databaseName, partnerResourceGroupName, resp));
        }
コード例 #4
0
        /// <summary>
        /// Lists Azure SQL Database Secondaries for the specified primary for the specified partner resource group
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="databaseName">The name of primary database</param>
        /// <param name="partnerResourceGroupName">The name of the Resource Group containing the secondary database</param>
        /// <returns>The collection of Azure SQL Database ReplicationLink objects for the primary</returns>
        internal ICollection <AzureReplicationLinkModel> ListLinks(string resourceGroupName, string serverName, string databaseName,
                                                                   string partnerResourceGroupName)
        {
            CheckPartnerResourceGroupValid(partnerResourceGroupName);

            var resp = ReplicationCommunicator.ListLinks(resourceGroupName, serverName, databaseName);

            return(resp.Select((link) =>
            {
                return CreateReplicationLinkModelFromReplicationLinkResponse(resourceGroupName, serverName, databaseName, partnerResourceGroupName, link);
            }).ToList());
        }
コード例 #5
0
        /// <summary>
        /// Creates an Azure SQL Database Secondary using Legacy sdk
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="model">The input parameters for the create operation</param>
        /// <returns>The Azure SQL Database ReplicationLink object</returns>
        internal AzureReplicationLinkModel CreateLink(string resourceGroupName, string serverName, AzureReplicationLinkModel model)
        {
            var resp = ReplicationCommunicator.CreateCopy(resourceGroupName, serverName, model.DatabaseName, new DatabaseCreateOrUpdateParameters()
            {
                Location   = model.PartnerLocation,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    SourceDatabaseId = string.Format(AzureReplicationLinkModel.SourceIdTemplate, _subscription.Id.ToString(),
                                                     model.ResourceGroupName, model.ServerName, model.DatabaseName),
                    CreateMode      = model.AllowConnections.HasFlag(AllowConnections.All) ? Management.Sql.LegacySdk.Models.DatabaseCreateMode.Secondary : Management.Sql.LegacySdk.Models.DatabaseCreateMode.NonReadableSecondary,
                    ElasticPoolName = model.SecondaryElasticPoolName,
                    RequestedServiceObjectiveName = model.SecondaryServiceObjectiveName,
                }
            });

            return(GetLink(model.ResourceGroupName, model.ServerName, model.DatabaseName, model.PartnerResourceGroupName, model.PartnerServerName));
        }
コード例 #6
0
        /// <summary>
        /// Finds and removes the Secondary Link by the secondary resource group and Azure SQL Server
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="databaseName">The name of primary database</param>
        /// <param name="partnerResourceGroupName">The name of the Resource Group containing the secondary database</param>
        /// <param name="partnerServerName">The name of the Azure SQL Server containing the secondary database</param>
        /// <param name="allowDataLoss">Whether the failover operation will allow data loss</param>
        /// <returns>The Azure SQL Database ReplicationLink object</returns>
        internal AzureReplicationLinkModel FailoverLink(string resourceGroupName, string serverName, string databaseName, string partnerResourceGroupName, bool allowDataLoss)
        {
            IList <AzureReplicationLinkModel> links = ListLinks(resourceGroupName, serverName, databaseName, partnerResourceGroupName).ToList();

            // Resource Management executes in context of the Secondary
            AzureReplicationLinkModel link = links.First();

            if (allowDataLoss)
            {
                ReplicationCommunicator.FailoverLinkAllowDataLoss(link.ResourceGroupName, link.ServerName, link.DatabaseName, link.LinkId);
            }
            else
            {
                ReplicationCommunicator.FailoverLink(link.ResourceGroupName, link.ServerName, link.DatabaseName, link.LinkId);
            }

            return(GetLink(link.PartnerResourceGroupName, link.PartnerServerName, link.DatabaseName, link.PartnerResourceGroupName, link.PartnerServerName));
        }
コード例 #7
0
        /// <summary>
        /// Creates an Azure SQL Database Copy with Legacy SDK (Hyak SDK)
        /// </summary>
        /// <param name="copyResourceGroup">The name of the resource group</param>
        /// <param name="copyServerName">The name of the Azure SQL Server</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns>The Azure SQL Database Copy object</returns>
        internal AzureSqlDatabaseCopyModel CopyDatabase(string copyResourceGroup, string copyServerName, AzureSqlDatabaseCopyModel model)
        {
            var resp = ReplicationCommunicator.CreateCopy(copyResourceGroup, copyServerName, model.CopyDatabaseName, new DatabaseCreateOrUpdateParameters()
            {
                Location   = model.CopyLocation,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    SourceDatabaseId = string.Format(AzureReplicationLinkModel.SourceIdTemplate, _subscription.Id.ToString(),
                                                     model.ResourceGroupName, model.ServerName, model.DatabaseName),
                    CreateMode      = Management.Sql.LegacySdk.Models.DatabaseCreateMode.Copy,
                    ElasticPoolName = model.ElasticPoolName,
                    RequestedServiceObjectiveName = model.ServiceObjectiveName,
                }
            });

            return(CreateDatabaseCopyModelFromDatabaseCreateOrUpdateResponse(model.CopyResourceGroupName, model.CopyServerName, model.CopyDatabaseName,
                                                                             model.ResourceGroupName, model.ServerName, model.DatabaseName, resp));
        }
コード例 #8
0
        /// <summary>
        /// Finds and removes the Secondary Link by the secondary resource group and Azure SQL Server
        /// </summary>
        /// <param name="resourceGroupName">The name of the Resource Group containing the primary database</param>
        /// <param name="serverName">The name of the Azure SQL Server containing the primary database</param>
        /// <param name="databaseName">The name of primary database</param>
        /// <param name="partnerResourceGroupName">The name of the Resource Group containing the secondary database</param>
        /// <param name="partnerServerName">The name of the Azure SQL Server containing the secondary database</param>
        internal void RemoveLink(string resourceGroupName, string serverName, string databaseName, string partnerResourceGroupName, string partnerServerName)
        {
            AzureReplicationLinkModel link = GetLink(resourceGroupName, serverName, databaseName, partnerResourceGroupName, partnerServerName);

            ReplicationCommunicator.RemoveLink(link.ResourceGroupName, link.ServerName, link.DatabaseName, link.LinkId);
        }