public void GetDatabaseSkuName()
 {
     Assert.Equal(
         "Basic",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("Basic"));
     Assert.Equal(
         "Standard",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("Standard"));
     Assert.Equal(
         "Premium",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("Premium"));
     Assert.Equal(
         "DataWarehouse",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("DataWarehouse"));
     Assert.Equal(
         "Stretch",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("Stretch"));
     Assert.Equal(
         "GP",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("GeneralPurpose"));
     Assert.Equal(
         "BC",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("BusinessCritical"));
     Assert.Equal(
         "HS",
         AzureSqlDatabaseAdapter.GetDatabaseSkuName("Hyperscale"));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureSqlDatabaseModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseModel> model)
        {
            List <Model.AzureSqlDatabaseModel> newEntity = new List <AzureSqlDatabaseModel>();
            AzureSqlDatabaseModel newDbModel             = new AzureSqlDatabaseModel()
            {
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                DatabaseName      = DatabaseName,
                MaxSizeBytes      = MaxSizeBytes,
                Tags                    = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags),
                ElasticPoolName         = ElasticPoolName,
                Location                = model.FirstOrDefault().Location,
                ReadScale               = ReadScale,
                ZoneRedundant           = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
                LicenseType             = LicenseType ?? model.FirstOrDefault().LicenseType, // set to original license type
                AutoPauseDelayInMinutes = this.IsParameterBound(p => p.AutoPauseDelayInMinutes) ? AutoPauseDelayInMinutes : (int?)null,
                MinimumCapacity         = this.IsParameterBound(p => p.MinimumCapacity) ? MinimumCapacity : (double?)null,
                ReadReplicaCount        = this.IsParameterBound(p => p.ReadReplicaCount) ? ReadReplicaCount : (int?)null,
                BackupStorageRedundancy = BackupStorageRedundancy,
            };

            var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);

            Management.Sql.Models.Sku databaseCurrentSku = new Management.Sql.Models.Sku()
            {
                Name     = database.SkuName,
                Tier     = database.Edition,
                Family   = database.Family,
                Capacity = database.Capacity
            };

            // check if current db is serverless
            string databaseCurrentComputeModel = database.CurrentServiceObjectiveName.Contains("_S_") ? DatabaseComputeModel.Serverless : DatabaseComputeModel.Provisioned;

            if (this.ParameterSetName == UpdateParameterSetName)
            {
                newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName;
                newDbModel.Edition = Edition;

                newEntity.Add(newDbModel);
            }
            else if (this.ParameterSetName == VcoreDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(Edition) ||
                    !string.IsNullOrWhiteSpace(ComputeGeneration) ||
                    this.IsParameterBound(p => p.VCore))
                {
                    string skuTier = string.IsNullOrWhiteSpace(Edition) ? databaseCurrentSku.Tier : Edition;
                    string requestedComputeModel = string.IsNullOrWhiteSpace(ComputeModel) ? databaseCurrentComputeModel : ComputeModel;
                    newDbModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(skuTier, requestedComputeModel == DatabaseComputeModel.Serverless);
                    newDbModel.Edition  = skuTier;
                    newDbModel.Family   = string.IsNullOrWhiteSpace(ComputeGeneration) ? databaseCurrentSku.Family : ComputeGeneration;
                    newDbModel.Capacity = this.IsParameterBound(p => p.VCore) ? VCore : databaseCurrentSku.Capacity;
                }

                newEntity.Add(newDbModel);
            }

            return(newEntity);
        }
        /// <summary>
        /// Restore a given Sql Azure Database
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="restorePointInTime">A point to time to restore to (for PITR and dropped DB restore)</param>
        /// <param name="resourceId">The resource ID of the DB to restore (live, geo backup, deleted database, long term retention backup, etc.)</param>
        /// <param name="model">An object modeling the database to create via restore</param>
        /// <returns>Restored database object</returns>
        internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime restorePointInTime, string resourceId, AzureSqlDatabaseModel model)
        {
            if (model.CreateMode.Equals("RestoreLongTermRetentionBackup", StringComparison.OrdinalIgnoreCase) && CultureInfo.CurrentCulture.CompareInfo.IndexOf(resourceId, "/providers/Microsoft.Sql", CompareOptions.IgnoreCase) >= 0)
            {
                // LongTermRetentionV2 Restore
                //
                Management.Sql.Models.Database database = Communicator.RestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, resourceId, model);

                return(new AzureSqlDatabaseModel(resourceGroup, model.ServerName, database));
            }
            else
            {
                DatabaseCreateOrUpdateParameters parameters = new DatabaseCreateOrUpdateParameters()
                {
                    Location   = model.Location,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        Edition = model.Edition == DatabaseEdition.None ? null : model.Edition.ToString(),
                        RequestedServiceObjectiveId             = model.RequestedServiceObjectiveId,
                        ElasticPoolName                         = model.ElasticPoolName,
                        RequestedServiceObjectiveName           = model.RequestedServiceObjectiveName,
                        SourceDatabaseId                        = resourceId,
                        RecoveryServicesRecoveryPointResourceId = resourceId,
                        RestorePointInTime                      = restorePointInTime,
                        CreateMode = model.CreateMode
                    }
                };
                var resp = Communicator.LegacyRestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, parameters);
                return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, model.ServerName, resp));
            }
        }
        /// <summary>
        /// Gets a list of Azure Sql Databases in an ElasticPool.
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="poolName">The name of the elastic pool the database are in</param>
        /// <returns>A list of database objects</returns>
        internal ICollection <AzureSqlDatabaseModel> ListElasticPoolDatabases(string resourceGroupName, string serverName, string poolName)
        {
            var resp = Communicator.ListDatabases(resourceGroupName, serverName, poolName);

            return(resp.Select((db) =>
            {
                return AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, db);
            }).ToList());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets a list of Azure Sql Databases in a secondary server.
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <returns>A list of database objects</returns>
        internal ICollection <AzureSqlDatabaseModel> ListDatabasesOnServer(string resourceGroupName, string serverName)
        {
            var resp = Communicator.ListDatabasesOnServer(resourceGroupName, serverName, Util.GenerateTracingId());

            return(resp.Select((db) =>
            {
                return AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, db);
            }).ToList());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureSqlDatabaseModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseModel> model)
        {
            List <Model.AzureSqlDatabaseModel> newEntity = new List <AzureSqlDatabaseModel>();
            AzureSqlDatabaseModel newDbModel             = new AzureSqlDatabaseModel()
            {
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                DatabaseName      = DatabaseName,
                MaxSizeBytes      = MaxSizeBytes,
                Tags            = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags),
                ElasticPoolName = ElasticPoolName,
                Location        = model.FirstOrDefault().Location,
                ReadScale       = ReadScale,
                ZoneRedundant   =
                    ZoneRedundant != null
                           ? (bool?)ZoneRedundant.ToBool()
                           : null,
                LicenseType = LicenseType ?? model.FirstOrDefault().LicenseType // set to original license type
            };

            var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);

            Management.Sql.Models.Sku databaseCurrentSku = new Management.Sql.Models.Sku()
            {
                Name     = database.SkuName,
                Tier     = database.Edition,
                Family   = database.Family,
                Capacity = database.Capacity
            };

            if (this.ParameterSetName == UpdateParameterSetName)
            {
                newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName;
                newDbModel.Edition = Edition;

                newEntity.Add(newDbModel);
            }
            else if (this.ParameterSetName == VcoreDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(Edition) ||
                    !string.IsNullOrWhiteSpace(ComputeGeneration) ||
                    MyInvocation.BoundParameters.ContainsKey("VCore"))
                {
                    string skuTier = string.IsNullOrWhiteSpace(Edition) ? databaseCurrentSku.Tier : Edition;
                    newDbModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(skuTier);
                    newDbModel.Edition  = skuTier;
                    newDbModel.Family   = string.IsNullOrWhiteSpace(ComputeGeneration) ? databaseCurrentSku.Family : ComputeGeneration;
                    newDbModel.Capacity = MyInvocation.BoundParameters.ContainsKey("VCore") ? VCore : databaseCurrentSku.Capacity;
                }

                newEntity.Add(newDbModel);
            }

            return(newEntity);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureSqlDatabaseCopyModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseCopyModel> model)
        {
            string copyResourceGroup = string.IsNullOrWhiteSpace(CopyResourceGroupName) ? ResourceGroupName : CopyResourceGroupName;
            string copyServer        = string.IsNullOrWhiteSpace(CopyServerName) ? ServerName : CopyServerName;

            string location     = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            string copyLocation = copyServer.Equals(ServerName) ? location : ModelAdapter.GetServerLocation(copyResourceGroup, copyServer);

            Database.Model.AzureSqlDatabaseModel   sourceDb  = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);
            List <Model.AzureSqlDatabaseCopyModel> newEntity = new List <AzureSqlDatabaseCopyModel>();

            AzureSqlDatabaseCopyModel copyModel = new AzureSqlDatabaseCopyModel()
            {
                Location              = location,
                ResourceGroupName     = ResourceGroupName,
                ServerName            = ServerName,
                DatabaseName          = DatabaseName,
                CopyResourceGroupName = copyResourceGroup,
                CopyServerName        = copyServer,
                CopyDatabaseName      = CopyDatabaseName,
                CopyLocation          = copyLocation,
                ServiceObjectiveName  = ServiceObjectiveName,
                ElasticPoolName       = ElasticPoolName,
                Tags        = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                LicenseType = LicenseType, // note: default license type is LicenseIncluded
                RequestedBackupStorageRedundancy = BackupStorageRedundancy,
                ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null,
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(ServiceObjectiveName))
                {
                    copyModel.SkuName = ServiceObjectiveName;
                }
                else if (string.IsNullOrWhiteSpace(ElasticPoolName))
                {
                    copyModel.SkuName  = sourceDb.CurrentServiceObjectiveName;
                    copyModel.Edition  = sourceDb.Edition;
                    copyModel.Capacity = sourceDb.Capacity;
                    copyModel.Family   = sourceDb.Family;
                }
            }
            else
            {
                copyModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(sourceDb.Edition);
                copyModel.Edition  = sourceDb.Edition;
                copyModel.Capacity = VCore;
                copyModel.Family   = ComputeGeneration;
            }

            newEntity.Add(copyModel);
            return(newEntity);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureReplicationLinkModel> ApplyUserInputToModel(IEnumerable <AzureReplicationLinkModel> model)
        {
            string location = ModelAdapter.GetServerLocation(this.PartnerResourceGroupName, this.PartnerServerName);
            List <Model.AzureReplicationLinkModel> newEntity = new List <AzureReplicationLinkModel>();

            Database.Model.AzureSqlDatabaseModel primaryDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);

            AzureReplicationLinkModel linkModel = new AzureReplicationLinkModel()
            {
                PartnerLocation          = location,
                ResourceGroupName        = this.ResourceGroupName,
                ServerName               = this.ServerName,
                DatabaseName             = this.DatabaseName,
                PartnerResourceGroupName = this.PartnerResourceGroupName,
                PartnerServerName        = this.PartnerServerName,
                PartnerDatabaseName      = GetEffectivePartnerDatabaseName(this.DatabaseName, this.PartnerDatabaseName),
                SecondaryElasticPoolName = this.SecondaryElasticPoolName,
                AllowConnections         = this.AllowConnections,
                Tags        = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                LicenseType = LicenseType,
                RequestedBackupStorageRedundancy = this.BackupStorageRedundancy,
                SecondaryType = SecondaryType,
                HighAvailabilityReplicaCount = this.IsParameterBound(p => p.HighAvailabilityReplicaCount) ? HighAvailabilityReplicaCount : (int?)null,
                ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null,
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(SecondaryServiceObjectiveName))
                {
                    linkModel.SkuName = SecondaryServiceObjectiveName;
                }
                else if (string.IsNullOrWhiteSpace(SecondaryElasticPoolName))
                {
                    linkModel.SkuName  = primaryDb.CurrentServiceObjectiveName;
                    linkModel.Edition  = primaryDb.Edition;
                    linkModel.Capacity = primaryDb.Capacity;
                    linkModel.Family   = primaryDb.Family;
                }
            }
            else
            {
                linkModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(primaryDb.Edition);
                linkModel.Edition  = primaryDb.Edition;
                linkModel.Capacity = SecondaryVCore;
                linkModel.Family   = SecondaryComputeGeneration;
            }

            newEntity.Add(linkModel);
            return(newEntity);
        }
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureSqlDatabaseCopyModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseCopyModel> model)
        {
            string copyResourceGroup = string.IsNullOrWhiteSpace(CopyResourceGroupName) ? ResourceGroupName : CopyResourceGroupName;
            string copyServer        = string.IsNullOrWhiteSpace(CopyServerName) ? ServerName : CopyServerName;

            string location     = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            string copyLocation = copyServer.Equals(ServerName) ? location : ModelAdapter.GetServerLocation(copyResourceGroup, copyServer);

            Database.Model.AzureSqlDatabaseModel   sourceDb  = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);
            List <Model.AzureSqlDatabaseCopyModel> newEntity = new List <AzureSqlDatabaseCopyModel>();

            AzureSqlDatabaseCopyModel copyModel = new AzureSqlDatabaseCopyModel()
            {
                Location              = location,
                ResourceGroupName     = ResourceGroupName,
                ServerName            = ServerName,
                DatabaseName          = DatabaseName,
                CopyResourceGroupName = copyResourceGroup,
                CopyServerName        = copyServer,
                CopyDatabaseName      = CopyDatabaseName,
                CopyLocation          = copyLocation,
                ServiceObjectiveName  = ServiceObjectiveName,
                ElasticPoolName       = ElasticPoolName,
                Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true)
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(ServiceObjectiveName))
                {
                    copyModel.SkuName = ServiceObjectiveName;
                }
                else if (string.IsNullOrWhiteSpace(ElasticPoolName))
                {
                    copyModel.SkuName  = sourceDb.CurrentServiceObjectiveName;
                    copyModel.Edition  = sourceDb.Edition;
                    copyModel.Capacity = sourceDb.Capacity;
                    copyModel.Family   = sourceDb.Family;
                }
            }
            else
            {
                copyModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(sourceDb.Edition);
                copyModel.Edition  = sourceDb.Edition;
                copyModel.Capacity = VCore;
                copyModel.Family   = ComputeGeneration;
            }

            newEntity.Add(copyModel);
            return(newEntity);
        }
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override IEnumerable <AzureReplicationLinkModel> ApplyUserInputToModel(IEnumerable <AzureReplicationLinkModel> model)
        {
            string location = ModelAdapter.GetServerLocation(this.PartnerResourceGroupName, this.PartnerServerName);
            List <Model.AzureReplicationLinkModel> newEntity = new List <AzureReplicationLinkModel>();

            Database.Model.AzureSqlDatabaseModel primaryDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);

            AzureReplicationLinkModel linkModel = new AzureReplicationLinkModel()
            {
                PartnerLocation          = location,
                ResourceGroupName        = this.ResourceGroupName,
                ServerName               = this.ServerName,
                DatabaseName             = this.DatabaseName,
                PartnerResourceGroupName = this.PartnerResourceGroupName,
                PartnerServerName        = this.PartnerServerName,
                PartnerDatabaseName      = string.IsNullOrWhiteSpace(this.PartnerDatabaseName) ? this.DatabaseName : this.PartnerDatabaseName,
                SecondaryElasticPoolName = this.SecondaryElasticPoolName,
                AllowConnections         = this.AllowConnections,
                Tags        = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                LicenseType = LicenseType
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(SecondaryServiceObjectiveName))
                {
                    linkModel.SkuName = SecondaryServiceObjectiveName;
                }
                else if (string.IsNullOrWhiteSpace(SecondaryElasticPoolName))
                {
                    linkModel.SkuName  = primaryDb.CurrentServiceObjectiveName;
                    linkModel.Edition  = primaryDb.Edition;
                    linkModel.Capacity = primaryDb.Capacity;
                    linkModel.Family   = primaryDb.Family;
                }
            }
            else
            {
                linkModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(primaryDb.Edition);
                linkModel.Edition  = primaryDb.Edition;
                linkModel.Capacity = SecondaryVCore;
                linkModel.Family   = SecondaryComputeGeneration;
            }

            newEntity.Add(linkModel);
            return(newEntity);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel();
            AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel()
            {
                Location          = location,
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                CatalogCollation  = CatalogCollation,
                CollationName     = CollationName,
                DatabaseName      = DatabaseName,
                MaxSizeBytes      = MaxSizeBytes,
                Tags                             = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                ElasticPoolName                  = ElasticPoolName,
                ReadScale                        = this.IsParameterBound(p => p.ReadScale) ? ReadScale : (DatabaseReadScale?)null,
                ZoneRedundant                    = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null,
                LicenseType                      = LicenseType, // note: default license type will be LicenseIncluded in SQL RP if not specified
                AutoPauseDelayInMinutes          = this.IsParameterBound(p => p.AutoPauseDelayInMinutes) ? AutoPauseDelayInMinutes : (int?)null,
                MinimumCapacity                  = this.IsParameterBound(p => p.MinimumCapacity) ? MinimumCapacity : (double?)null,
                HighAvailabilityReplicaCount     = this.IsParameterBound(p => p.HighAvailabilityReplicaCount) ? HighAvailabilityReplicaCount : (int?)null,
                RequestedBackupStorageRedundancy = BackupStorageRedundancy,
                SecondaryType                    = SecondaryType,
                MaintenanceConfigurationId       = MaintenanceConfigurationId,
                EnableLedger                     = this.IsParameterBound(p => p.EnableLedger) ? EnableLedger.ToBool() : (bool?)null,
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName;
                newDbModel.Edition = Edition;
            }
            else
            {
                newDbModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition, ComputeModel == DatabaseComputeModel.Serverless);
                newDbModel.Edition  = Edition;
                newDbModel.Capacity = VCore;
                newDbModel.Family   = ComputeGeneration;
            }

            dbCreateUpdateModel.Database   = newDbModel;
            dbCreateUpdateModel.SampleName = SampleName;

            return(dbCreateUpdateModel);
        }
        /// <summary>
        /// Restore a given Sql Azure Database
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="restorePointInTime">A point to time to restore to (for PITR and dropped DB restore)</param>
        /// <param name="resourceId">The resource ID of the DB to restore (live, geo backup, or deleted database)</param>
        /// <param name="model">An object modeling the database to create via restore</param>
        /// <param name="parameters">Parameters describing the database restore request</param>
        /// <returns>Restored database object</returns>
        internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime restorePointInTime, string resourceId, AzureSqlDatabaseModel model)
        {
            DatabaseCreateOrUpdateParameters parameters = new DatabaseCreateOrUpdateParameters()
            {
                Location   = model.Location,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    Edition = model.Edition == DatabaseEdition.None ? null : model.Edition.ToString(),
                    RequestedServiceObjectiveId   = model.RequestedServiceObjectiveId,
                    ElasticPoolName               = model.ElasticPoolName,
                    RequestedServiceObjectiveName = model.RequestedServiceObjectiveName,
                    SourceDatabaseId              = resourceId,
                    RestorePointInTime            = restorePointInTime,
                    CreateMode = model.CreateMode
                }
            };
            var resp = Communicator.RestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, Util.GenerateTracingId(), parameters);

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, model.ServerName, resp));
        }
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel();
            AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel()
            {
                Location          = location,
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                CatalogCollation  = CatalogCollation,
                CollationName     = CollationName,
                DatabaseName      = DatabaseName,
                MaxSizeBytes      = MaxSizeBytes,
                Tags                    = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                ElasticPoolName         = ElasticPoolName,
                ReadScale               = ReadScale,
                ZoneRedundant           = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
                LicenseType             = LicenseType, // note: default license type will be LicenseIncluded in SQL RP if not specified
                AutoPauseDelayInMinutes = MyInvocation.BoundParameters.ContainsKey("AutoPauseDelayInMinutes") ? AutoPauseDelayInMinutes : (int?)null,
                MinimumCapacity         = MyInvocation.BoundParameters.ContainsKey("AutoPauseDelayInMinutes") ? MinimumCapacity : (double?)null,
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName;
                newDbModel.Edition = Edition;
            }
            else
            {
                newDbModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition, ComputeModel == DatabaseComputeModel.Serverless);
                newDbModel.Edition  = Edition;
                newDbModel.Capacity = VCore;
                newDbModel.Family   = ComputeGeneration;
            }

            dbCreateUpdateModel.Database   = newDbModel;
            dbCreateUpdateModel.SampleName = SampleName;

            return(dbCreateUpdateModel);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Create the model from user input
        /// </summary>
        /// <param name="model">Model retrieved from service</param>
        /// <returns>The model that was passed in</returns>
        protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel();
            AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel()
            {
                Location          = location,
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                CatalogCollation  = CatalogCollation,
                CollationName     = CollationName,
                DatabaseName      = DatabaseName,
                MaxSizeBytes      = MaxSizeBytes,
                Tags            = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                ElasticPoolName = ElasticPoolName,
                ReadScale       = ReadScale,
                ZoneRedundant   = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null
            };

            if (ParameterSetName == DtuDatabaseParameterSet)
            {
                newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName;
                newDbModel.Edition = Edition;
            }
            else
            {
                newDbModel.SkuName  = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition);
                newDbModel.Edition  = Edition;
                newDbModel.Capacity = VCore;
                newDbModel.Family   = ComputeGeneration;
            }

            dbCreateUpdateModel.Database   = newDbModel;
            dbCreateUpdateModel.SampleName = SampleName;

            return(dbCreateUpdateModel);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Send the restore request
        /// </summary>
        /// <returns>The list of entities</returns>
        protected override AzureSqlDatabaseModel GetEntity()
        {
            AzureSqlDatabaseModel model;
            DateTime restorePointInTime = DateTime.MinValue;
            string   createMode;
            string   location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);

            switch (ParameterSetName)
            {
            case FromPointInTimeBackupSetName:
            case FromPointInTimeBackupWithVcoreSetName:
                createMode         = "PointInTimeRestore";
                restorePointInTime = PointInTime;
                break;

            case FromDeletedDatabaseBackupSetName:
            case FromDeletedDatabaseBackupWithVcoreSetName:
                createMode         = "Restore";
                restorePointInTime = PointInTime == DateTime.MinValue ? DeletionDate : PointInTime;
                break;

            case FromGeoBackupSetName:
            case FromGeoBackupWithVcoreSetName:
                createMode = "Recovery";
                break;

            case FromLongTermRetentionBackupSetName:
            case FromLongTermRetentionBackupWithVcoreSetName:
                createMode = "RestoreLongTermRetentionBackup";
                break;

            default:
                throw new ArgumentException("No ParameterSet name");
            }

            model = new AzureSqlDatabaseModel()
            {
                Location                      = location,
                ResourceGroupName             = ResourceGroupName,
                ServerName                    = ServerName,
                DatabaseName                  = TargetDatabaseName,
                ElasticPoolName               = ElasticPoolName,
                RequestedServiceObjectiveName = ServiceObjectiveName,
                Edition     = Edition,
                CreateMode  = createMode,
                LicenseType = LicenseType
            };

            if (ParameterSetName == FromPointInTimeBackupWithVcoreSetName || ParameterSetName == FromDeletedDatabaseBackupWithVcoreSetName ||
                ParameterSetName == FromGeoBackupWithVcoreSetName || ParameterSetName == FromLongTermRetentionBackupWithVcoreSetName)
            {
                string skuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition);
                model.SkuName  = skuName;
                model.Edition  = Edition;
                model.Capacity = VCore;
                model.Family   = ComputeGeneration;
            }
            else
            {
                model.SkuName = string.IsNullOrWhiteSpace(ServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : ServiceObjectiveName;
                model.Edition = Edition;
            }

            return(ModelAdapter.RestoreDatabase(this.ResourceGroupName, restorePointInTime, ResourceId, model));
        }
        /// <summary>
        /// Send the restore request
        /// </summary>
        /// <returns>The list of entities</returns>
        protected override AzureSqlDatabaseModel GetEntity()
        {
            AzureSqlDatabaseModel model;
            DateTime restorePointInTime = DateTime.MinValue;
            string   createMode;
            string   location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);

            switch (ParameterSetName)
            {
            case FromPointInTimeBackupSetName:
            case FromPointInTimeBackupWithVcoreSetName:
                createMode         = "PointInTimeRestore";
                restorePointInTime = PointInTime;
                break;

            case FromDeletedDatabaseBackupSetName:
            case FromDeletedDatabaseBackupWithVcoreSetName:
                createMode         = "Restore";
                restorePointInTime = PointInTime == DateTime.MinValue ? DeletionDate : PointInTime;
                break;

            case FromGeoBackupSetName:
            case FromGeoBackupWithVcoreSetName:
                createMode = "Recovery";
                break;

            case FromLongTermRetentionBackupSetName:
            case FromLongTermRetentionBackupWithVcoreSetName:
                createMode = "RestoreLongTermRetentionBackup";
                break;

            default:
                throw new ArgumentException("No ParameterSet name");
            }

            model = new AzureSqlDatabaseModel()
            {
                Location                      = location,
                ResourceGroupName             = ResourceGroupName,
                ServerName                    = ServerName,
                DatabaseName                  = TargetDatabaseName,
                ElasticPoolName               = ElasticPoolName,
                RequestedServiceObjectiveName = ServiceObjectiveName,
                Edition     = Edition,
                CreateMode  = createMode,
                LicenseType = LicenseType,
                RequestedBackupStorageRedundancy = BackupStorageRedundancy,
                Tags          = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null,
            };

            if (ParameterSetName == FromPointInTimeBackupWithVcoreSetName || ParameterSetName == FromDeletedDatabaseBackupWithVcoreSetName ||
                ParameterSetName == FromGeoBackupWithVcoreSetName || ParameterSetName == FromLongTermRetentionBackupWithVcoreSetName)
            {
                string skuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition);
                model.SkuName  = skuName;
                model.Edition  = Edition;
                model.Capacity = VCore;
                model.Family   = ComputeGeneration;
            }
            else
            {
                model.SkuName = string.IsNullOrWhiteSpace(ServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : ServiceObjectiveName;
                model.Edition = Edition;
            }

            /// get auth headers for cross-sub and cross-tenant restore operations
            string targetSubscriptionId = ModelAdapter.Context?.Subscription.Id;
            string sourceSubscriptionId = ParseSourceSubscriptionIdFromResourceId(ResourceId);
            Dictionary <string, List <string> > auxAuthHeader = null;

            if (!string.IsNullOrEmpty(ResourceId) && targetSubscriptionId != sourceSubscriptionId)
            {
                List <string> resourceIds = new List <string>();
                resourceIds.Add(ResourceId);
                var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
                if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
                {
                    auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary);
                }
            }

            return(ModelAdapter.RestoreDatabase(this.ResourceGroupName, restorePointInTime, ResourceId, model, sourceSubscriptionId, auxAuthHeader));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets a SQL database by name
        /// </summary>
        /// <param name="resourceGroupName">The resource group the database is in</param>
        /// <param name="serverName">The name of the server</param>
        /// <param name="databaseName">The name of the database</param>
        /// <returns></returns>
        public AzureSqlDatabaseModel GetDatabase(string resourceGroupName, string serverName, string databaseName)
        {
            AzureSqlDatabaseAdapter databaseAdapter = new AzureSqlDatabaseAdapter(Context);

            return(databaseAdapter.GetDatabase(resourceGroupName, serverName, databaseName));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Resumes a Azure Sql Data Warehouse database.
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure SQL Server</param>
        /// <param name="databaseName">The name of the Azure SQL Data Warehouse database</param>
        /// <returns>The resumed Azure SQL Data Warehouse database object</returns>
        internal AzureSqlDatabaseModel ResumeDatabase(string resourceGroup, string serverName, string databaseName)
        {
            var resp = Communicator.Resume(resourceGroup, serverName, databaseName, Util.GenerateTracingId());

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, serverName, resp));
        }
        /// <summary>
        /// Gets a database in an elastic pool
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="poolName">The name of the Azure Sql Database ElasticPool</param>
        /// <param name="databaseName">The name of the database</param>
        /// <returns></returns>
        public AzureSqlDatabaseModel GetElasticPoolDatabase(string resourceGroupName, string serverName, string poolName, string databaseName)
        {
            var resp = Communicator.GetDatabase(resourceGroupName, serverName, databaseName);

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, resp));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets a database in an recommended elastic pool
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="poolName">The name of the Azure Sql RecommendedElasticPool</param>
        /// <param name="databaseName">The name of the database</param>
        /// <returns></returns>
        public AzureSqlDatabaseModel GetElasticPoolRecommendationDatabase(string resourceGroupName, string serverName, string poolName, string databaseName)
        {
            var resp = RecommendationCommunicator.GetDatabase(resourceGroupName, serverName, poolName, databaseName, Util.GenerateTracingId());

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, resp));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets an Azure SQL Database by name
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure SQL Server</param>
        /// <param name="databaseName">The name of the Azure SQL Database</param>
        /// <returns>The Azure SQL Database object</returns>
        internal AzureSqlDatabaseModel GetDatabase(string resourceGroupName, string serverName, string databaseName)
        {
            var resp = DatabaseCommunicator.Get(resourceGroupName, serverName, databaseName);

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, resp));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets a list of Azure Sql Databases in an RecommendedElasticPool.
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="poolName">The name of the recommended elastic pool the database are in</param>
        /// <returns>A list of database objects</returns>
        internal ICollection <AzureSqlDatabaseModel> ListElasticPoolRecommendationDatabases(string resourceGroupName, string serverName, string poolName)
        {
            var resp = RecommendationCommunicator.ListDatabases(resourceGroupName, serverName, poolName, Util.GenerateTracingId());

            return(resp.Select((db) => AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroupName, serverName, db)).ToList());
        }