예제 #1
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,
                ReadReplicaCount        = this.IsParameterBound(p => p.ReadReplicaCount) ? ReadReplicaCount : (int?)null,
                BackupStorageRedundancy = BackupStorageRedundancy,
            };

            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>
        /// 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 <AzureSqlElasticPoolModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticPoolModel> model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            List <AzureSqlElasticPoolModel> newEntity = new List <AzureSqlElasticPoolModel>();
            AzureSqlElasticPoolModel        newModel  = new AzureSqlElasticPoolModel()
            {
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                ElasticPoolName   = ElasticPoolName,
                Tags          = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                Location      = location,
                ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
                MaxSizeBytes  = MyInvocation.BoundParameters.ContainsKey("StorageMB") ? (long?)(StorageMB * Megabytes) : null,
                LicenseType   = LicenseType ?? model.FirstOrDefault().LicenseType
            };

            var elasticPool = ModelAdapter.GetElasticPool(ResourceGroupName, ServerName, ElasticPoolName);

            Management.Sql.Models.Sku poolCurrentSku = new Management.Sql.Models.Sku()
            {
                Name     = elasticPool.SkuName,
                Tier     = elasticPool.Edition,
                Family   = elasticPool.Family,
                Capacity = elasticPool.Capacity
            };
            Management.Sql.Models.ElasticPoolPerDatabaseSettings poolCurrentDbSetting = new Management.Sql.Models.ElasticPoolPerDatabaseSettings()
            {
                MinCapacity = elasticPool.DatabaseCapacityMin,
                MaxCapacity = elasticPool.DatabaseCapacityMax
            };

            if (ParameterSetName == DtuPoolParameterSet)
            {
                if (!string.IsNullOrWhiteSpace(Edition) || MyInvocation.BoundParameters.ContainsKey("Dtu"))
                {
                    string edition = string.IsNullOrWhiteSpace(Edition) ? poolCurrentSku.Tier : Edition;

                    newModel.SkuName  = AzureSqlElasticPoolAdapter.GetPoolSkuName(edition);
                    newModel.Edition  = edition;
                    newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("Dtu") ? (int?)Dtu : null;
                }

                if (MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") || MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax"))
                {
                    newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") ? (double?)DatabaseDtuMin : null;
                    newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax") ? (double?)DatabaseDtuMax : null;
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(Edition) || MyInvocation.BoundParameters.ContainsKey("VCore") || !string.IsNullOrWhiteSpace(ComputeGeneration))
                {
                    string skuTier = string.IsNullOrWhiteSpace(Edition) ? poolCurrentSku.Tier : Edition;

                    newModel.SkuName  = AzureSqlElasticPoolAdapter.GetPoolSkuName(skuTier);
                    newModel.Edition  = skuTier;
                    newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("VCore") ? VCore : poolCurrentSku.Capacity;
                    newModel.Family   = string.IsNullOrWhiteSpace(ComputeGeneration) ? poolCurrentSku.Family : ComputeGeneration;
                }

                if (MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") || MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax"))
                {
                    newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") ? (double?)DatabaseVCoreMin : null;
                    newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax") ? (double?)DatabaseVCoreMax : null;
                }
            }

            newEntity.Add(newModel);
            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 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
            };

            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);
        }
        /// <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 <AzureSqlElasticPoolModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticPoolModel> model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            List <AzureSqlElasticPoolModel> newEntity = new List <AzureSqlElasticPoolModel>();

            newEntity.Add(new AzureSqlElasticPoolModel()
            {
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                Tags            = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags),
                Location        = location,
                ElasticPoolName = ElasticPoolName,
                DatabaseDtuMax  = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax") ? (int?)DatabaseDtuMax : null,
                DatabaseDtuMin  = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") ? (int?)DatabaseDtuMin : null,
                Dtu             = MyInvocation.BoundParameters.ContainsKey("Dtu") ? (int?)Dtu : null,
                Edition         = MyInvocation.BoundParameters.ContainsKey("Edition") ? (DatabaseEdition?)Edition : null,
                StorageMB       = MyInvocation.BoundParameters.ContainsKey("StorageMB") ? (int?)StorageMB : null,
                ZoneRedundant   = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
            });
            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 <AzureSqlElasticPoolModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticPoolModel> model)
        {
            string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName);
            List <AzureSqlElasticPoolModel> newEntity = new List <AzureSqlElasticPoolModel>();
            AzureSqlElasticPoolModel        newModel  = new AzureSqlElasticPoolModel()
            {
                ResourceGroupName = ResourceGroupName,
                ServerName        = ServerName,
                ElasticPoolName   = ElasticPoolName,
                Tags          = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                Location      = location,
                ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
                MaxSizeBytes  = MyInvocation.BoundParameters.ContainsKey("StorageMB") ? (long?)(StorageMB * Megabytes) : null,
                LicenseType   = LicenseType,
                MaintenanceConfigurationId = MaintenanceConfigurationId,
            };


            if (ParameterSetName == DtuPoolParameterSet)
            {
                string edition = string.IsNullOrWhiteSpace(Edition) ? null : Edition;

                if (!string.IsNullOrWhiteSpace(edition))
                {
                    newModel.SkuName  = AzureSqlElasticPoolAdapter.GetPoolSkuName(edition);
                    newModel.Edition  = edition;
                    newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("Dtu") ? (int?)Dtu : null;
                }

                newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") ? (double?)DatabaseDtuMin : null;
                newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax") ? (double?)DatabaseDtuMax : null;
            }
            else
            {
                newModel.SkuName  = AzureSqlElasticPoolAdapter.GetPoolSkuName(Edition);
                newModel.Edition  = Edition;
                newModel.Capacity = VCore;
                newModel.Family   = ComputeGeneration;

                newModel.DatabaseCapacityMin          = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") ? (double?)DatabaseVCoreMin : null;
                newModel.DatabaseCapacityMax          = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax") ? (double?)DatabaseVCoreMax : null;
                newModel.HighAvailabilityReplicaCount = MyInvocation.BoundParameters.ContainsKey("HighAvailabilityReplicaCount") ? (int?)HighAvailabilityReplicaCount : null;
            }

            newEntity.Add(newModel);
            return(newEntity);
        }
        /// <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       = ParseSubscriptionIdFromResourceId(ResourceId);
            bool   isCrossSubscriptionRestore = false;
            Dictionary <string, List <string> > auxAuthHeader = null;

            if (!string.IsNullOrEmpty(sourceSubscriptionId) && !string.IsNullOrEmpty(targetSubscriptionId) && !targetSubscriptionId.Equals(sourceSubscriptionId, StringComparison.OrdinalIgnoreCase))
            {
                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);
                }

                isCrossSubscriptionRestore = true;
            }

            return(ModelAdapter.RestoreDatabase(this.ResourceGroupName, restorePointInTime, ResourceId, model, isCrossSubscriptionRestore, auxAuthHeader));
        }
        /// <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,
                HighAvailabilityReplicaCount     = this.IsParameterBound(p => p.HighAvailabilityReplicaCount) ? HighAvailabilityReplicaCount : (int?)null,
                RequestedBackupStorageRedundancy = BackupStorageRedundancy,
                SecondaryType                    = SecondaryType,
                MaintenanceConfigurationId       = MaintenanceConfigurationId,
            };

            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>
        /// 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);

            return(new AzureSqlDatabaseCreateOrUpdateModel
            {
                Database = new AzureSqlDatabaseModel()
                {
                    Location = location,
                    ResourceGroupName = ResourceGroupName,
                    ServerName = ServerName,
                    CatalogCollation = CatalogCollation,
                    CollationName = CollationName,
                    DatabaseName = DatabaseName,
                    Edition = Edition,
                    MaxSizeBytes = MaxSizeBytes,
                    RequestedServiceObjectiveName = RequestedServiceObjectiveName,
                    Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
                    ElasticPoolName = ElasticPoolName,
                    ReadScale = ReadScale,
                    ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
                },
                SampleName = SampleName
            });
        }
예제 #9
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="ZoneRedundant" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => ZoneRedundant.CreateFrom(sourceValue);