Пример #1
0
 internal InstanceFailoverGroupData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, InstanceFailoverGroupReadWriteEndpoint readWriteEndpoint, InstanceFailoverGroupReadOnlyEndpoint readOnlyEndpoint, InstanceFailoverGroupReplicationRole?replicationRole, string replicationState, IList <PartnerRegionInfo> partnerRegions, IList <ManagedInstancePairInfo> managedInstancePairs) : base(id, name, type, systemData)
 {
     ReadWriteEndpoint    = readWriteEndpoint;
     ReadOnlyEndpoint     = readOnlyEndpoint;
     ReplicationRole      = replicationRole;
     ReplicationState     = replicationState;
     PartnerRegions       = partnerRegions;
     ManagedInstancePairs = managedInstancePairs;
 }
Пример #2
0
        /// <summary>
        /// Creates or updates an Azure Sql Database InstanceFailoverGroup.
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="location">The name of the local region</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns>The upserted Azure Sql Database InstanceFailoverGroup</returns>
        internal AzureSqlInstanceFailoverGroupModel UpsertInstanceFailoverGroup(AzureSqlInstanceFailoverGroupModel model)
        {
            List <PartnerRegionInfo> partnerRegions = new List <PartnerRegionInfo>();
            PartnerRegionInfo        partnerRegion  = new PartnerRegionInfo(model.PartnerRegion, "Secondary");

            partnerRegions.Add(partnerRegion);

            List <ManagedInstancePairInfo> pairs = new List <ManagedInstancePairInfo>();
            ManagedInstancePairInfo        pair  = new ManagedInstancePairInfo();

            pair.PrimaryManagedInstanceId = string.Format(
                AzureSqlInstanceFailoverGroupModel.PrimaryManagedInstanceIdTemplate,
                _subscription.Id.ToString(),
                model.ResourceGroupName,
                model.PrimaryManagedInstanceName);
            pair.PartnerManagedInstanceId = string.Format(
                AzureSqlInstanceFailoverGroupModel.PartnerManagedInstanceIdTemplate,
                model.PartnerSubscriptionId == null ? _subscription.Id.ToString() : model.PartnerSubscriptionId,
                model.PartnerResourceGroupName,
                model.PartnerManagedInstanceName);
            pairs.Add(pair);

            InstanceFailoverGroupReadOnlyEndpoint readOnlyEndpoint = new InstanceFailoverGroupReadOnlyEndpoint();

            readOnlyEndpoint.FailoverPolicy = model.ReadOnlyFailoverPolicy;
            InstanceFailoverGroupReadWriteEndpoint readWriteEndpoint = new InstanceFailoverGroupReadWriteEndpoint();

            readWriteEndpoint.FailoverPolicy = model.ReadWriteFailoverPolicy;

            if (model.FailoverWithDataLossGracePeriodHours.HasValue)
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = checked (model.FailoverWithDataLossGracePeriodHours * 60);
            }

            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.Location, model.Name, new Management.Sql.Models.InstanceFailoverGroup
            {
                ReadWriteEndpoint    = readWriteEndpoint,
                ReadOnlyEndpoint     = readOnlyEndpoint,
                PartnerRegions       = partnerRegions,
                ManagedInstancePairs = pairs
            });

            return(CreateInstanceFailoverGroupModelFromResponse(resp));
        }
Пример #3
0
        private async Task <InstanceFailoverGroupResource> CreateInstanceFailoverGroup(string locationName, string instanceFailoverGroupName)
        {
            // create PrimaryManagedInstance(WestUS2) and PartnerManagedInstance(NorthEurope)
            string primaryManagedInstanceName = Recording.GenerateAssetName("managed-instance-primary-");
            string partnerManagedInstanceName = Recording.GenerateAssetName("managed-instance-partner-");
            string managedInstanceName1       = Recording.GenerateAssetName("managed-instance-");
            string managedInstanceName2       = Recording.GenerateAssetName("managed-instance-");
            string networkSecurityGroupName1  = Recording.GenerateAssetName("network-security-group-");
            string networkSecurityGroupName2  = Recording.GenerateAssetName("network-security-group-");
            string routeTableName1            = Recording.GenerateAssetName("route-table-");
            string routeTableName2            = Recording.GenerateAssetName("route-table-");
            string vnetName1 = Recording.GenerateAssetName("vnet-");
            string vnetName2 = Recording.GenerateAssetName("vnet-");

            Task[] tasks = new Task[]
            {
                CreateDefaultManagedInstance(managedInstanceName1, networkSecurityGroupName1, routeTableName1, vnetName1, AzureLocation.WestUS2, _resourceGroup),
                CreateDefaultManagedInstance(managedInstanceName2, networkSecurityGroupName2, routeTableName2, vnetName2, AzureLocation.WestUS2, _resourceGroup),
            };
            Task.WaitAll(tasks);
            string primaryManagedInstanceId = (await _resourceGroup.GetManagedInstances().GetAsync(primaryManagedInstanceName)).Value.Data.Id.ToString();
            string partnerManagedInstanceId = (await _resourceGroup.GetManagedInstances().GetAsync(partnerManagedInstanceName)).Value.Data.Id.ToString();

            // create InstanceFailoverGroup
            InstanceFailoverGroupReadWriteEndpoint instanceFailoverGroupReadWriteEndpoint = new InstanceFailoverGroupReadWriteEndpoint(ReadWriteEndpointFailoverPolicy.Automatic);

            instanceFailoverGroupReadWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = 60;
            InstanceFailoverGroupData data = new InstanceFailoverGroupData()
            {
                ReadWriteEndpoint    = instanceFailoverGroupReadWriteEndpoint,
                ManagedInstancePairs =
                {
                    new ManagedInstancePairInfo(primaryManagedInstanceId, partnerManagedInstanceId),
                },
            };
            var instanceFailoverGroupLro = await _resourceGroup.GetInstanceFailoverGroups(locationName).CreateOrUpdateAsync(WaitUntil.Completed, instanceFailoverGroupName, data);

            return(instanceFailoverGroupLro.Value);
        }
 internal static InstanceFailoverGroupData DeserializeInstanceFailoverGroupData(JsonElement element)
 {
     ResourceIdentifier id = default;
     string name = default;
     ResourceType type = default;
     Optional<InstanceFailoverGroupReadWriteEndpoint> readWriteEndpoint = default;
     Optional<InstanceFailoverGroupReadOnlyEndpoint> readOnlyEndpoint = default;
     Optional<InstanceFailoverGroupReplicationRole> replicationRole = default;
     Optional<string> replicationState = default;
     Optional<IList<PartnerRegionInfo>> partnerRegions = default;
     Optional<IList<ManagedInstancePairInfo>> managedInstancePairs = default;
     foreach (var property in element.EnumerateObject())
     {
         if (property.NameEquals("id"))
         {
             id = new ResourceIdentifier(property.Value.GetString());
             continue;
         }
         if (property.NameEquals("name"))
         {
             name = property.Value.GetString();
             continue;
         }
         if (property.NameEquals("type"))
         {
             type = property.Value.GetString();
             continue;
         }
         if (property.NameEquals("properties"))
         {
             if (property.Value.ValueKind == JsonValueKind.Null)
             {
                 property.ThrowNonNullablePropertyIsNull();
                 continue;
             }
             foreach (var property0 in property.Value.EnumerateObject())
             {
                 if (property0.NameEquals("readWriteEndpoint"))
                 {
                     if (property0.Value.ValueKind == JsonValueKind.Null)
                     {
                         property0.ThrowNonNullablePropertyIsNull();
                         continue;
                     }
                     readWriteEndpoint = InstanceFailoverGroupReadWriteEndpoint.DeserializeInstanceFailoverGroupReadWriteEndpoint(property0.Value);
                     continue;
                 }
                 if (property0.NameEquals("readOnlyEndpoint"))
                 {
                     if (property0.Value.ValueKind == JsonValueKind.Null)
                     {
                         property0.ThrowNonNullablePropertyIsNull();
                         continue;
                     }
                     readOnlyEndpoint = InstanceFailoverGroupReadOnlyEndpoint.DeserializeInstanceFailoverGroupReadOnlyEndpoint(property0.Value);
                     continue;
                 }
                 if (property0.NameEquals("replicationRole"))
                 {
                     if (property0.Value.ValueKind == JsonValueKind.Null)
                     {
                         property0.ThrowNonNullablePropertyIsNull();
                         continue;
                     }
                     replicationRole = new InstanceFailoverGroupReplicationRole(property0.Value.GetString());
                     continue;
                 }
                 if (property0.NameEquals("replicationState"))
                 {
                     replicationState = property0.Value.GetString();
                     continue;
                 }
                 if (property0.NameEquals("partnerRegions"))
                 {
                     if (property0.Value.ValueKind == JsonValueKind.Null)
                     {
                         property0.ThrowNonNullablePropertyIsNull();
                         continue;
                     }
                     List<PartnerRegionInfo> array = new List<PartnerRegionInfo>();
                     foreach (var item in property0.Value.EnumerateArray())
                     {
                         array.Add(PartnerRegionInfo.DeserializePartnerRegionInfo(item));
                     }
                     partnerRegions = array;
                     continue;
                 }
                 if (property0.NameEquals("managedInstancePairs"))
                 {
                     if (property0.Value.ValueKind == JsonValueKind.Null)
                     {
                         property0.ThrowNonNullablePropertyIsNull();
                         continue;
                     }
                     List<ManagedInstancePairInfo> array = new List<ManagedInstancePairInfo>();
                     foreach (var item in property0.Value.EnumerateArray())
                     {
                         array.Add(ManagedInstancePairInfo.DeserializeManagedInstancePairInfo(item));
                     }
                     managedInstancePairs = array;
                     continue;
                 }
             }
             continue;
         }
     }
     return new InstanceFailoverGroupData(id, name, type, readWriteEndpoint.Value, readOnlyEndpoint.Value, Optional.ToNullable(replicationRole), replicationState.Value, Optional.ToList(partnerRegions), Optional.ToList(managedInstancePairs));
 }